What steps will reproduce the problem?
1. Create a GSON object: new GsonBuilder().create();
2. Retrotranslate the byte code to jdk 1.4, using Retrotranslator
http://retrotranslator.sourceforge.net/
3. Run the code.
What is the expected output? What do you see instead?
I would expect no WARNINGs to be logged. However, I see the following output to
the console:
com.google.gson.ParameterizedTypeHandlerMap register
WARNING: Overriding the existing type handler for interface java.util.Collection
What version of the product are you using? On what operating system?
1.3 and also tested with 1.4 built from trunk.
Please provide any additional information below.
This log message comes from the following line of code:
http://code.google.com/p/google-
gson/source/browse/trunk/gson/src/main/java/com/google/gson/ParameterizedTypeHan
dlerM
ap.java#49
Specifically, it is logged because the
DefaultTypeAdapters.createDefaultInstanceCreators method
adds a COLLECTION_TYPE_HANDLER for Collection.class, and then later, a
Queue.class.
Because Queue.class is @since 1.5, retrotranslator replaces the class literal
"java.util.Queue", with
"java.util.Collection". This causes the Queue type handler to overwrite the
Collection type
handler.
map.register(Map.class, MAP_TYPE_ADAPTER);
// Add Collection type instance creators
map.register(Collection.class, COLLECTION_TYPE_ADAPTER);
map.register(List.class, COLLECTION_TYPE_ADAPTER);
map.register(Queue.class, COLLECTION_TYPE_ADAPTER);
I'm not sure that a WARNING is needed here, since both Collection and Queue
have the same
Collection type handlers.
Either the WARNING could be removed, or there could be some smarter registering
of type
handlers so that the Queue class automatically gets the COLLECTION_TYPE_HANDLER.
Original issue reported on code.google.com by
npel...@gmail.comon 27 Aug 2009 at 1:17