Skip to content

Commit d53ade1

Browse files
8301813: Bad caret position in error message
Reviewed-by: iris
1 parent 8c01b6e commit d53ade1

File tree

5 files changed

+142
-14
lines changed

5 files changed

+142
-14
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ protected DCTree blockTag() {
280280
}
281281
}
282282
}
283+
int prefPos = bp;
283284
blockContent();
284285

285-
return erroneous("dc.no.tag.name", p);
286+
return erroneous("dc.no.tag.name", p, prefPos);
286287
} catch (ParseException e) {
287288
blockContent();
288289
return erroneous(e.getMessage(), p, e.pos);
@@ -315,7 +316,7 @@ protected DCTree inlineTag() {
315316
try {
316317
nextChar();
317318
if (!isIdentifierStart(ch)) {
318-
return erroneous("dc.no.tag.name", p);
319+
return erroneous("dc.no.tag.name", p, bp);
319320
}
320321
Name name = readTagName();
321322
TagParser tp = tagParsers.get(name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8301813
27+
* @summary Bad caret position in error message
28+
* @library /tools/lib ../../lib
29+
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30+
* @build toolbox.ToolBox javadoc.tester.*
31+
* @run main TestNoTagName
32+
*/
33+
34+
import java.nio.file.Path;
35+
36+
import javadoc.tester.JavadocTester;
37+
import toolbox.ToolBox;
38+
39+
public class TestNoTagName extends JavadocTester {
40+
41+
public static void main(String... args) throws Exception {
42+
var test = new TestNoTagName();
43+
test.runTests();
44+
}
45+
46+
private ToolBox tb = new ToolBox();
47+
48+
@Test
49+
public void test_inline_missing(Path base) throws Exception {
50+
Path src = base.resolve("src");
51+
tb.writeJavaFiles(src, """
52+
/**
53+
* abc {@ } def
54+
*/
55+
public class C { private C() { } }
56+
"""
57+
);
58+
javadoc("-d", base.resolve("api").toString(),
59+
src.resolve("C.java").toString()
60+
);
61+
checkExit(Exit.ERROR);
62+
checkOutput(Output.OUT, true, """
63+
C.java:2: error: no tag name after '@'
64+
* abc {@ } def
65+
^
66+
""");
67+
}
68+
69+
@Test
70+
public void test_inline_bad(Path base) throws Exception {
71+
Path src = base.resolve("src");
72+
tb.writeJavaFiles(src, """
73+
/**
74+
* abc {@/ } def
75+
*/
76+
public class C { private C() { } }
77+
"""
78+
);
79+
javadoc("-d", base.resolve("api").toString(),
80+
src.resolve("C.java").toString()
81+
);
82+
checkExit(Exit.ERROR);
83+
checkOutput(Output.OUT, true, """
84+
C.java:2: error: no tag name after '@'
85+
* abc {@/ } def
86+
^
87+
""");
88+
}
89+
90+
@Test
91+
public void test_block_missing(Path base) throws Exception {
92+
Path src = base.resolve("src");
93+
tb.writeJavaFiles(src, """
94+
/**
95+
* abc.
96+
* @ def
97+
*/
98+
public class C { private C() { } }
99+
"""
100+
);
101+
javadoc("-d", base.resolve("api").toString(),
102+
src.resolve("C.java").toString()
103+
);
104+
checkExit(Exit.ERROR);
105+
checkOutput(Output.OUT, true, """
106+
C.java:3: error: no tag name after '@'
107+
* @ def
108+
^
109+
""");
110+
}
111+
112+
@Test
113+
public void test_block_bad(Path base) throws Exception {
114+
Path src = base.resolve("src");
115+
tb.writeJavaFiles(src, """
116+
/**
117+
* abc.
118+
* @/ def
119+
*/
120+
public class C { private C() { } }
121+
"""
122+
);
123+
javadoc("-d", base.resolve("api").toString(),
124+
src.resolve("C.java").toString()
125+
);
126+
checkExit(Exit.ERROR);
127+
checkOutput(Output.OUT, true, """
128+
C.java:3: error: no tag name after '@'
129+
* @/ def
130+
^
131+
""");
132+
}
133+
}

test/langtools/tools/doclint/BadPackageCommentTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
/**
1111
* abc.
12-
* @@@
12+
* @!#
1313
*/
1414
package p;

test/langtools/tools/doclint/BadPackageCommentTest.out

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ BadPackageCommentTest.java:14: warning: documentation comment not expected here
22
package p;
33
^
44
BadPackageCommentTest.java:12: error: no tag name after '@'
5-
* @@@
6-
^
7-
BadPackageCommentTest.java:12: error: no tag name after '@'
8-
* @@@
5+
* @!#
96
^
10-
BadPackageCommentTest.java:12: error: no tag name after '@'
11-
* @@@
12-
^
13-
3 errors
7+
1 error
148
1 warning

test/langtools/tools/javac/doctree/TagTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 7021614 8078320 8273244 8284908 8301201
26+
* @bug 7021614 8078320 8273244 8284908 8301201 8301813
2727
* @summary extend com.sun.source API to support parsing javadoc comments
2828
* @modules jdk.compiler/com.sun.tools.javac.api
2929
* jdk.compiler/com.sun.tools.javac.file
@@ -93,7 +93,7 @@ void no_name_block() { }
9393
firstSentence: empty
9494
body: empty
9595
block tags: 1
96-
Erroneous[ERRONEOUS, pos:1, prefPos:5
96+
Erroneous[ERRONEOUS, pos:1, prefPos:2
9797
code: compiler.err.dc.no.tag.name
9898
body: @_abc
9999
]
@@ -141,7 +141,7 @@ void no_name_inline() { }
141141
/*
142142
DocComment[DOC_COMMENT, pos:1
143143
firstSentence: 2
144-
Erroneous[ERRONEOUS, pos:1, prefPos:2
144+
Erroneous[ERRONEOUS, pos:1, prefPos:3
145145
code: compiler.err.dc.no.tag.name
146146
body: {@
147147
]

0 commit comments

Comments
 (0)