Skip to content

Commit 8193ba3

Browse files
SirYwellTheShermanTanker
authored andcommitted
8347562: javac crash due to type vars in permits clause
Reviewed-by: vromero
1 parent 7df21a8 commit 8193ba3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -875,7 +875,7 @@ public Object attribLazyConstantValue(Env<AttrContext> env,
875875
}
876876
}
877877

878-
/** Attribute type reference in an `extends' or `implements' clause.
878+
/** Attribute type reference in an `extends', `implements', or 'permits' clause.
879879
* Supertypes of anonymous inner classes are usually already attributed.
880880
*
881881
* @param tree The tree making up the type reference.
@@ -5407,6 +5407,10 @@ void attribClass(ClassSymbol c) throws CompletionFailure {
54075407
Set<Symbol> permittedTypes = new HashSet<>();
54085408
boolean sealedInUnnamed = c.packge().modle == syms.unnamedModule || c.packge().modle == syms.noModule;
54095409
for (Type subType : c.getPermittedSubclasses()) {
5410+
if (subType.isErroneous()) {
5411+
// the type already caused errors, don't produce more potentially misleading errors
5412+
continue;
5413+
}
54105414
boolean isTypeVar = false;
54115415
if (subType.getTag() == TYPEVAR) {
54125416
isTypeVar = true; //error recovery

test/langtools/tools/javac/sealed/SealedCompilationTests.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
2525
* SealedCompilationTests
2626
*
2727
* @test
28-
* @bug 8246353 8273257 8294550
28+
* @bug 8246353 8273257 8294550 8347562
2929
* @summary Negative compilation tests, and positive compilation (smoke) tests for sealed classes
3030
* @library /lib/combo /tools/lib
3131
* @modules
@@ -41,6 +41,7 @@
4141
import java.nio.file.Files;
4242
import java.nio.file.Path;
4343
import java.nio.file.Paths;
44+
import java.util.Collections;
4445
import java.util.List;
4546
import java.util.Set;
4647
import java.util.stream.Collectors;
@@ -61,6 +62,7 @@
6162
import toolbox.Task;
6263
import toolbox.Task.OutputKind;
6364

65+
import static org.junit.jupiter.api.Assertions.assertEquals;
6466
import static org.junit.jupiter.api.Assertions.fail;
6567

6668
class SealedCompilationTests extends CompilationTestCase {
@@ -560,6 +562,13 @@ sealed class C permits T {}
560562
""")) {
561563
assertFail("compiler.err.invalid.permits.clause", s);
562564
}
565+
assertFail("compiler.err.illegal.forward.ref", _ -> {
566+
assertEquals(Collections.nCopies(2, "compiler.err.illegal.forward.ref"), diags.keys());
567+
},
568+
"""
569+
sealed class Permits<X, Y> permits X, Y {}
570+
"""
571+
);
563572
}
564573

565574
@Test

0 commit comments

Comments
 (0)