A DESCRIPTION OF THE PROBLEM :
In an array constructor reference like String[]::new the array type may be annotated. However, if both array type and its element type are annotated, e.g.
@Anno1 String @Anno2 []::new
the compiler crashes with exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the provided executable test case with javac.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation succeeds.
ACTUAL -
javac crashes with the following stack trace:
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
at jdk.compiler/com.sun.tools.javac.code.Type.addMetadata(Type.java:389)
at jdk.compiler/com.sun.tools.javac.code.Type.preannotatedType(Type.java:452)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnnotatedType(Attr.java:5271)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotatedType.accept(JCTree.java:3101)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReference(Attr.java:3601)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:2662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:2475)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1728)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:755)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1439)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1229)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:916)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5655)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5543)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5367)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5306)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1359)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:976)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
---------- BEGIN SOURCE ----------
import java.lang.annotation.*;
import java.util.function.Function;
class Test {
@Target(ElementType.TYPE_USE)
@interface Anno1 { }
@Target(ElementType.TYPE_USE)
@interface Anno2 { }
Function<Integer, String[]> method() {
return @Anno1 String @Anno2 []::new;
}
}
---------- END SOURCE ----------
FREQUENCY : always
In an array constructor reference like String[]::new the array type may be annotated. However, if both array type and its element type are annotated, e.g.
@Anno1 String @Anno2 []::new
the compiler crashes with exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the provided executable test case with javac.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation succeeds.
ACTUAL -
javac crashes with the following stack trace:
java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
at jdk.compiler/com.sun.tools.javac.code.Type.addMetadata(Type.java:389)
at jdk.compiler/com.sun.tools.javac.code.Type.preannotatedType(Type.java:452)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnnotatedType(Attr.java:5271)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotatedType.accept(JCTree.java:3101)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReference(Attr.java:3601)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:2662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:2475)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1728)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:755)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1439)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1229)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:916)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:662)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:736)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5655)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5543)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5367)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5306)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1359)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:976)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
---------- BEGIN SOURCE ----------
import java.lang.annotation.*;
import java.util.function.Function;
class Test {
@Target(ElementType.TYPE_USE)
@interface Anno1 { }
@Target(ElementType.TYPE_USE)
@interface Anno2 { }
Function<Integer, String[]> method() {
return @Anno1 String @Anno2 []::new;
}
}
---------- END SOURCE ----------
FREQUENCY : always