You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to apply some annotations, defined by Java code, to Scala classes and methods. The annotations have @retention(RetentionPolicy.CLASS) as they are defined in Java. When applied to Java code, they show up as RuntimeInvisibleAnnotations in the class file generated by javac. However, when applied to Scala code, scalac generates them as RuntimeVisibleAnnotations. This semantic change breaks the framework I'm using.
Stephen Kell (stephenrkell) said:
Thanks for the confirmation. In the meantime I have worked around my problem by hacking the framework I'm using so that it doesn't care about attribute visibility. If I continue in this direction I'll have a go at patching the compiler to do the right thing (though this is looking unlikely for the moment).
I am trying to apply some annotations, defined by Java code, to Scala classes and methods. The annotations have @retention(RetentionPolicy.CLASS) as they are defined in Java. When applied to Java code, they show up as RuntimeInvisibleAnnotations in the class file generated by javac. However, when applied to Scala code, scalac generates them as RuntimeVisibleAnnotations. This semantic change breaks the framework I'm using.
Here is a minimal test case.
/* file MyAnnotation.java */
import java.lang.annotation.Retention;
@retention(java.lang.annotation.RetentionPolicy.CLASS)
@interface MyAnnotation {
public String blah();
}
/* file UsesAnnotation.scala */
@MyAnnotation(blah = "blah")
class UsesAnnotation {}
$ javac -version
javac 1.7.0_03
$ javac MyAnnotation.java
$ scalac -version
Scala compiler version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
$ scalac UsesAnnotation.java
$ javap -verbose UsesAnnotation.class | grep -i visible
RuntimeVisibleAnnotations:
#17 = Utf8 RuntimeVisibleAnnotations
Whereas if I write a class JUsesAnnotation:
/* file JUsesAnnotation.java */
@MyAnnotation(blah = "blah")
class JUsesAnnotation {}
$ javac JUsesAnnotation.java
$ javap -verbose JUsesAnnotation.class | grep -i visible
RuntimeInvisibleAnnotations:
#10 = Utf8 RuntimeInvisibleAnnotations
I've attached the .java, .scala and .class files, and also put them here:
http://www.inf.usi.ch/postdoc/kells/private/scala-annotations-mintest.tar.gz.
If there is a fix or workaround, it would be much appreciated! Let me know if I can supply any more details.
The text was updated successfully, but these errors were encountered: