Revision: 6983 Author: [email protected] Date: Wed Nov 18 07:57:10 2009 Log: Ensure server info from superclasses doesn't stomp on subclass info.
This fixes external issue 3969 (http://code.google.com/p/google-web-toolkit/issues/detail?id=3969). When a class with superclasses was being serialized, the extra info for the superclass and the subclass were being stored in the same place using WeakMapping. The result was that the superclass version was seen when deserializing the subclass, causing an exception. By using different keys, we can associate each portion of the data with the appropriate phase of the serialization/deserialization process. Review by: bobv http://code.google.com/p/google-web-toolkit/source/detail?r=6983 Modified: /trunk/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java ======================================= --- /trunk/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java Wed Nov 11 11:41:51 2009 +++ /trunk/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java Wed Nov 18 07:57:10 2009 @@ -121,6 +121,18 @@ return sb.toString(); } + + /** + * Returns the depth of the given class in the class hierarchy + * (where the depth of java.lang.Object == 0). + */ + private int getDepth(JClassType clazz) { + int depth = 0; + while ((clazz = clazz.getSuperclass()) != null) { + depth++; + } + return depth; + } private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx) { String qualifiedSerializerName = SerializationUtils.getFieldSerializerName( @@ -272,7 +284,9 @@ */ if (serializableClass.isEnhanced()) { sourceWriter.println(WEAK_MAPPING_CLASS_NAME + ".set(instance, " - + "\"server-enhanced-data\", streamReader.readString());"); + + "\"server-enhanced-data-" + + getDepth(serializableClass) + + "\", streamReader.readString());"); } for (JField serializableField : serializableFields) { @@ -320,7 +334,9 @@ if (serializableClass.isEnhanced()) { sourceWriter.println("streamWriter.writeString((String) " - + WEAK_MAPPING_CLASS_NAME + ".get(instance, \"server-enhanced-data\"));"); + + WEAK_MAPPING_CLASS_NAME + + ".get(instance, \"server-enhanced-data-" + + getDepth(serializableClass) + "\"));"); } for (JField serializableField : serializableFields) { -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
