From 1e04ee6d57d5fe84e1d202b16e8d13dc13c002ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Fri, 31 May 2024 13:19:15 +0000 Subject: [PATCH] 8331579: Reference to primitive type fails without error or warning Reviewed-by: jjg, prappo --- .../jdk/javadoc/internal/doclint/Checker.java | 15 +++ .../TestLinkTagletPrimitive.java | 112 +++++++++++++++++- 2 files changed, 125 insertions(+), 2 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java index 559e520c7c902..8fbdce922fe69 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java @@ -78,6 +78,7 @@ 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 String toString() { private int implicitHeadingRank; private boolean inIndex; private boolean inLink; + private boolean inSee; private boolean inSummary; // @@ -903,6 +905,16 @@ public Void visitLink(LinkTree tree, Void ignore) { } } + @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 Void visitReference(ReferenceTree tree, Void ignore) { 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); } diff --git a/test/langtools/jdk/javadoc/doclet/testLinkTaglet/TestLinkTagletPrimitive.java b/test/langtools/jdk/javadoc/doclet/testLinkTaglet/TestLinkTagletPrimitive.java index 5b285e95f4abe..bca3e909462be 100644 --- a/test/langtools/jdk/javadoc/doclet/testLinkTaglet/TestLinkTagletPrimitive.java +++ b/test/langtools/jdk/javadoc/doclet/testLinkTaglet/TestLinkTagletPrimitive.java @@ -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 @@ private C() { } """); } + + @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, + """ +
Comment. + Double:\s +
+ invalid reference +
double
+
+ + Void:\s +
+ invalid reference +
void
+
+
+ """, + """ +
See Also:
+
+
    +
  • +
    + invalid reference +
    int
    +
    +
  • +
+
"""); + } + @Test public void testArray(Path base) throws IOException { Path src = base.resolve("src"); @@ -122,4 +180,54 @@ private C() { } """); } + + @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, + """ +
Comment. + Double[]:\s +
+ invalid reference +
double[]
+
+
+ """, + """ +
See Also:
+
+
    +
  • +
    + invalid reference +
    int[]
    +
    +
  • +
+
+ """); + } }