SafeVarargs classfile encoding

Joe Darcy joe.darcy at oracle.com
Fri Jan 21 10:56:59 PST 2011


Paul,

The additional restrictions are given in the specification of the 
annotation type:

http://download.java.net/jdk7/docs/api/java/lang/SafeVarargs.html

>
>  In addition to the usage restrictions imposed by its @Target 
> meta-annotation, compilers are required to implement additional usage 
> restrictions on this annotation type; it is a compile-time error if a 
> method or constructor declaration is annotated with a @SafeVarargs 
> annotation, and either:
>
>     * the declaration is a fixed-arity method or constructor
>     * the declaration is a variable-arity method that is neither 
> static nor final.

-Joe

Paul Benedict wrote:
> Joe,
>
> Will there be any language restriction on using @SafeVarargs for 
> non-var arg methods? After all, it's just an annotation so I wonder if 
> normal annotation rules apply or it has restricted syntax.
>
> Paul
>
> On Fri, Jan 21, 2011 at 12:50 PM, Joe Darcy <joe.darcy at oracle.com 
> <mailto:joe.darcy at oracle.com>> wrote:
>
>     Hi Rémi.
>
>     A few comments, in the entirety of the "jdk" repository, there were a
>     total of five methods where it was appropriate to add this annotation,
>     which is not a very high density!  For Coin, to keep the features
>     small,
>     we're avoiding JVM changes and defining a new attribute is a JVM
>     changes
>     of sorts.
>
>     The SafeVarargs information is needed in the class file in some
>     fashion
>     to so that compilers can know to omit unchecked warnings that would
>     otherwise have to be emitted.  Additionally, having the information in
>     the class file enables tools like findbugs to do additional
>     checking on
>     the operations of the SafeVarargs methods.
>
>     Using an annotation to store this information avoids the need to add a
>     new core reflection API to access it, Method.isSafeVarargs, etc.
>
>     -Joe
>
>     Rémi Forax wrote:
>     > I wonder if encoding @SafeVarargs as a runtime annotation
>     > in the classfile is a good idea. A runtime visible annotation is
>     fat.
>     >
>     > In my opinion, @SafeVarargs should be an annotation with
>     > retention SOURCE, translated by the compiler to an empty SafeVarargs
>     > method attribute.
>     >
>     > Is there a use case where this annotation is needed at runtime ?
>     >
>     > Rémi
>     >
>     >
>
>
>




More information about the coin-dev mailing list