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

AnnotationParser throws NullPointerException on incompatible member type

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 17
    • core-libs
    • None
    • behavioral
    • minimal
    • Hide
      Current implementations might anticipate the incorrect implementation and expect a NullPointerException. Since AnnotationTypeMismatchExceptions are however already thrown for any other incompatible change, this risk is to be expected minimal as this exception type should be handled for changes other than changing an annotation type to an enum type or vice versa.
      Show
      Current implementations might anticipate the incorrect implementation and expect a NullPointerException. Since AnnotationTypeMismatchExceptions are however already thrown for any other incompatible change, this risk is to be expected minimal as this exception type should be handled for changes other than changing an annotation type to an enum type or vice versa.
    • Other

    Description

      Summary

      This change proposes to always throw an AnnotationTypeMismatchException if the type of an annotation member is changed and the member is accessed for an annotation that was compiled prior to this change. The javadoc for AnnotationTypeMismatchException documents that this exception is intended for this purpose but is not currently thrown out of an oversight in the annotation parser implementation.

      Problem

      If an annotation member type is changed from being an enum to an annotation or vice versa, the current implementation of the annotation parser in the reflection API throws a NullPointerException upon processing a previously compiled annotation. This is the result of that change not being explicitly handled in the code. Unfortunately, the null pointer is already thrown when processing the annotation as no exception proxy is generated. This makes the entire annotation inaccessible as parsing an annotation is impossible and always yields the error, even if another, compatible member is supposed to be accessed.

      Solution

      Change the existing implementation to throw an AnnotationTypeMismatchException if a member type is changed from an enum to an annotation type or vice versa. This avoids the null pointer altogether.

      Specification

      The behavior is already specified in the annotation parser's javadoc but currently incorrectly implemented.

          /**
           * (...)
           *
           * The member must be of the indicated type. If it is not, this
           * method returns an AnnotationTypeMismatchExceptionProxy.
           */
           public static Object parseMemberValue(Class<?> memberType,
                                                 ByteBuffer buf,
                                                 ConstantPool constPool,
                                                 Class<?> container);

      Attachments

        Issue Links

          Activity

            People

              winterhalter Rafael Winterhalter
              winterhalter Rafael Winterhalter
              Joel Borggrén-Franck (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: