Missing null check in AnnotatedType annotation accessor methods

XMLWordPrintable

    • Type: CSR
    • Resolution: Approved
    • Priority: P4
    • 26
    • Component/s: core-libs
    • None
    • behavioral
    • low
    • Hide
      The 3 methods are inconsistent with `get(Declared)AnnotationsByType`. Users relying on the null behavior would likely have noticed this and reported an issue, but there has been no such report.

      The 3 methods that did not throw NPE always returned `false` or `null`. Migration would be trivial too if it was really a dependency.
      Show
      The 3 methods are inconsistent with `get(Declared)AnnotationsByType`. Users relying on the null behavior would likely have noticed this and reported an issue, but there has been no such report. The 3 methods that did not throw NPE always returned `false` or `null`. Migration would be trivial too if it was really a dependency.
    • Java API
    • Implementation

      Summary

      Add null checks to AnnotatedType methods inherited from AnnotatedElement, where they are specifed to throw NPE for null.

      Problem

      AnnotatedElement specifies the following methods to throw NPE for null arguments:

      • isAnnotationPresent
      • getAnnotation
      • getDeclaredAnnotation
      • getAnnotationsByType
      • getDeclaredAnnotationsByType

      The implementation of the first 3 methods in AnnotatedType implementations do not throw NPE for null arguments.

      Solution

      Introduce new NPE for calling the first 3 methods on AnnotatedType with null argument.

      The NPE has been conventional in all system AnnotatedElement implementations besides AnnotatedType. Loosening the NPE restriction would be more confusing than helpful.

      In addition, get(Declared)AnnotationsByType already throw NPE. If users have relied on the 3 methods not failing on null, they likely would have noticed this inconsistency and reported an issue, so tighting the first 3 methods would be reasonable.

      Specification

      No specification change. This is purely behavioral, to correct AnnotatedType implementations to be compliant.

            Assignee:
            Chen Liang
            Reporter:
            Chen Liang
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: