Skip to content

Commit 8102f43

Browse files
author
Vicente Romero
committed
8371480: VerifyError after JDK-8369654
Reviewed-by: mcimadamore
1 parent 7d78818 commit 8102f43

File tree

3 files changed

+142
-9
lines changed

3 files changed

+142
-9
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3971,7 +3971,7 @@ else if (compound.tail.isEmpty())
39713971
* Return the minimum types of a closure, suitable for computing
39723972
* compoundMin or glb.
39733973
*/
3974-
private List<Type> closureMin(List<Type> cl) {
3974+
public List<Type> closureMin(List<Type> cl) {
39753975
ListBuffer<Type> classes = new ListBuffer<>();
39763976
ListBuffer<Type> interfaces = new ListBuffer<>();
39773977
Set<Type> toSkip = new HashSet<>();

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,14 +1854,17 @@ private Type erasedSuper(Type t1, Type t2) {
18541854
} else {
18551855
t1 = types.skipTypeVars(t1, false);
18561856
t2 = types.skipTypeVars(t2, false);
1857-
List<Type> intersection = types.intersect(
1858-
t1.hasTag(ARRAY) ?
1859-
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
1860-
types.erasedSupertypes(t1),
1861-
t2.hasTag(ARRAY) ?
1862-
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
1863-
types.erasedSupertypes(t2));
1864-
return intersection.head;
1857+
List<Type> result = types.closureMin(
1858+
types.intersect(
1859+
t1.hasTag(ARRAY) ?
1860+
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
1861+
types.erasedSupertypes(t1),
1862+
t2.hasTag(ARRAY) ?
1863+
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
1864+
types.erasedSupertypes(t2)
1865+
)
1866+
);
1867+
return result.head;
18651868
}
18661869
}
18671870

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright (c) 2025, 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+
* @summary VerifyError after JDK-8369654, incorrect supertype
27+
* @library /tools/lib
28+
* @modules jdk.compiler/com.sun.tools.javac.api
29+
* jdk.compiler/com.sun.tools.javac.main
30+
* jdk.compiler/com.sun.tools.javac.util
31+
* jdk.compiler/com.sun.tools.javac.code
32+
* @build toolbox.ToolBox toolbox.JavacTask
33+
* @run main VerifierErrorWrongSuperTypeTest
34+
*/
35+
36+
import java.util.*;
37+
38+
import java.io.IOException;
39+
import java.nio.file.Files;
40+
import java.nio.file.Path;
41+
import java.nio.file.Paths;
42+
43+
import toolbox.TestRunner;
44+
import toolbox.ToolBox;
45+
import toolbox.JavaTask;
46+
import toolbox.JavacTask;
47+
import toolbox.Task;
48+
import toolbox.Task.OutputKind;
49+
50+
public class VerifierErrorWrongSuperTypeTest extends TestRunner {
51+
ToolBox tb;
52+
53+
VerifierErrorWrongSuperTypeTest() {
54+
super(System.err);
55+
tb = new ToolBox();
56+
}
57+
58+
protected void runTests() throws Exception {
59+
runTests(m -> new Object[]{Paths.get(m.getName())});
60+
}
61+
62+
Path[] findJavaFiles(Path... paths) throws IOException {
63+
return tb.findJavaFiles(paths);
64+
}
65+
66+
public static void main(String... args) throws Exception {
67+
VerifierErrorWrongSuperTypeTest t = new VerifierErrorWrongSuperTypeTest();
68+
t.runTests();
69+
}
70+
71+
@Test
72+
public void testCompatibilityAfterMakingSuperclassSealed(Path base) throws Exception {
73+
Path src = base.resolve("src");
74+
Path pkg = src.resolve("p");
75+
Path v = pkg.resolve("V");
76+
tb.writeJavaFiles(v,
77+
"""
78+
package p;
79+
public abstract class V {}
80+
"""
81+
);
82+
Path d = pkg.resolve("D");
83+
tb.writeJavaFiles(d,
84+
"""
85+
package p;
86+
public abstract class D extends V implements Cloneable {}
87+
"""
88+
);
89+
Path a = pkg.resolve("A");
90+
tb.writeJavaFiles(a,
91+
"""
92+
package p;
93+
public class A extends V implements Cloneable {}
94+
"""
95+
);
96+
Path t = src.resolve("T");
97+
tb.writeJavaFiles(t,
98+
"""
99+
import p.A;
100+
import p.D;
101+
import p.V;
102+
class T {
103+
public static void main(String[] args) {
104+
new T().foo(false, null);
105+
}
106+
void foo(boolean b, D d) {
107+
V u = b ? d : new A();
108+
g(u);
109+
}
110+
void g(V u) {}
111+
}
112+
"""
113+
);
114+
Path out = base.resolve("out");
115+
Files.createDirectories(out);
116+
new JavacTask(tb)
117+
.outdir(out)
118+
.files(findJavaFiles(src))
119+
.run();
120+
121+
try {
122+
new JavaTask(tb)
123+
.classpath(out.toString())
124+
.classArgs("T")
125+
.run();
126+
} catch (Throwable error) {
127+
throw new AssertionError("execution failed");
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)