1.) LinkedHashMap extends HashMap but does not override HashMap.clone();
https://gwt.googlesource.com/gwt/+/releases/2.5/user/super/com/google/gwt/emul/java/util/LinkedHashMap.java
2.) HashMap.clone() returns a new HashMap instance.
https://gwt.googlesource.com/gwt/+/releases/2.5/user/super/com/google/gwt/emul/java/util/HashMap.java
This means when you call LinkedHashMap.clone() you only receive a HashMap that can't be cast to LinkedHashMap. Thats why you have a ClassCastException and thats why the exception disappears when you cast it to HashMap. In DevMode it works because in DevMode the ordinary JRE classes are used. For web mode GWT provides different (JS based) implementations (the links above).
Although I am not sure if GWT's JRE emulation respects inheritance it clearly states that HashMap.clone() is emulated while LinkedHashMap.clone() is not (https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation#Package_java_util) although its a sub class. A similar situation exists with java.util.Vector and java.util.Stack. Stack extends Vector but in this case the JRE emulation page says that Stack.clone() and Vector.clone() are emulated.
But in general I would say that its a bug in the LinkedHashMap emulation. It should override HashMap.clone() to return a LinkedHashMap instead. Its too easy to hit this issue.
-- J.
-- 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment