Updates to the Java Specification Request (JSR)
The following information has been updated from the original JSR:
2012年09月12日:
The Expert Group and Specification Lead moved the JSR to JCP 2.8.
EG communication archive: http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/
Comments on draft specifications may be sent to type-annotations-spec-comments
http://code.google.com/p/jsr308-langtools/issues/list
http://types.cs.washington.edu/jsr308/
2011年12月22日:
The Current proposal and
other materials are available at http://types.cs.washington.edu/jsr308/.
2010年02月16日: The Specification Leads have changed.
Specification Lead: Alex Buckley (Oracle), Michael Ernst
E-Mail Address: alex.buckley
Telephone Number: +1 408 276 3065, +1 617 253 0945
Fax Number: -, +1 617 258 8682
2007年12月18日: (削除) The Specification Leads have changed. (削除ここまで)
(削除) Specification Lead: Alex Buckley, Michael Ernst (削除ここまで)
(削除) E-Mail Address: alex.buckley
(削除) Telephone Number: +1 617 253 0945 (削除ここまで)
(削除) Fax Number: +1 617 258 8682 (削除ここまで)
2007年03月06日: (削除) The Current proposal and
other materials are available at http://pag.csail.mit.edu/jsr308/. (削除ここまで)
Note that out-of-date information has been crossed out. Current information is found at the top of this update section.
Original Java Specification Request (JSR)
Identification |
Request |
Contributions |
Additional Information
Section 1. Identification
Submitting Member: Michael Ernst
(削除) Name of Contact Person: Michael Ernst, Danny Coward (削除ここまで)
(削除) E-Mail Address: mernst@csail.mit.edu, Danny.Coward@Sun.COM (削除ここまで)
(削除) Telephone Number: +1 617 253 0945, +1 415 294 5386 (削除ここまで)
(削除) Fax Number: +1 617 258 8682, +1 408 276 7700 (削除ここまで)
Initial Expert Group Membership:
Doug Lea
Google
JetBrains
Michael Ernst
Sun
Ted Neward
William Pugh
Supporting this JSR:
Doug Lea
Google
JetBrains
Michael Ernst
Sun
Ted Neward
William Pugh
Section 2: Request
We propose an extension to Java's annotation system that permits annotations to appear on any use of a type, not just on class/method/field/variable declarations, as is the case in Java SE 6. Such a generalization removes arbitrary limitations of Java's annotation system, and it enables new uses of annotations.
This JSR specifies the syntax of extended Java annotations, but it makes no commitment as to their semantics. As with Java's existing annotations, the semantics is dependent on annotation processors (compiler plug-ins), and not every annotation is necessarily sensible in every location where it is syntactically permitted to appear. This proposal is compatible with existing annotations, such as those specified in JSR 250, "Common Annotations for the Java Platform", and JSR 305, "Annotations for Software Defect Detection".
This proposal does not change the compile-time, load-time, or run-time semantics of Java. It does not change the abilities of Java annotation processors. The proposal merely makes annotations more general --- and thus more useful for their current purposes, and also usable for new purposes that are compatible with the original vision for annotations.
The new Java syntax allows annotations in the following locations. (The specific annotation names, such as @NonNull, are examples only; this document does not propose any annotations, merely specifying where they can appear in Java code.)
generic type arguments:
Map<@nonnull String, @NonEmpty List<@readonly Document>> files;
arrays:
Document[@Readonly] docs1;
Document[][@Readonly] docs2 = new Document[2][@Readonly 12];
(docs1 is an unmodifiable one-dimensional array of mutable Documents.
docs2 is a mutable array whose elements are unmodifiable
one-dimensional arrays of mutable Documents.)
typecasts:
myString = (@NonNull String)myObject;
type tests:
boolean isNonNull = myString instanceof @NonNull String;
object creation:
type parameter bounds:
class inheritance:
throws clauses:
new @NonEmpty @Readonly List
class Folder
class UnmodifiableList
void monitorTemperature() throws @Critical TemperatureException { ... }
Java annotations (including the extended annotations) must be stored in the class file for two reasons. First, they may be part of the interface of a class and, if so, must be available to the compiler (really, to the type-checking plug-in) when compiling clients of the class. Second, since class files may originate from any source, the information may be useful in other contexts, such as compile-time verification.
This JSR proposes conventions for storing the new annotations, as well as for storing local variable annotations, which are permitted in Java syntax but currently discarded by the compiler. Class files already store annotations in the form of ``attributes''. JVMs ignore unknown attributes. For backward compatibility, we use new attributes for storing the type annotations. In other words, our proposal merely reserves the names of a few attributes and specifies their layout. Our proposal does not alter the way that existing annotations on classes, methods, method parameters, and fields are stored in the class file. Class files generated from programs that use no new annotations will be identical to those generated by a standard Java SE 6 (that is, pre-extended-annotations) compiler.
This JSR introduces two new attributes: RuntimeVisibleTypeAnnotations and RuntimeInvisibleTypeAnnotations. These attributes are structurally identical to the existing RuntimeVisibleAnnotations and RuntimeInvisibleAnnotations attributes described above with one exception: rather than an array of annotation elements, RuntimeVisibleTypeAnnotations and RuntimeInvisibleTypeAnnotations contain an array of extendedannotation elements. An extendedannotation element is like an annotation element, but it adds a target_type field and a reference_info field.
The specification will also attempt to provide a simple approach for writing annotations with array-valued elements.
This technology targets all Java platforms that support Java annotations, as introduced in Java SE 5.
This technology should be deployed as part of Java SE 7.
No. The Java SE/EE executive committee is sufficient.
Among other uses, annotations on Java types will enable the use of type qualifiers. Type qualifiers are modifiers that provide extra information about a type or variable; they can be thought of as a form of subtyping. A designer can define new type qualifiers using Java annotations, and can provide plug-ins to check their semantics (for instance, by issuing lint-like warnings during compilation). A programmer can then use these type qualifiers throughout a program to obtain additional guarantees at compile time about the program.
A system for custom type qualifiers requires extensions to Java's annotation system, to permit annotation of any use of a type in a program. The existing Java SE 6 annotations are inadequate, because many facts a programmer would like to specify are inexpressible. Similarly to type qualifiers, other pluggable type systems and similar lint-like checkers also require these extensions to Java's annotation system.
The key underlying technology is Java SE and JSR 250 ("Common Annotations for the Java Platform"). Implementation of the JSR will require changes to Java compilers and other tools to recognize the new syntax and place attributes in classfiles.
No.
No
No known security problems.
No
This work may require updates to the Java SE core reflection APIs (in java.lang.* and java.lang.reflect.*), and updates to the Pluggable Annotation Processing API (JSR 269), to be determined with the appropriate expert groups.
The intention is to deliver this JSR as a component of Java SE 7. Early Draft Review would occur in the second half of 2006, Public Review in the first half of 2007, and Proposed Final Draft in the second half of 2007.
We will primarily use email, with conference calls and meetings as needed.
The JSR process will be run in an open and transparent way, with drafts, discussion, and progress reports available for public view and comments via java.net and our own websites. We also plan to provide a draft reference implementation for public use and comment, beginning with the early draft review, and fold that implementation into the Java SE 7 sources as soon as possible. We may also add a public Wiki or other web support to further involve the Java community.
This JSR proposes a change to the Java language and thus can only be delivered in a Java SE platform release. It is targeted for Java SE 7.
N/A
The Reference Implementation and TCK will be made available as part of some future Java SE platform release, hence under the same terms.
Note that the following information was added when the JSR moved to JCP 2.8:
EG communication archive: http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/
Comments on draft specifications may be sent to type-annotations-spec-comments
http://code.google.com/p/jsr308-langtools/issues/list
http://types.cs.washington.edu/jsr308/
Section 3: Contributions
Annotations on Java types
http://pag.csail.mit.edu/javari/java-annotation-design.pdf
A longer and more technically detailed version of this JSR, which
contains over two dozen references to related work, including examples
of the utility of type qualifiers.
Custom type qualifiers via annotations on Java types
http://pag.csail.mit.edu/javari/java-type-qualifiers.pdf
Describes one way that annotations on Java types could be used
Annotation index file specification
http://pag.csail.mit.edu/javari/index-file-format.pdf
File format for describing annotations outside a .java file; useful
for tools, though not necessarily a part of this JSR.
Related JSRs:
JSR 175: A Metadata Facility for the Java Programming Language
http://jcp.org/en/jsr/detail?id=175
JSR 250: Common Annotations for the Java Platform
http://jcp.org/en/jsr/detail?id=250
JSR 269: Pluggable Annotation Processing API
http://jcp.org/en/jsr/detail?id=269
JSR 305: Annotations for Software Defect Detection
http://jcp.org/en/jsr/detail?id=305
The JSR will build directly on these documents, especially the first one listed above.
Section 4: Additional Information (Optional)