diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java index e5e607784a2..1a12e939f4f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java @@ -280,9 +280,10 @@ public class DocCommentParser { } } } + int prefPos = bp; blockContent(); - return erroneous("dc.no.tag.name", p); + return erroneous("dc.no.tag.name", p, prefPos); } catch (ParseException e) { blockContent(); return erroneous(e.getMessage(), p, e.pos); @@ -315,7 +316,7 @@ public class DocCommentParser { try { nextChar(); if (!isIdentifierStart(ch)) { - return erroneous("dc.no.tag.name", p); + return erroneous("dc.no.tag.name", p, bp); } Name name = readTagName(); TagParser tp = tagParsers.get(name); diff --git a/test/langtools/jdk/javadoc/doclet/testNoTagName/TestNoTagName.java b/test/langtools/jdk/javadoc/doclet/testNoTagName/TestNoTagName.java new file mode 100644 index 00000000000..c12a4d878b1 --- /dev/null +++ b/test/langtools/jdk/javadoc/doclet/testNoTagName/TestNoTagName.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2023, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8301813 + * @summary Bad caret position in error message + * @library /tools/lib ../../lib + * @modules jdk.javadoc/jdk.javadoc.internal.tool + * @build toolbox.ToolBox javadoc.tester.* + * @run main TestNoTagName + */ + +import java.nio.file.Path; + +import javadoc.tester.JavadocTester; +import toolbox.ToolBox; + +public class TestNoTagName extends JavadocTester { + + public static void main(String... args) throws Exception { + var test = new TestNoTagName(); + test.runTests(); + } + + private ToolBox tb = new ToolBox(); + + @Test + public void test_inline_missing(Path base) throws Exception { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, """ + /** + * abc {@ } def + */ + public class C { private C() { } } + """ + ); + javadoc("-d", base.resolve("api").toString(), + src.resolve("C.java").toString() + ); + checkExit(Exit.ERROR); + checkOutput(Output.OUT, true, """ + C.java:2: error: no tag name after '@' + * abc {@ } def + ^ + """); + } + + @Test + public void test_inline_bad(Path base) throws Exception { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, """ + /** + * abc {@/ } def + */ + public class C { private C() { } } + """ + ); + javadoc("-d", base.resolve("api").toString(), + src.resolve("C.java").toString() + ); + checkExit(Exit.ERROR); + checkOutput(Output.OUT, true, """ + C.java:2: error: no tag name after '@' + * abc {@/ } def + ^ + """); + } + + @Test + public void test_block_missing(Path base) throws Exception { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, """ + /** + * abc. + * @ def + */ + public class C { private C() { } } + """ + ); + javadoc("-d", base.resolve("api").toString(), + src.resolve("C.java").toString() + ); + checkExit(Exit.ERROR); + checkOutput(Output.OUT, true, """ + C.java:3: error: no tag name after '@' + * @ def + ^ + """); + } + + @Test + public void test_block_bad(Path base) throws Exception { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, """ + /** + * abc. + * @/ def + */ + public class C { private C() { } } + """ + ); + javadoc("-d", base.resolve("api").toString(), + src.resolve("C.java").toString() + ); + checkExit(Exit.ERROR); + checkOutput(Output.OUT, true, """ + C.java:3: error: no tag name after '@' + * @/ def + ^ + """); + } +} diff --git a/test/langtools/tools/doclint/BadPackageCommentTest.java b/test/langtools/tools/doclint/BadPackageCommentTest.java index 85d24e05fda..1f778cfc6a9 100644 --- a/test/langtools/tools/doclint/BadPackageCommentTest.java +++ b/test/langtools/tools/doclint/BadPackageCommentTest.java @@ -9,6 +9,6 @@ /** * abc. - * @@@ + * @!# */ package p; diff --git a/test/langtools/tools/doclint/BadPackageCommentTest.out b/test/langtools/tools/doclint/BadPackageCommentTest.out index 136792f5852..d4d33e60970 100644 --- a/test/langtools/tools/doclint/BadPackageCommentTest.out +++ b/test/langtools/tools/doclint/BadPackageCommentTest.out @@ -2,13 +2,7 @@ BadPackageCommentTest.java:14: warning: documentation comment not expected here package p; ^ BadPackageCommentTest.java:12: error: no tag name after '@' - * @@@ - ^ -BadPackageCommentTest.java:12: error: no tag name after '@' - * @@@ + * @!# ^ -BadPackageCommentTest.java:12: error: no tag name after '@' - * @@@ - ^ -3 errors +1 error 1 warning diff --git a/test/langtools/tools/javac/doctree/TagTest.java b/test/langtools/tools/javac/doctree/TagTest.java index 34ac83c6a3d..99a293871b7 100644 --- a/test/langtools/tools/javac/doctree/TagTest.java +++ b/test/langtools/tools/javac/doctree/TagTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 8078320 8273244 8284908 8301201 + * @bug 7021614 8078320 8273244 8284908 8301201 8301813 * @summary extend com.sun.source API to support parsing javadoc comments * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file @@ -93,7 +93,7 @@ DocComment[DOC_COMMENT, pos:1 firstSentence: empty body: empty block tags: 1 - Erroneous[ERRONEOUS, pos:1, prefPos:5 + Erroneous[ERRONEOUS, pos:1, prefPos:2 code: compiler.err.dc.no.tag.name body: @_abc ] @@ -141,7 +141,7 @@ DocComment[DOC_COMMENT, pos:1 /* DocComment[DOC_COMMENT, pos:1 firstSentence: 2 - Erroneous[ERRONEOUS, pos:1, prefPos:2 + Erroneous[ERRONEOUS, pos:1, prefPos:3 code: compiler.err.dc.no.tag.name body: {@ ]