Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8062771

Core reflection should use final fields whenever possible

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • None
    • core-libs
    • None
    • b40
    • generic
    • generic
    • Verified

        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.

              martin Martin Buchholz
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: