strictfp in annotations

Alex Buckley alex.buckley at oracle.com
Fri Nov 15 10:52:50 PST 2013


First, ignore the separate grammar in JLS7 chapter 18. It has caused 
nothing but confusion for years, and is replaced in JLS8 with a 
concatenation of the grammars from the preceding chapters.

Second, an element of an annotation type should never be strictfp. JLS7 
9.6.1 was clear about that, since AbstractMethodModifiers disallowed 
strictfp.

For JLS8, the Lambda spec drops AbstractMethodModifiers. Instead, it 
uses InterfaceMethodModifiers in interface declarations - which allows 
strictfp due to default methods - and AnnotationTypeElementModifiers in 
annotation type declarations - which continues to disallow strictfp. I 
expect javac is erroneously parsing for InterfaceMethodModifiers in 
annotation type declarations. static would be another modifier to try.

Alex

On 11/15/2013 5:09 AM, Joel Borggren-Franck wrote:
> Hi Alex,
>
> https://bugs.openjdk.java.net/browse/JDK-8028428
>
> tl;dr
>
> The following file does not compile in 7:
>
> import java.lang.annotation.*;
> @Retention(RetentionPolicy.RUNTIME)
> @interface T {
>      strictfp float ff() default -1.0f;
> }
>
>
> $ javac T.java
> T.java:4: error: modifier strictfp not allowed here
> strictfp float ff() default -1.0f;
>                 ^
> 1 error
>
> In 8 it compiles.
>
> JLS for 7 is actually slightly inconsistent here, the grammar in 9.6.1
> says AbstractMethodModifier but the grammar in chapter 18 says modifier.
>
> Question: is the grammar in 8 fixed? I assume AbstractMethodModifier is
> correct.
>
> cheers
> /Joel
>


More information about the compiler-dev mailing list