Irfan Adilovic
unread,Jan 23, 2012, 10:51:38 PM1/23/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit Contributors
[According to svn logs, this email would best be addressed to
"gwt.team.ecc" and "jat"]
I ran into a nasty problem where my code would run in development mode
but would die in production. I pinpointed the problem to a cast to
LinkedHashMap on the result of cloning an existing LinkedHashMap, with
the assumption that LinkedHashMap.clone() will be of the same type.
However, LinkedHashMap.clone() returnes a HashMap instance in
production.
Now, according to Java's Object.clone() javadoc, .clone() is not
obliged to return anything specific, there are only guidelines and
conventions, and because of this, strictly speaking, this is not a
bug. However, it is counter-intuitive and it is different from what
the Java implementation of LinkedHashMap.clone() does.
I went to the gwt sources (user/core/super/com/google/gwt/emul/java/
util) to see what causes the problem, and saw that LinkedHashMap
inherits HashMap's implementation of .clone() which --correctly in the
case of a HashMap-- returns a HashMap instance. The fix would be
trivial, by adding the equivalent code from HashMap with adaptation
for LinkedHashMap:
@Override
public Object clone() {
return new LinkedHashMap<K, V>(this);
}
I did this, and went to write a test, and found the following in trunk/
user/test/com/google/gwt/emultest/java/util/LinkedHashMapTest.java:
/*
* Test method for 'java.util.LinkedHashMap.clone()'
*/
// public void donttestClone() {
// LinkedHashMap srcMap = new LinkedHashMap();
// checkEmptyLinkedHashMapAssumptions(srcMap);
//
// // Check empty clone behavior
// LinkedHashMap dstMap = (LinkedHashMap) srcMap.clone();
// ... [5 commented-out lines of test code]
// // Check non-empty clone behavior
// ... [10 commented-out lines of test code]
// }
This seems to test the LinkedHashMap clone behavior, as if it were
implemented, but it is disabled. By analyzing the (luckily short) svn
log of the file with some svn diff -r bisecting, I identified that the
disabled code is there from the very first revision of the file:
gwt/trunk/user/test/com/google/gwt/emultest/java/util$ svn log
LinkedHashMapTest.java | tail
------------------------------------------------------------------------
r2609 | gwt.team.ecc | 2008-04-29 20:01:50 +0200 (Tue, 29 Apr 2008) |
2 lines
Adding LinkedHashMap and supporting tests and RPC serializers
Review by:jat (desk review)
gwt/trunk/user/test/com/google/gwt/emultest/java/util$ svn cat -r 2609
LinkedHashMapTest.java | grep -C2 donttest
* Test method for 'java.util.LinkedHashMap.clone()'
*/
// public void donttestClone() {
// LinkedHashMap srcMap = new LinkedHashMap();
// checkEmptyLinkedHashMapAssumptions(srcMap);
I have a feeling the code was added with the intention to be enabled,
but never was, as nobody came to actually "implementing"
LinkedHashMap.clone(). What's the official situation on this? Should I
file a bug and submit a patch?
-- Irfan Adilovic