Skip to content

Commit c2228cc

Browse files
Satyen SubramaniamVictor Rudometov
authored andcommitted
8320948: NPE due to unreported compiler error
Backport-of: a9cb120d03e5b2efa244086e213d3b9e4706558a
1 parent d5a2f76 commit c2228cc

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,10 @@ private Type recover(DeferredType dt, Type pt) {
10891089
boolean isLambdaOrMemberRef =
10901090
dt.tree.hasTag(REFERENCE) || dt.tree.hasTag(LAMBDA);
10911091
boolean needsRecoveryType =
1092-
pt == null || (isLambdaOrMemberRef && !types.isFunctionalInterface(pt));
1092+
pt == null ||
1093+
((dt instanceof ArgumentAttr.ArgumentType<?> at) &&
1094+
at.speculativeTypes.values().stream().allMatch(type -> type.hasTag(ERROR))) ||
1095+
(isLambdaOrMemberRef && !types.isFunctionalInterface(pt));
10931096
Type ptRecovery = needsRecoveryType ? Type.recoveryType: pt;
10941097
dt.check(attr.new RecoveryInfo(deferredAttrContext, ptRecovery) {
10951098
@Override
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @test /nodynamiccopyright/
3+
* @bug 8320948
4+
* @summary NPE due to unreported compiler error
5+
* @compile/fail/ref=CrashDueToUnreportedError.out -XDrawDiagnostics CrashDueToUnreportedError.java
6+
*/
7+
8+
import java.util.List;
9+
10+
public class CrashDueToUnreportedError {
11+
class Builder {
12+
private Builder(Person person, String unused) {}
13+
public Builder withTypes(Entity<String> entities) {
14+
return new Builder(Person.make(Entity.combineAll(entities)));
15+
}
16+
}
17+
18+
interface Person {
19+
static <E> Person make(List<? extends Entity<E>> eventSubtypes) {
20+
return null;
21+
}
22+
}
23+
24+
class Entity<E> {
25+
public static <Root> List<? extends Entity<Root>> combineAll(Entity<Root> subtypes) {
26+
return null;
27+
}
28+
}
29+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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>>))
2+
1 error

0 commit comments

Comments
 (0)