Closed dankurka closed 9 years ago
I believe I've tracked down the problem, based on the encoded RPC string you enclosed.
The value
'1768522993081' is intended to be the hashCode field of the org.adligo.models.core.client.User
class.
However, its value is too large to fit into an int, so when ServerSerializationStreamReader.readInt
calls
Integer.parseInt on it, a java.lang.NumberFormatException is thrown.
In GWT, client-side code represents Java 'int's using native JavaScript numbers, which
act more like Java
'double's. In the interest of performance, GWT does not attempt to emulate the way
int arithmetic
handles overflow via wraparound. Thus your User.genHashCode method ends up generating
different values
in dev (hosted) mode versus prod (web) mode, and sometimes that values can't be passed
through RPC since
the server-side code expects a true Java int. The larger value is written out in decimal
representation as 1768522993081 and the server-side code chokes on it.
There are two main workarounds I can think of:
1) Add code to handle overflow such as 'result = result & 0xffffffff' after each computation
that could overflow
32 bits. If you do this correctly your hash code computation should be identical in
dev an dprod modes.
Basically you would be forcing int emulation at specific places where it matters for
RPC.
2) Make dangerous fields like 'hashCode' transient, i.e., don't attempt to send them
via RPC. Make the rest of
the code generate the 'hashCode' field on demand, e.g, using code like 'if (hashCode
== 0) genHashCode();'.
(one object in 32 billion or so will fail to benefit from caching). The hash codes
will be different on the client
and server but as long as you don't 'pickle' any hash codes into collection objects
that get sent over RPC that
shouldn't matter. Each side will be self-consistent.
While the lack of integer wraparound is not a bug in GWT (since GWT explicitly chooses
not to emulate it),
the way this behavior interacts with RPC seems like a trouble spot within GWT and we
will give some thought
as to how the experience for code similar to yours could be improved.
Reported by rice@google.com
on 2009-12-01 19:26:13
NotPlanned
Reported by rice@google.com
on 2009-12-01 21:13:17
Accepted
I'm closing this as "AsDesigned." It's up to the client code to avoid overflow for
integer fields that are
transmitted by RPC. Revision r7238 adds a more descriptive error message for this
case.
Reported by rice@google.com
on 2009-12-22 18:01:02
AsDesigned
Originally reported on Google Code with ID 4263
Reported by
adligo778
on 2009-11-21 18:24:39