From 374193b6d2465a356941f9588a0ccf6d97cb76f6 Mon Sep 17 00:00:00 2001 From: Pavel Rappo Date: Fri, 11 Mar 2022 22:41:47 +0000 Subject: [PATCH] 8283041: [javadoc] Crashes using {@return} with @param Reviewed-by: jjg --- .../jdk/javadoc/internal/doclint/Checker.java | 6 +++--- .../doclet/testReturnTag/TestReturnTag.java | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 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 446757513a1..6b167aa3933 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2022, 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 @@ -985,8 +985,8 @@ public class Checker extends DocTreePathScanner { } if (tree.isInline()) { DocCommentTree dct = getCurrentPath().getDocComment(); - if (tree != dct.getFirstSentence().get(0)) { - env.messages.warning(REFERENCE, tree, "dc.return.not.first"); + if (dct.getFirstSentence().isEmpty() || tree != dct.getFirstSentence().get(0)) { + env.messages.warning(SYNTAX, tree, "dc.return.not.first"); } } diff --git a/test/langtools/jdk/javadoc/doclet/testReturnTag/TestReturnTag.java b/test/langtools/jdk/javadoc/doclet/testReturnTag/TestReturnTag.java index 00d5c92c630..4974f4e586e 100644 --- a/test/langtools/jdk/javadoc/doclet/testReturnTag/TestReturnTag.java +++ b/test/langtools/jdk/javadoc/doclet/testReturnTag/TestReturnTag.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2022, 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 4490068 8075778 + * @bug 4490068 8075778 8283041 * @summary General tests for inline or block at-return tag * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool @@ -265,16 +265,30 @@ public class TestReturnTag extends JavadocTester { */ public int m() { return 0; } } + """, + """ + /** Comment. */ + public class X { + /** + * @author Jim + * {@return the result} + */ + public int m() { return 0; } + } """); javadoc("-d", base.resolve("out").toString(), "-sourcepath", src.toString(), - src.resolve("C.java").toString()); + src.resolve("C.java").toString(), + src.resolve("X.java").toString()); checkExit(Exit.OK); checkOutput(Output.OUT, true, "C.java:4: warning: {@return} not at beginning of description"); + checkOutput(Output.OUT, true, + "X.java:5: warning: {@return} not at beginning of description"); + checkOutput("C.html", true, """
Some text. Returns the result. More text.