Friday, December 27, 2013

Differences between DevMode and Production mode related to trim()

OK, we ran into a strange issue today. This is using GWT 2.5.1 with Chrome 32.0.1700.68 beta-m (and latest stable). Production mode is hosted by Jetty.

The following code works fine in DevMode but fails in Production (same browser):

List<SchGetInfoForDoorsReq_DoorDto> tempDocksModel = new ArrayList<SchGetInfoForDoorsReq_DoorDto>();
for (SchGetInfoForDoorsReq_DoorDto dock: allDocksList)
{
if (dock.DoorInfo.getTrailerID().trim().equalsIgnoreCase("") && 
dock.DoorInfo.getTripID().trim().equalsIgnoreCase(""))
{
tempDocksModel.add(dock);
}
}

Generated Pretty JS:
tempDocksModel = new ArrayList_0;
for (dock$iterator = new AbstractList$IteratorImpl_0(this$static.allDocksList); dock$iterator.i < dock$iterator.this$0_0.size_1(); ) {
    dock = dynamicCast($next_4(dock$iterator), Q$SchGetInfoForDoorsReq_DoorDto);
    $equalsIgnoreCase($trim(valueOf_4(dock.DoorInfo.TrailerID)), '') && $equalsIgnoreCase($trim(valueOf_4(dock.DoorInfo.TripID)), '') && (setCheck(tempDocksModel.array, tempDocksModel.size_0++, dock), true);
}

List<SchGetInfoForDoorsReq_DoorDto> tempDocksModel = new ArrayList<SchGetInfoForDoorsReq_DoorDto>();
for (SchGetInfoForDoorsReq_DoorDto dock: allDocksList)
{
if (dock.DoorInfo.getTrailerID().trim().isEmpty() && 
dock.DoorInfo.getTripID().trim().isEmpty())
{
tempDocksModel.add(dock);
}
}

Generated Pretty JS:
tempDocksModel = new ArrayList_0;
for (dock$iterator = new AbstractList$IteratorImpl_0(this$static.allDocksList); dock$iterator.i < dock$iterator.this$0_0.size_1(); ) {
    dock = dynamicCast($next_4(dock$iterator), Q$SchGetInfoForDoorsReq_DoorDto);
    !$trim(valueOf_4(dock.DoorInfo.TrailerID)).length && !$trim(valueOf_4(dock.DoorInfo.TripID)).length && (setCheck(tempDocksModel.array, tempDocksModel.size_0++, dock), true);
}

The fix was to do something like the following (not quite equivalent check):

                        List<SchGetInfoForDoorsReq_DoorDto> tempDocksModel = new ArrayList<SchGetInfoForDoorsReq_DoorDto>();
for (SchGetInfoForDoorsReq_DoorDto dock: allDocksList)
{
if (dock.DoorInfo.getTrailerID().charAt(0) == '\0' && 
dock.DoorInfo.getTripID().charAt(0) == '\0')
{
tempDocksModel.add(dock);
}
}

Generated Pretty JS:
tempDocksModel = new ArrayList_0;
for (dock$iterator = new AbstractList$IteratorImpl_0(this$static.allDocksList); dock$iterator.i < dock$iterator.this$0_0.size_1(); ) {
    dock = dynamicCast($next_4(dock$iterator), Q$SchGetInfoForDoorsReq_DoorDto);
    valueOf_4(dock.DoorInfo.TrailerID).charCodeAt(0) == 0 && valueOf_4(dock.DoorInfo.TripID).charCodeAt(0) == 0 && (setCheck(tempDocksModel.array, tempDocksModel.size_0++, dock), true);
}


According to http://www.w3schools.com/jsref/jsref_trim_string.asp , The trim() method is supported in all major browsers.

"String.trim() was added natively in JavaScript 1.8.1 / ECMAScript 5, supported in: Firefox 3.5+, Chrome/Safari 5+, IE9+ (in Standards mode only!) see scunliffe's answer: stackoverflow.com/a/8522376/8432 –  wweicker"


We've noticed some other cases in our code lately where we used trim() and it works fine in DevMode, but then later in production mode we end up seeing lots of nulls and extra spaces at the end of things like tokens.

Is this a known issue? Is this a problem with Chrome or GWT or are we just 'doing it wrong'?

Thank you,

Michael Prentice
GDG Space Coast

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment