8298525: javadoc crashes with "UnsupportedOperationException: Not yet implemented" in SeeTaglet.inherit

Reviewed-by: jjg
This commit is contained in:
Pavel Rappo 2023-01-05 22:43:20 +00:00
parent 9c4ed16be2
commit 284c94e20d
3 changed files with 27 additions and 6 deletions
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets
test/langtools/jdk/javadoc/doclet/testInheritDocWithinInappropriateTag

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
@ -37,6 +37,7 @@ import com.sun.source.doctree.SeeTree;
import jdk.javadoc.doclet.Taglet.Location;
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Result;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
@ -51,7 +52,10 @@ public class SeeTaglet extends BaseTaglet implements InheritableTaglet {
@Override
public Output inherit(Element owner, DocTree tag, boolean isFirstSentence, BaseConfiguration configuration) {
throw new UnsupportedOperationException("Not yet implemented");
CommentHelper ch = configuration.utils.getCommentHelper(owner);
var path = ch.getDocTreePath(tag);
configuration.getMessages().warning(path, "doclet.inheritDocWithinInappropriateTag");
return new Output(null, null, List.of(), true /* true, otherwise there will be an exception up the stack */);
}
@Override

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@ -36,6 +36,7 @@ import com.sun.source.doctree.SpecTree;
import jdk.javadoc.doclet.Taglet.Location;
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Result;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
@ -50,7 +51,10 @@ public class SpecTaglet extends BaseTaglet implements InheritableTaglet {
@Override
public Output inherit(Element owner, DocTree tag, boolean isFirstSentence, BaseConfiguration configuration) {
throw new UnsupportedOperationException("Not yet implemented");
CommentHelper ch = configuration.utils.getCommentHelper(owner);
var path = ch.getDocTreePath(tag);
configuration.getMessages().warning(path, "doclet.inheritDocWithinInappropriateTag");
return new Output(null, null, List.of(), true /* true, otherwise there will be an exception up the stack */);
}
@Override

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 8284299 8287379
* @bug 8284299 8287379 8298525
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
@ -65,6 +65,9 @@ public class TestInheritDocWithinInappropriateTag extends JavadocTester {
* {@linkplain Object#hashCode() {@inheritDoc}}
*
* {@index term {@inheritDoc}}
*
* @see A {@inheritDoc}
* @spec http://example.com {@inheritDoc}
*/
@Override
public void x() { }
@ -95,6 +98,16 @@ public class TestInheritDocWithinInappropriateTag extends JavadocTester {
warning: @inheritDoc cannot be used within this tag
* {@index term {@inheritDoc}}
^
""",
"""
warning: @inheritDoc cannot be used within this tag
* @see A {@inheritDoc}
^
""",
"""
warning: @inheritDoc cannot be used within this tag
* @spec http://example.com {@inheritDoc}
^
""");
}