Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3971,7 +3971,7 @@ else if (compound.tail.isEmpty())
* Return the minimum types of a closure, suitable for computing
* compoundMin or glb.
*/
private List<Type> closureMin(List<Type> cl) {
public List<Type> closureMin(List<Type> cl) {
ListBuffer<Type> classes = new ListBuffer<>();
ListBuffer<Type> interfaces = new ListBuffer<>();
Set<Type> toSkip = new HashSet<>();
Expand Down
19 changes: 11 additions & 8 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -1854,14 +1854,17 @@ private Type erasedSuper(Type t1, Type t2) {
} else {
t1 = types.skipTypeVars(t1, false);
t2 = types.skipTypeVars(t2, false);
List<Type> intersection = types.intersect(
t1.hasTag(ARRAY) ?
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
types.erasedSupertypes(t1),
t2.hasTag(ARRAY) ?
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
types.erasedSupertypes(t2));
return intersection.head;
List<Type> result = types.closureMin(
types.intersect(
t1.hasTag(ARRAY) ?
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
types.erasedSupertypes(t1),
t2.hasTag(ARRAY) ?
List.of(syms.serializableType, syms.cloneableType, syms.objectType) :
types.erasedSupertypes(t2)
)
);
return result.head;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @summary VerifyError after JDK-8369654, incorrect supertype
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.javac.util
* jdk.compiler/com.sun.tools.javac.code
* @build toolbox.ToolBox toolbox.JavacTask
* @run main VerifierErrorWrongSuperTypeTest
*/

import java.util.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import toolbox.TestRunner;
import toolbox.ToolBox;
import toolbox.JavaTask;
import toolbox.JavacTask;
import toolbox.Task;
import toolbox.Task.OutputKind;

public class VerifierErrorWrongSuperTypeTest extends TestRunner {
ToolBox tb;

VerifierErrorWrongSuperTypeTest() {
super(System.err);
tb = new ToolBox();
}

protected void runTests() throws Exception {
runTests(m -> new Object[]{Paths.get(m.getName())});
}

Path[] findJavaFiles(Path... paths) throws IOException {
return tb.findJavaFiles(paths);
}

public static void main(String... args) throws Exception {
VerifierErrorWrongSuperTypeTest t = new VerifierErrorWrongSuperTypeTest();
t.runTests();
}

@Test
public void testCompatibilityAfterMakingSuperclassSealed(Path base) throws Exception {
Path src = base.resolve("src");
Path pkg = src.resolve("p");
Path v = pkg.resolve("V");
tb.writeJavaFiles(v,
"""
package p;
public abstract class V {}
"""
);
Path d = pkg.resolve("D");
tb.writeJavaFiles(d,
"""
package p;
public abstract class D extends V implements Cloneable {}
"""
);
Path a = pkg.resolve("A");
tb.writeJavaFiles(a,
"""
package p;
public class A extends V implements Cloneable {}
"""
);
Path t = src.resolve("T");
tb.writeJavaFiles(t,
"""
import p.A;
import p.D;
import p.V;
class T {
public static void main(String[] args) {
new T().foo(false, null);
}
void foo(boolean b, D d) {
V u = b ? d : new A();
g(u);
}
void g(V u) {}
}
"""
);
Path out = base.resolve("out");
Files.createDirectories(out);
new JavacTask(tb)
.outdir(out)
.files(findJavaFiles(src))
.run();

try {
new JavaTask(tb)
.classpath(out.toString())
.classArgs("T")
.run();
} catch (Throwable error) {
throw new AssertionError("execution failed");
}
}
}