Skip to content

Commit 64c3642

Browse files
Vladimir Petkojonathan-gibbons
Vladimir Petko
authored andcommittedJan 29, 2024
8242564: javadoc crashes:: class cast exception com.sun.tools.javac.code.Symtab$6
Reviewed-by: jjg
1 parent e999dfc commit 64c3642

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ToolEnvironment.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2023, 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
@@ -31,6 +31,7 @@
3131
import javax.lang.model.element.Element;
3232
import javax.lang.model.element.TypeElement;
3333
import javax.lang.model.util.Elements;
34+
import javax.lang.model.type.TypeKind;
3435
import javax.tools.JavaFileManager;
3536
import javax.tools.JavaFileObject;
3637
import javax.tools.JavaFileObject.Kind;
@@ -181,6 +182,8 @@ void setElementToTreePath(Element e, TreePath tree) {
181182
}
182183

183184
public Kind getFileKind(TypeElement te) {
185+
if (te.asType().getKind() == TypeKind.ERROR)
186+
return Kind.OTHER;
184187
JavaFileObject jfo = ((ClassSymbol)te).outermostClass().classfile;
185188
return jfo == null ? Kind.SOURCE : jfo.getKind();
186189
}

‎test/langtools/jdk/javadoc/doclet/testClassTree/TestClassTree.java

+57-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2023, 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
@@ -23,26 +23,79 @@
2323

2424
/*
2525
* @test
26-
* @bug 4632553 4973607 8026567
26+
* @bug 4632553 4973607 8026567 8242564
2727
* @summary No need to include type name (class, interface, etc.) before
2828
* every single type in class tree.
2929
* Make sure class tree includes heirarchy for enums and annotation
3030
* types.
31-
* @library ../../lib
31+
* Make sure class tree handles undefined types in the class
32+
* hierarchy.
33+
* @library /tools/lib ../../lib
3234
* @modules jdk.javadoc/jdk.javadoc.internal.tool
33-
* @build javadoc.tester.*
35+
* @build toolbox.ToolBox javadoc.tester.*
3436
* @run main TestClassTree
3537
*/
3638

39+
import java.io.IOException;
40+
import java.nio.file.Path;
41+
3742
import javadoc.tester.JavadocTester;
43+
import toolbox.ToolBox;
3844

3945
public class TestClassTree extends JavadocTester {
4046

47+
private final ToolBox tb = new ToolBox();
48+
4149
public static void main(String... args) throws Exception {
4250
var tester = new TestClassTree();
4351
tester.runTests();
4452
}
4553

54+
/**
55+
* Given badpkg package containing class ChildClass with UndefinedClass
56+
* base class, implementing UndefinedInterface and a defined
57+
* interface
58+
* When the javadoc is generated with '--ignore-source-errors option'
59+
* Then javadoc exits successfully
60+
* And generates html for the ChildClass with UndefinedClass base class
61+
* And UndefinedInterface is not present in html
62+
*/
63+
@Test
64+
public void testBadPkg(Path base) throws IOException {
65+
Path src = base.resolve("src");
66+
tb.writeJavaFiles(src,
67+
"""
68+
package badpkg;
69+
public class ChildClass extends UndefinedClass
70+
implements UndefinedInterface, Iterable {
71+
72+
}
73+
"""
74+
);
75+
76+
javadoc("--ignore-source-errors",
77+
"-d", base.resolve("badout").toString(),
78+
"--no-platform-links",
79+
"-sourcepath", src.toString(),
80+
"badpkg");
81+
82+
83+
checkExit(Exit.OK);
84+
checkOutput("badpkg/package-tree.html", true,
85+
"""
86+
<li class="circle">badpkg.<a href="ChildClass.html" class="type-name-link" title="\
87+
class in badpkg">ChildClass</a> (implements java.lang.Iterable&lt;T&gt;)</li>
88+
""");
89+
checkOutput("badpkg/ChildClass.html", true,
90+
"""
91+
<div class="type-signature"><span class="modifiers">public class </span>\
92+
<span class="element-name type-name-label">ChildClass</span>
93+
<span class="extends-implements">extends UndefinedClass
94+
implements java.lang.Iterable</span></div>
95+
""");
96+
checkOutput("badpkg/ChildClass.html", false, "UndefinedInterface");
97+
}
98+
4699
@Test
47100
public void test() {
48101
javadoc("-d", "out",

0 commit comments

Comments
 (0)
Please sign in to comment.