Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gissuebot opened this issue Jul 7, 2014 · 2 comments

Comments

@gissuebot
Copy link

From sammccall@google.com on July 17, 2012 11:37:29

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: https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/reflect/Types.java#471

Original issue: http://code.google.com/p/google-guice/issues/detail?id=715

@gissuebot
Copy link
Author

From cgruber@google.com on July 17, 2012 11:52:29

Agreed.  I'll roll a fix.

Status: Accepted
Owner: cgruber@google.com
Labels: Type-Defect Priority-High Component-Core

@gissuebot
Copy link
Author

From cgruber@google.com on July 17, 2012 12:08:40

Or rather, I'll dig into an internal discussion and summarize the relevant portions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants