8331579: Reference to primitive type fails without error or warning
Reviewed-by: jjg, prappo
This commit is contained in:
parent
32ee252c45
commit
1e04ee6d57
@ -78,6 +78,7 @@ import com.sun.source.doctree.ProvidesTree;
|
||||
import com.sun.source.doctree.RawTextTree;
|
||||
import com.sun.source.doctree.ReferenceTree;
|
||||
import com.sun.source.doctree.ReturnTree;
|
||||
import com.sun.source.doctree.SeeTree;
|
||||
import com.sun.source.doctree.SerialDataTree;
|
||||
import com.sun.source.doctree.SerialFieldTree;
|
||||
import com.sun.source.doctree.SinceTree;
|
||||
@ -151,6 +152,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
private int implicitHeadingRank;
|
||||
private boolean inIndex;
|
||||
private boolean inLink;
|
||||
private boolean inSee;
|
||||
private boolean inSummary;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Top level">
|
||||
@ -903,6 +905,16 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitSee(SeeTree node, Void unused) {
|
||||
try {
|
||||
inSee = true;
|
||||
return super.visitSee(node, unused);
|
||||
} finally {
|
||||
inSee = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Void visitLiteral(LiteralTree tree, Void ignore) {
|
||||
markEnclosingTag(Flag.HAS_INLINE_TAG);
|
||||
@ -984,6 +996,9 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
Element e = env.trees.getElement(getCurrentPath());
|
||||
if (e == null) {
|
||||
reportBadReference(tree);
|
||||
} else if ((inLink || inSee)
|
||||
&& e.getKind() == ElementKind.CLASS && e.asType().getKind() != TypeKind.DECLARED) {
|
||||
reportBadReference(tree);
|
||||
}
|
||||
return super.visitReference(tree, ignore);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2024, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8284030 8307377
|
||||
* @bug 8284030 8307377 8331579
|
||||
* @summary LinkFactory should not attempt to link to primitive types
|
||||
* @library /tools/lib ../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
@ -88,6 +88,64 @@ public class TestLinkTagletPrimitive extends JavadocTester {
|
||||
</div>
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleDocLint(Path base) throws IOException {
|
||||
Path src = base.resolve("src");
|
||||
|
||||
tb.writeJavaFiles(src, """
|
||||
/**
|
||||
* Comment.
|
||||
* Double: {@link double}
|
||||
* Void: {@link void}
|
||||
* @see int
|
||||
*/
|
||||
public class C {\s
|
||||
private C() { }
|
||||
}
|
||||
""");
|
||||
|
||||
javadoc("-Xdoclint:reference",
|
||||
"-d", base.resolve("api").toString(),
|
||||
"-sourcepath", src.toString(),
|
||||
src.resolve("C.java").toString());
|
||||
checkExit(Exit.ERROR);
|
||||
|
||||
checkOutput(Output.OUT, true,
|
||||
"C.java:3: error: reference not found",
|
||||
"C.java:4: error: reference not found",
|
||||
"C.java:5: error: reference not found");
|
||||
|
||||
checkOutput("C.html", true,
|
||||
"""
|
||||
<div class="block">Comment.
|
||||
Double:\s
|
||||
<details class="invalid-tag">
|
||||
<summary>invalid reference</summary>
|
||||
<pre><code>double</code></pre>
|
||||
</details>
|
||||
|
||||
Void:\s
|
||||
<details class="invalid-tag">
|
||||
<summary>invalid reference</summary>
|
||||
<pre><code>void</code></pre>
|
||||
</details>
|
||||
</div>
|
||||
""",
|
||||
"""
|
||||
<dt>See Also:</dt>
|
||||
<dd>
|
||||
<ul class="tag-list">
|
||||
<li>
|
||||
<details class="invalid-tag">
|
||||
<summary>invalid reference</summary>
|
||||
<pre><code>int</code></pre>
|
||||
</details>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray(Path base) throws IOException {
|
||||
Path src = base.resolve("src");
|
||||
@ -122,4 +180,54 @@ public class TestLinkTagletPrimitive extends JavadocTester {
|
||||
</div>
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayDocLint(Path base) throws IOException {
|
||||
Path src = base.resolve("src");
|
||||
|
||||
tb.writeJavaFiles(src, """
|
||||
/**
|
||||
* Comment.
|
||||
* Double[]: {@link double[]}
|
||||
* @see int[]
|
||||
*/
|
||||
public class C {\s
|
||||
private C() { }
|
||||
}
|
||||
""");
|
||||
|
||||
javadoc("-Xdoclint:reference",
|
||||
"-d", base.resolve("api").toString(),
|
||||
"-sourcepath", src.toString(),
|
||||
src.resolve("C.java").toString());
|
||||
checkExit(Exit.ERROR);
|
||||
|
||||
checkOutput(Output.OUT, true,
|
||||
"C.java:3: error: reference not found",
|
||||
"C.java:4: error: reference not found");
|
||||
|
||||
checkOutput("C.html", true,
|
||||
"""
|
||||
<div class="block">Comment.
|
||||
Double[]:\s
|
||||
<details class="invalid-tag">
|
||||
<summary>invalid reference</summary>
|
||||
<pre><code>double[]</code></pre>
|
||||
</details>
|
||||
</div>
|
||||
""",
|
||||
"""
|
||||
<dt>See Also:</dt>
|
||||
<dd>
|
||||
<ul class="tag-list">
|
||||
<li>
|
||||
<details class="invalid-tag">
|
||||
<summary>invalid reference</summary>
|
||||
<pre><code>int[]</code></pre>
|
||||
</details>
|
||||
</li>
|
||||
</ul>
|
||||
</dd>
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user