8349512: Duplicate PermittedSubclasses entries with doclint enabled

Reviewed-by: vromero
This commit is contained in:
Liam Miller-Cushon 2025-02-07 19:43:33 +00:00
parent b40f8eef98
commit bd9b24c0f8
2 changed files with 35 additions and 3 deletions

View File

@ -1353,8 +1353,8 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
int index = Collections.binarySearch(permitted, element, java.util.Comparator.comparing(PermittedClassWithPos::pos));
if (index < 0) {
index = -index - 1;
permitted.add(index, element);
}
permitted.add(index, element);
}
public boolean isPermittedSubclass(Symbol csym) {

View File

@ -22,7 +22,7 @@
*/
/*
* @test 8247352 8293348
* @test 8247352 8293348 8349512
* @summary test different configurations of sealed classes, same compilation unit, diff pkg or mdl, etc
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -132,7 +132,10 @@ public class SealedDiffConfigurationsTest extends TestRunner {
ClassModel sealedCF = ClassFile.of().parse(out.resolve(cfName));
Assert.check((sealedCF.flags().flagsMask() & ClassFile.ACC_FINAL) == 0, String.format("class at file %s must not be final", cfName));
PermittedSubclassesAttribute permittedSubclasses = sealedCF.findAttribute(Attributes.permittedSubclasses()).orElseThrow();
Assert.check(permittedSubclasses.permittedSubclasses().size() == expectedSubTypeNames.size());
Assert.check(permittedSubclasses.permittedSubclasses().size() == expectedSubTypeNames.size(),
String.format("%s != %s",
permittedSubclasses.permittedSubclasses(),
expectedSubTypeNames));
List<String> subtypeNames = new ArrayList<>();
permittedSubclasses.permittedSubclasses().forEach(i -> {
try {
@ -726,4 +729,33 @@ public class SealedDiffConfigurationsTest extends TestRunner {
.run();
checkSealedClassFile(out, "Foo.class", List.of("Foo$R1", "Foo$R2"));
}
@Test
public void testDuplicatePermittedSubclassesDoclint(Path base) throws Exception {
Path src = base.resolve("src");
Path foo = src.resolve("Foo.java");
tb.writeFile(foo,
"""
public class Foo {
private enum E {
INSTANCE {
/** foo {@link E} */
void f() {}
};
void f() {}
}
}
""");
Path out = base.resolve("out");
Files.createDirectories(out);
new JavacTask(tb)
.options("-Xdoclint:html,syntax")
.outdir(out)
.files(foo)
.run();
checkSealedClassFile(out, "Foo$E.class", List.of("Foo$E$1"));
}
}