8320948: NPE due to unreported compiler error

Reviewed-by: jlahoda
This commit is contained in:
Vicente Romero 2023-12-06 16:48:08 +00:00
parent 4ef24e2596
commit a9cb120d03
3 changed files with 35 additions and 1 deletions
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/recovery

@ -1089,7 +1089,10 @@ public class DeferredAttr extends JCTree.Visitor {
boolean isLambdaOrMemberRef =
dt.tree.hasTag(REFERENCE) || dt.tree.hasTag(LAMBDA);
boolean needsRecoveryType =
pt == null || (isLambdaOrMemberRef && !types.isFunctionalInterface(pt));
pt == null ||
((dt instanceof ArgumentAttr.ArgumentType<?> at) &&
at.speculativeTypes.values().stream().allMatch(type -> type.hasTag(ERROR))) ||
(isLambdaOrMemberRef && !types.isFunctionalInterface(pt));
Type ptRecovery = needsRecoveryType ? Type.recoveryType: pt;
dt.check(attr.new RecoveryInfo(deferredAttrContext, ptRecovery) {
@Override

@ -0,0 +1,29 @@
/**
* @test /nodynamiccopyright/
* @bug 8320948
* @summary NPE due to unreported compiler error
* @compile/fail/ref=CrashDueToUnreportedError.out -XDrawDiagnostics CrashDueToUnreportedError.java
*/
import java.util.List;
public class CrashDueToUnreportedError {
class Builder {
private Builder(Person person, String unused) {}
public Builder withTypes(Entity<String> entities) {
return new Builder(Person.make(Entity.combineAll(entities)));
}
}
interface Person {
static <E> Person make(List<? extends Entity<E>> eventSubtypes) {
return null;
}
}
class Entity<E> {
public static <Root> List<? extends Entity<Root>> combineAll(Entity<Root> subtypes) {
return null;
}
}
}

@ -0,0 +1,2 @@
CrashDueToUnreportedError.java:14:43: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: E,compiler.misc.type.captureof: 1, ? extends CrashDueToUnreportedError.Entity<Root>,Root, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 2, ? extends CrashDueToUnreportedError.Entity<Root>>, java.util.List<? extends CrashDueToUnreportedError.Entity<java.lang.Object>>))
1 error