pombreda / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 1 forks source link

Types doesn't match JDK7 behaviour where primitive arrays are used as type parameters #715

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This code, using Guava's TypeToken, returns 'true' in JDK6 and 'false' in JDK7.

TypeToken listOfByteArray = new TypeToken<List<byte[]>>(){};
TypeToken listOfByteArray2 = 
TypeToken.of(com.google.inject.util.Types.listOf(byte[].class));
System.out.println(listOfByteArray2.isAssignableFrom(listOfByteArray));

This is because listOfByteArray2 is a ParameterizedType whose argument is a 
GenericArray whose component type is byte[].
This matches the JDK6 behaviour when reflecting on a field of type List<byte[]>.

In JDK7 a bug was fixed 
(http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784); this type is now 
represented by a ParameterizedType whose argument is byte[].class.

So the correct behaviour, I think, is to detect the current JDK version and use 
the appropriate implementation.
The corresponding class in Guava does this: 
http://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/comm
on/reflect/Types.java#471

Original issue reported on code.google.com by sammcc...@google.com on 17 Jul 2012 at 3:37

GoogleCodeExporter commented 9 years ago
Agreed.  I'll roll a fix. 

Original comment by cgruber@google.com on 17 Jul 2012 at 6:52

GoogleCodeExporter commented 9 years ago
Or rather, I'll dig into an internal discussion and summarize the relevant 
portions here.

Original comment by cgruber@google.com on 17 Jul 2012 at 7:08