Translated to null.nullField when using JsInterop & @JsType

150 views
Skip to first unread message

田传武

unread,
Jun 30, 2014, 10:31:54 AM6/30/14
to google-web-tool...@googlegroups.com
Hello, 
The newest @JsType feature is really very fascinating, and works in most cases. The only issue i found was the wrong null.nullField javascript output.

the compile command:
java -cp xxx com.google.gwt.dev.Compiler -war xxx -XnoclassMetadata -XnocheckCasts -XjsInteropMode JS -XclosureCompiler -style PRETTY com.goodow.realtime.store.StoreProd

Java code:
public CollaborativeOperation compose(JsonArray operations) {
    final CollaborativeOperation first = operations.<CollaborativeOperation> get(0);
    if (operations.length() == 1) {
      return first;
    }
    final JsonArray components = Json.createArray();
    operations.forEach(...);
    return new CollaborativeOperation(first.userId, first.sessionId, components);
  }

translated to the following javascript:
 function $compose(operations) {
  var components;
  components = operations[0];
  if (1 == operations.length) {
    return components;
  }
  components = [];
  $forEach(operations, new CollaborativeTransformer$1(components));
  return new CollaborativeOperation(null.nullField, null.nullField, components);
}


There's an easy workaround to fix this: using the -draftCompile options when compilation. Here is the full compilation log:
 

John A. Tamplin

unread,
Jun 30, 2014, 10:58:08 AM6/30/14
to Google Web Toolkit Contributors

Generally, null.nullField means the compiler can prove the value is null at that point, and draft compile skills the optimization that defects a lot of that.  So either it really is always null, or there is an optimizer bug.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/35eb8ed2-588b-484a-b2f4-b58b5bb01f46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

田传武

unread,
Jun 30, 2014, 11:09:49 AM6/30/14
to google-web-tool...@googlegroups.com
I'm sure this is an optimizer bug. 

null.nullField causes the following error at runtime:
SEVERE: (TypeError) : Cannot read property 'nullField' of nullcom.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'nullField' of null
        at
Unknown.$compose(
http://localhost:63342/realtime/app/bower_components/realtime-store/realtime-store.js@41)

However, the 
draft compilation javascript works very well.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.

Daniel Kurka

unread,
Jun 30, 2014, 11:18:12 AM6/30/14
to google-web-tool...@googlegroups.com
I have seen this happening before when the pruner removes a type that he does not consider live but actually is live.

Fast try, can you change:
final CollaborativeOperation first = operations.<CollaborativeOperation> get(0);

to:
final CollaborativeOperation first = (CollaborativeOperation) operations.<CollaborativeOperation> get(0);

-Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/362b0daf-c174-4021-9bc8-acee19af0cfc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Katherine Stephens

Ray Cromwell

unread,
Jun 30, 2014, 1:18:33 PM6/30/14
to google-web-toolkit-contributors
Can you post the full source for CollaborativeOperation? My guess is
the UserID and SessionID fields are being proven by the compiler to be
uninstantiated types. Are userId/sessionId simple Strings, or some
other type?

.
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CALLujirJ7CD%2B_fRDFyE9kUX%2BCLeeaMbd8JQraWMMp6CWQKtNMQ%40mail.gmail.com.

田传武

unread,
Jun 30, 2014, 9:39:40 PM6/30/14
to google-web-tool...@googlegroups.com, google-we...@googlegroups.com
Hi Ray,

Here is the source for CollaborativeOperation:

the final project which depends on realtime-operation:
https://github.com/goodow/realtime-store (Using the ./gwt-compile.sh to compile)

and the live playground:

Thanks!
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/35eb8ed2-588b-484a-b2f4-b58b5bb01f46%40googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "GWT Contributors" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/362b0daf-c174-4021-9bc8-acee19af0cfc%40googlegroups.com.
>>
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> Google Germany GmbH
> Dienerstr. 12
> 80331 München
>
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: Graham Law, Katherine Stephens
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an

田传武

unread,
Jun 30, 2014, 9:58:52 PM6/30/14
to google-web-tool...@googlegroups.com
Hi Daniel,
I just tried the code you provided, unfortunately, the explicit class cast workaround does not solve this issue. The translated javascript code is the same as before.

Thanks!
Reply all
Reply to author
Forward
0 new messages