Skip to content

Commit cb6167b

Browse files
lgxbslgxmcimadamore
authored andcommitted
8254557: Compiler crashes with java.lang.AssertionError: isSubtype UNKNOWN
Reviewed-by: mcimadamore
1 parent 40f847e commit cb6167b

File tree

2 files changed

+145
-0
lines changed
  • src/jdk.compiler/share/classes/com/sun/tools/javac/comp
  • test/langtools/tools/javac/T8254557

2 files changed

+145
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,26 @@ public void scan(JCTree tree) {
21082108
}
21092109
super.scan(tree);
21102110
}
2111+
2112+
@Override
2113+
public void visitClassDef(JCClassDecl that) {
2114+
if (that.sym != null) {
2115+
// Method preFlow shouldn't visit class definitions
2116+
// that have not been entered and attributed.
2117+
// See JDK-8254557 and JDK-8203277 for more details.
2118+
super.visitClassDef(that);
2119+
}
2120+
}
2121+
2122+
@Override
2123+
public void visitLambda(JCLambda that) {
2124+
if (that.type != null) {
2125+
// Method preFlow shouldn't visit lambda expressions
2126+
// that have not been entered and attributed.
2127+
// See JDK-8254557 and JDK-8203277 for more details.
2128+
super.visitLambda(that);
2129+
}
2130+
}
21112131
}.scan(tree);
21122132
}
21132133

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8254557
27+
* @summary Method Attr.preFlow shouldn't visit class definitions that have not yet been entered and attributed.
28+
* @compile T8254557.java
29+
*/
30+
31+
import java.util.Iterator;
32+
import java.util.function.Function;
33+
34+
public class T8254557 {
35+
// test anonymous class in if statement
36+
public <T> void testIf(boolean b) {
37+
test(rs -> {
38+
if (b) {
39+
return new Iterator<>() {
40+
@Override
41+
public boolean hasNext() {
42+
return true;
43+
}
44+
45+
@Override
46+
public T next() {
47+
return null;
48+
}
49+
};
50+
} else {
51+
return new Iterator<>() {
52+
@Override
53+
public boolean hasNext() {
54+
return true;
55+
}
56+
57+
@Override
58+
public T next() {
59+
return null;
60+
}
61+
};
62+
}
63+
});
64+
}
65+
66+
// test anonymous class in while statement
67+
public <T> void testWhile(boolean b) {
68+
test(rs -> {
69+
while (b) {
70+
return new Iterator<>() {
71+
@Override
72+
public boolean hasNext() {
73+
return true;
74+
}
75+
76+
@Override
77+
public T next() {
78+
return null;
79+
}
80+
};
81+
}
82+
return null;
83+
});
84+
}
85+
86+
// test anonymous class in do while statement
87+
public <T> void testDoWhileLoop(boolean b) {
88+
test(rs -> {
89+
do {
90+
return new Iterator<>() {
91+
@Override
92+
public boolean hasNext() {
93+
return true;
94+
}
95+
96+
@Override
97+
public T next() {
98+
return null;
99+
}
100+
};
101+
} while (b);
102+
});
103+
}
104+
105+
// test anonymous class in for statement
106+
public <T> void testForLoop(boolean b) {
107+
test(rs -> {
108+
for ( ; ; ) {
109+
return new Iterator<>() {
110+
@Override
111+
public boolean hasNext() {
112+
return true;
113+
}
114+
115+
@Override
116+
public T next() {
117+
return null;
118+
}
119+
};
120+
}
121+
});
122+
}
123+
124+
private void test(Function function) { }
125+
}

0 commit comments

Comments
 (0)