-
Bug
-
Resolution: Fixed
-
P4
-
11, 17, 23, 24
A DESCRIPTION OF THE PROBLEM :
javac throws an internal java compiler error when compiling code with annotations on constants in @interface
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a Java class containing an annotation (@interface) with a constant field that applies an annotation to the constant.
Define a @Target(ElementType.TYPE_USE) annotation in the @interface.
Attempt to compile the following code:
package com.my.company;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
public class Client {
public void packs3_new() {
// Attempt to use the constant in the code
float y = Client.ThreeFieldPack.EMPTY_PACK;
}
@Target(ElementType.TYPE_USE)
public @interface ThreeFieldPack {
// Invalid annotation usage on a constant field
@Client.ThreeFieldPack float EMPTY_PACK = (@Client.ThreeFieldPack float) 0;
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile successfully, and the annotation @Client.ThreeFieldPack should be applied correctly in places where type annotations are supported, such as variable declarations or method parameters. Specifically:
The annotation should not be applied to constants within the annotation itself.
ACTUAL -
When attempting to compile the code with javac, the following error is encountered:
java: Compilation failed: internal java compiler error
The error message does not provide specific details or a helpful stack trace to diagnose the cause of the failure.
javac throws an internal java compiler error when compiling code with annotations on constants in @interface
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a Java class containing an annotation (@interface) with a constant field that applies an annotation to the constant.
Define a @Target(ElementType.TYPE_USE) annotation in the @interface.
Attempt to compile the following code:
package com.my.company;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
public class Client {
public void packs3_new() {
// Attempt to use the constant in the code
float y = Client.ThreeFieldPack.EMPTY_PACK;
}
@Target(ElementType.TYPE_USE)
public @interface ThreeFieldPack {
// Invalid annotation usage on a constant field
@Client.ThreeFieldPack float EMPTY_PACK = (@Client.ThreeFieldPack float) 0;
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile successfully, and the annotation @Client.ThreeFieldPack should be applied correctly in places where type annotations are supported, such as variable declarations or method parameters. Specifically:
The annotation should not be applied to constants within the annotation itself.
ACTUAL -
When attempting to compile the code with javac, the following error is encountered:
java: Compilation failed: internal java compiler error
The error message does not provide specific details or a helpful stack trace to diagnose the cause of the failure.
- links to
-
Commit(master) openjdk/jdk/0395593a
-
Review(master) openjdk/jdk/23029