Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8272374: doclint should report missing "body" comments #5106

Closed

Conversation

jonathan-gibbons
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons commented Aug 13, 2021

Please review a relatively simple update to have doclnt check for empty "descriptions" -- the body of a doc comment, before the block tags.

It is already the case that doclint checks for missing/empty descriptions in block tags, like @param, @return, etc.

There are three cases to consider:

  • The comment itself is missing: this was already checked and reported as "missing comment".
  • The comment is present, but is empty ... this seems relatively unlikely, but is nevertheless checked and reported as "empty comment".
  • The comment is present but only has block tags. This is not always a problem, since the description may be inherited, for example, in an overriding method, but when it is an issue, it is reported as "no initial description".

No diagnostic is reported if the description is missing but the first tag is @deprecated, because in this case, javadoc will use the body of the @deprecated tag for the summary. See Character.UnicodeBlock#SURROGATES_AREA and the corresponding entry in the summary table to see an example of this situation.

Diagnostics are reported if the declaration is not an overriding method and does not begin with @deprecated. This occurs in a number of places in the java.desktop module, often where the doc comment is of the form /** @return _description_ */. To suppress those warnings for now, the -missing option is added to DOCLINT_OPTIONS for the java.desktop module. To see the effects of this anti-pattern, look at the empty descriptions for javax.swing.text.html.parser.AttributeList

Many of the doclint tests needed to be updated, because of their over-simplistic minimal comments. It was not possible, in general, to avoid updating the source code while preserving line numbers, so in many cases, the golden *.out files had to be updated as well.

A new test is added, focussing on the different forms of empty/missing descriptions, as described above.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8272374: doclint should report missing "body" comments

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5106/head:pull/5106
$ git checkout pull/5106

Update a local copy of the PR:
$ git checkout pull/5106
$ git pull https://git.openjdk.java.net/jdk pull/5106/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5106

View PR using the GUI difftool:
$ git pr show -t 5106

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5106.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 13, 2021

👋 Welcome back jjg! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 13, 2021
@openjdk
Copy link

openjdk bot commented Aug 13, 2021

@jonathan-gibbons The following labels will be automatically applied to this pull request:

  • 2d
  • build
  • compiler
  • javadoc

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added javadoc javadoc-dev@openjdk.org 2d client-libs-dev@openjdk.org build build-dev@openjdk.org compiler compiler-dev@openjdk.org labels Aug 13, 2021
@mlbridge
Copy link

mlbridge bot commented Aug 13, 2021

Webrevs

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this by using it to generate the JavaFX docs. We have 62 new warnings for methods with empty descriptions that we otherwise would not have easily found.

Copy link
Member

@hns hns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One thing I wonder about is why you only look for @deprecated in the first block tag. I guess it is just a convention to add this tag at the first position?

DocTree firstTag = tree.getBlockTags().get(0);
// Don't report an empty description if the comment begins with @deprecated,
// because javadoc will use the content of that tag in summary tables.
if (firstTag.getKind() != DocTree.Kind.DEPRECATED) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only check the first block tag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various reasons,

  1. It seems the convention is to simply prefix an existing comment with @deprecated or to replace the existing body description with @deprecated reason-why-deprecated
  2. This is only for the case when there is no body description; it seems hard to imagine that someone would start a comment with @see @param @return etc and then have the @deprecated tag.

That being said, it would be easy enough to change the code to check for any instance of @deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the downstream code does not impose any ordering restrictions on the tags, it is probably with doing the same here.

// Don't report an empty description if the comment begins with @deprecated,
// because javadoc will use the content of that tag in summary tables.
if (firstTag.getKind() != DocTree.Kind.DEPRECATED) {
env.messages.report(MISSING, Kind.WARNING, tree, "dc.empty.description");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not use reportMissing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have the right signature. reportMissing reports a missing comment on an element; here, we're reporting a missing description within a DocTree. There's a similar occurrence at line 1214.

@openjdk
Copy link

openjdk bot commented Aug 16, 2021

@jonathan-gibbons This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8272374: doclint should report missing "body" comments

Reviewed-by: kcr, hannesw

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 24 new commits pushed to the master branch:

  • b2c272d: 8272305: several hotspot runtime/modules don't check exit codes
  • 8268825: 8272297: FileInputStream should override transferTo() for better performance
  • 3677734: 8271471: [IR Framework] Rare occurrence of "" in PrintIdeal/PrintOptoAssembly can let tests fail
  • 0a03481: 8272231: G1: Refactor G1CardSet::get_card_set to return G1CardSetHashTableValue*
  • 83d0e12: 8267833: Improve G1CardSetInlinePtr::add()
  • 69cc588: 8272235: G1: update outdated code root fixup
  • 5db36ce: 8272158: SoftReference related bugs under memory pressure
  • 7a5b37b: 8272439: G1: add documentation to G1CardSetInlinePtr
  • 0209d9f: 8272461: G1: remove empty declaration of cleanup_after_scan_heap_roots
  • 36e2dda: 8272348: Update CDS tests in anticipation of JDK-8270489
  • ... and 14 more: https://git.openjdk.java.net/jdk/compare/428d51694f56788f89e8df100a74cbadd369ffa6...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 16, 2021
@jonathan-gibbons
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Aug 16, 2021

Going to push as commit ae45592.
Since your change was applied there have been 24 commits pushed to the master branch:

  • b2c272d: 8272305: several hotspot runtime/modules don't check exit codes
  • 8268825: 8272297: FileInputStream should override transferTo() for better performance
  • 3677734: 8271471: [IR Framework] Rare occurrence of "" in PrintIdeal/PrintOptoAssembly can let tests fail
  • 0a03481: 8272231: G1: Refactor G1CardSet::get_card_set to return G1CardSetHashTableValue*
  • 83d0e12: 8267833: Improve G1CardSetInlinePtr::add()
  • 69cc588: 8272235: G1: update outdated code root fixup
  • 5db36ce: 8272158: SoftReference related bugs under memory pressure
  • 7a5b37b: 8272439: G1: add documentation to G1CardSetInlinePtr
  • 0209d9f: 8272461: G1: remove empty declaration of cleanup_after_scan_heap_roots
  • 36e2dda: 8272348: Update CDS tests in anticipation of JDK-8270489
  • ... and 14 more: https://git.openjdk.java.net/jdk/compare/428d51694f56788f89e8df100a74cbadd369ffa6...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Aug 16, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 16, 2021
@openjdk
Copy link

openjdk bot commented Aug 16, 2021

@jonathan-gibbons Pushed as commit ae45592.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jonathan-gibbons jonathan-gibbons deleted the 8272374.doclint.empty branch August 16, 2021 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d client-libs-dev@openjdk.org build build-dev@openjdk.org compiler compiler-dev@openjdk.org integrated Pull request has been integrated javadoc javadoc-dev@openjdk.org
3 participants