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

Annotation system prohibits certain annotations, drops others

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 8
    • 5.0
    • specification
    • Verified

    Description

      A DESCRIPTION OF THE REQUEST :
      The current Java annotation system is too weak to use for many purposes.
      There are two main problems: inability to annotate certain constructs, and
      loss of other annotations by the compilation process.

      1. Annotations can only be applied to type declarations, not to other uses
      of types.
        * Annotations cannot be applied to a cast.
        * Annotations cannot be applied to the receiver (this) of a method.
          (This could be worked around with an annotation that is syntactically
          applied to the method return type but semantically applies to the
          receiver type.)
        * Annotations cannot be inserted at arbitrary locations within array and
          parameterized types. Consider annotating the various levels of an
          array with different annotations; one would like to say, for example
            (@annotation Date[])[][] myarray;
        * Annotations are not permitted on type parameters. Consider placing
          annotations on various parts of the following type:
            Map<List<Date>, Set<Number>>

      2. Annotations on local variables are not recorded within the classfile by
      the javac compiler. Therefore, if we wish to use annotations and perform
      type checking on classfiles, we would be required to extend the annotation
      system. This would require changing the compiler, possibly by recording
      local variables' annotations within the local variable symbol table. A
      compiler change eliminates one of the benefits of using annotations: not
      requiring people to use a new compiler to check reference immutability
      constraints. (But the Javari code would remain backward-compatible with
      other Java compilers.)

      JUSTIFICATION :
      If these problems were resolved, then the annotation system would become
      much more expressive and more useful for a variety of purposes. As just
      one example, it would become possible to experiment with new type systems
      without changing the syntax of the Java language in an incompatible way.
      Other applications would benefit as well.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Annotations should be permitted on any type, and should be preserved
      by the compiler.
      ACTUAL -
      Annotations are prohibited on certain uses of types.
      Annotations on local variables are dropped by the compiler.

      Attachments

        Issue Links

          Activity

            People

              abuckley Alex Buckley
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: