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

Annotation element as '_' gives compiler error instead of a warning

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • tools
    • None
    • b82
    • Verified

    Description

      Sample test case:
      //Annotation with _ as one of the elements
      @interface MyAnno {
          int _() default 0;
      }
      // Element Value pair
      @MyAnno(_=2)
      class test{}


      Compilation output:
      test.java:3: warning: '_' used as an identifier
          int _() default 0;
              ^
        (use of '_' as an identifier might not be supported in future releases)
      test.java:6: warning: '_' used as an identifier
        @MyAnno(_=2)
                ^
        (use of '_' as an identifier might not be supported in future releases)
      test.java:6: error: ')' expected
        @MyAnno(_=2)
                 ^
      test.java:6: error: class, interface, or enum expected
        @MyAnno(_=2)
                  ^
      test.java:6: error: class, interface, or enum expected
        @MyAnno(_=2)
                   ^
      3 errors
      2 warnings

      Errors in the above output are unexpected.

      JLS rule in section 9.6 states the following:
      AnnotationTypeElementDeclaration:
      AbstractMethodModifiersopt Type Identifier ( ) DefaultValueopt ;

      Attachments

        Issue Links

          Activity

            People

              mcimadamore Maurizio Cimadamore
              sogoel Sonali Goel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: