8334756: javac crashed on call to non-existent generic method with explicit annotated type arg

Reviewed-by: abimpoudis
This commit is contained in:
Vicente Romero 2024-12-11 02:12:23 +00:00
parent 2ddaa46054
commit abcd23f4d6
3 changed files with 29 additions and 1 deletions

View File

@ -1018,7 +1018,11 @@ public class TypeAnnotations {
if (!invocation.typeargs.contains(tree)) {
return TypeAnnotationPosition.unknown;
}
MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect());
Symbol exsym = TreeInfo.symbol(invocation.getMethodSelect());
if (exsym.type.isErroneous()) {
// bail out, don't deal with erroneous types which would be reported anyways
return TypeAnnotationPosition.unknown;
}
final int type_index = invocation.typeargs.indexOf(tree);
if (exsym == null) {
throw new AssertionError("could not determine symbol for {" + invocation + "}");

View File

@ -0,0 +1,22 @@
/*
* @test /nodynamiccopyright/
* @bug 8334756
* @summary javac crashes on call to non-existent generic method with explicit annotated type arg
* @compile/fail/ref=CrashOnNonExistingMethodTest.out -XDrawDiagnostics -XDdev CrashOnNonExistingMethodTest.java
*/
import static java.lang.annotation.ElementType.TYPE_USE;
import java.lang.annotation.Target;
class CrashOnNonExistingMethodTest {
@Target(TYPE_USE)
@interface Nullable {}
static <T extends @Nullable Object> T identity(T t) {
return t;
}
static void test() {
CrashOnNonExistingMethodTest.<@Nullable Object>nonNullIdentity(null);
}
}

View File

@ -0,0 +1,2 @@
CrashOnNonExistingMethodTest.java:20:37: compiler.err.cant.resolve.location.args.params: kindname.method, nonNullIdentity, java.lang.Object, compiler.misc.type.null, (compiler.misc.location: kindname.class, CrashOnNonExistingMethodTest, null)
1 error