JDK-8203277 : preflow visitor used during lambda attribution shouldn't visit class definitions inside the lambda body
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9,10,10.0.1,11
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-05-15
  • Updated: 2022-10-27
  • Resolved: 2018-11-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12
11.0.17Fixed 12 b22Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Linux (4.9.96-1-MANJARO) x86_64
OpenJDK 64-Bit Server VM (build 10.0.1+10, mixed mode)
and also OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)

A DESCRIPTION OF THE PROBLEM :
On complex diamond type inference, javac raise an exception without giving any information on the cause of the inference exception

REGRESSION : Last worked in version 8u172

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the class associated to the report.
guava-24.0 is required in the classpath

$ javac -classpath guava-24.0-jre.jar TestFail.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It compile or at least give interesting information about the cause and location of the failure
ACTUAL -
An exception has occurred in the compiler (9.0.4). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: isSubtype UNKNOWN
	at jdk.compiler/com.sun.tools.javac.code.Types$4.visitType(Types.java:803)
	at jdk.compiler/com.sun.tools.javac.code.Types$4.visitType(Types.java:780)
	at jdk.compiler/com.sun.tools.javac.code.Type.accept(Type.java:214)
	at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4614)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:776)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUncheckedInternal(Types.java:702)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUnchecked(Types.java:688)
	at jdk.compiler/com.sun.tools.javac.code.Types.isConvertible(Types.java:311)
	at jdk.compiler/com.sun.tools.javac.code.Types.isAssignable(Types.java:2070)
	at jdk.compiler/com.sun.tools.javac.comp.Check$1.compatible(Check.java:536)
	at jdk.compiler/com.sun.tools.javac.comp.Check.checkType(Check.java:577)
	at jdk.compiler/com.sun.tools.javac.comp.Check.checkType(Check.java:564)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.attributeAnnotationValues(Annotate.java:452)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.attributeAnnotation(Annotate.java:408)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.annotateNow(Annotate.java:334)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateLater$0(Annotate.java:260)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:184)
	at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:137)
	at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:210)
	at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:633)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1314)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:936)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnonymousClassDefinition(Attr.java:2302)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.lambda$visitAnonymousClassDefinition$2(Attr.java:2261)
	at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:265)
	at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:256)
	at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:248)
	at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:604)
	at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:643)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3998)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3791)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3698)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3677)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3664)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3549)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2104)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1911)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:693)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1155)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:950)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:742)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1203)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1094)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4562)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4454)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4383)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4328)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1329)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:959)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:302)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:162)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


---------- BEGIN SOURCE ----------
import java.util.List;
import java.util.function.Function;

import com.google.common.collect.Lists;

public final class TestFail {
	public void build() {
		List<Function<String, Double>> partialComputers = Lists.transform(null, builder -> new Function<>() {
			@Override public Double apply(String params) { return null; }
			@Override public String toString() { return null; }
		});
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
import java.util.List;
import java.util.function.Function;

import com.google.common.collect.Lists;

public final class TestOk {

	public void build() {
		List<Function<String, Double>> partialComputers = Lists.transform(null, builder -> new Function<String, Double>() {
			@Override public Double apply(String params) { return null; }
			@Override public String toString() { return null; }
		});
	}
}


FREQUENCY : always



Comments
Note for 11u: the change brings a regression JDK-8222251
27-10-2022

Fix request(11u) Request to backport this patch to jdk11u-dev. The code doesn't apply cleanly. One test case is removed from the original patch, because the jdk11-dev doesn't have the corresponding file `test/langtools/tools/javac/api/TestGetScopeResult.java`. Low risk: this patch has run well from jdk12. It is credible. Thanks.
10-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1207 Date: 2022-07-10 13:00:18 +0000
10-07-2022

URL: http://hg.openjdk.java.net/jdk/jdk/rev/605878cd4009 User: vromero Date: 2018-11-27 16:08:17 +0000
27-11-2018

review thread: http://mail.openjdk.java.net/pipermail/compiler-dev/2018-November/012600.html
08-11-2018

reduced test case without guava dependency: import java.util.List; import java.util.function.Function; public final class TestFail { public void build() { List<Function<String, Double>> list = transform(null, builder -> new Function<>() { public Double apply(String params) { return null; } }); } static <F,T> List<T> transform(List<F> fromList, Function<? super F,? extends T> function) { return null; } }
20-06-2018

This issue is reproducible in all the versions starting from 9 ea b59 (JDK-8062373) to 11 This is not regression, issue is due to diamond syntax are in conjunction with anonymous inner classes. Diamond and anonymous classes introduced in JDK-8062373(Project Coin) in 9 ea b59 Looks like this issue is related to JDK-8203195 (stack trace is different) Below is the snapshot of the javac crash executed on 11 ea b13 == -sh-4.2$ /scratch/fairoz/JAVA/jdk11/jdk-11-ea+13/bin/javac -cp ./guava-24.0-jre.jar TestFail.java An exception has occurred in the compiler (11-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.AssertionError: isSubtype UNKNOWN at jdk.compiler/com.sun.tools.javac.code.Types$4.visitType(Types.java:1112) at jdk.compiler/com.sun.tools.javac.code.Types$4.visitType(Types.java:1089) at jdk.compiler/com.sun.tools.javac.code.Type.accept(Type.java:214) at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4846) at jdk.compiler/com.sun.tools.javac.code.Types.isSubtype(Types.java:1085) at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUncheckedInternal(Types.java:1011) at jdk.compiler/com.sun.tools.javac.code.Types.isSubtypeUnchecked(Types.java:997) at jdk.compiler/com.sun.tools.javac.code.Types.isConvertible(Types.java:609) at jdk.compiler/com.sun.tools.javac.code.Types.isAssignable(Types.java:2308) at jdk.compiler/com.sun.tools.javac.comp.Check$1.compatible(Check.java:520) at jdk.compiler/com.sun.tools.javac.comp.Check.checkType(Check.java:561) at jdk.compiler/com.sun.tools.javac.comp.Check.checkType(Check.java:548) at jdk.compiler/com.sun.tools.javac.comp.Annotate.attributeAnnotationValues(Annotate.java:459) at jdk.compiler/com.sun.tools.javac.comp.Annotate.attributeAnnotation(Annotate.java:415) at jdk.compiler/com.sun.tools.javac.comp.Annotate.annotateNow(Annotate.java:341) at jdk.compiler/com.sun.tools.javac.comp.Annotate.lambda$annotateLater$0(Annotate.java:267) at jdk.compiler/com.sun.tools.javac.comp.Annotate.flush(Annotate.java:191) at jdk.compiler/com.sun.tools.javac.comp.Annotate.unblockAnnotations(Annotate.java:144) at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:213) at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:642) at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1326) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:941) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnonymousClassDefinition(Attr.java:2397) at jdk.compiler/com.sun.tools.javac.comp.Attr.lambda$visitAnonymousClassDefinition$2(Attr.java:2355) at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:265) at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:256) at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:241) at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:607) at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:646) at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:4152) at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3945) at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3846) at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3825) at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3812) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3705) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2110) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:695) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1174) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:956) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1294) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724) at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1098) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4715) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4606) at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4535) at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4480) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1341) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170) at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57) at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
16-05-2018