JDK-8062771 : Core reflection should use final fields whenever possible
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-11-03
  • Updated: 2015-06-04
  • Resolved: 2014-11-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u80Fixed 8u40Fixed 9 b40Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
We experienced very rare NullPointerExceptions in core reflection in jdk7, like this:

 *   at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
 *   at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
 *   at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:84)
 *   at java.lang.Class.getGenericSuperclass(Class.java:692)
 *   at com.google.inject.TypeLiteral.getSuperclassTypeParameter(TypeLiteral.java:99)
 *   at com.google.inject.TypeLiteral.<init>(TypeLiteral.java:79)

while experimenting with fixes, we were surprised to discover that making reflection class fields final fixed the problem - that's never happened before on x86 in my memory.  Although it's not reproducible on jdk8+, apparently because of the fix in 

8016236: Class.getGenericInterfaces performance improvement

(which is also a correctness improvement!)  we should preserve our work in jdk9 as well.
Comments
http://cr.openjdk.java.net/~martin/webrevs/openjdk9/reflection-final-fields/
03-11-2014