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

8285368: Overhaul doc-comment inheritance #14357

Closed
wants to merge 17 commits into from

Conversation

pavelrappo
Copy link
Member

@pavelrappo pavelrappo commented Jun 7, 2023

Please review this long-awaited change to documentation inheritance.

This change improves "methods comment algorithm" and introduces directed documentation inheritance. While "methods comment algorithm" -- automatic search for inheritable documentation -- has been improved, it still cannot read an author's mind so as to always find the documentation they intended. From now on, an author can state their intention, by providing an FQN of the superclass or superinterface from which to inherit documentation:

​{@inheritDoc S}

Which is exactly what I did to counterbalance some of the JDK API Documentation changes caused by the change to "methods comment algorithm".


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8287152 to be approved

Issues

  • JDK-8285368: Overhaul doc-comment inheritance (Bug - P3)
  • JDK-6376959: Algorithm for Inheriting Method Comments seems to go not as documented (Bug - P3)
  • JDK-6934301: Support directed inheriting of class comments with @inheritdoc (Enhancement - P3)
  • JDK-8287152: Overhaul doc-comment inheritance (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14357/head:pull/14357
$ git checkout pull/14357

Update a local copy of the PR:
$ git checkout pull/14357
$ git pull https://git.openjdk.org/jdk.git pull/14357/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14357

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14357.diff

Webrev

Link to Webrev Comment

The changes are in the JDK API Documentation.
This check is well-intended but problematic for JDK API Documentation
build, which errors on warnings.
@bridgekeeper
Copy link

bridgekeeper bot commented Jun 7, 2023

👋 Welcome back prappo! 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 Jun 7, 2023
@openjdk
Copy link

openjdk bot commented Jun 7, 2023

@pavelrappo The following labels will be automatically applied to this pull request:

  • client
  • compiler
  • core-libs
  • 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 client client-libs-dev@openjdk.org core-libs core-libs-dev@openjdk.org compiler compiler-dev@openjdk.org labels Jun 7, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 7, 2023

@pavelrappo
Copy link
Member Author

/csr

@openjdk
Copy link

openjdk bot commented Jun 7, 2023

@pavelrappo This pull request already associated with these approved CSRs: JDK-8287152

@pavelrappo
Copy link
Member Author

For details on changes to "methods comment algorithm", see the associated CSR: https://bugs.openjdk.org/browse/JDK-8287152

@pavelrappo
Copy link
Member Author

Full disclosure. Here are all the files that are different before (1) and after (2) the change:

As you can see, the vast majority of differences are in "See Also" sections, which come from @see tags. Sadly, @see tags are inheritable "by omission". That said, @see is also underspecified, somewhat broken, and I believe is not as important as those parts of a doc comment that allow {@inheritDoc}.

I suggest that we integrate this PR and take care of @see in 22. But if the corrections are really required, I can try to introduce explicit @see tags, so there are no changes whatsoever.

var supertype = (TypeElement) ch.getReferencedElement(inheritDoc.getSupertype());
if (supertype == null) {
messages.error(inheritDocPath, "doclet.inheritDocBadSupertype");
return replacement;
Copy link
Contributor

Choose a reason for hiding this comment

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

replacement may be empty.
Consider using HtmlDocletWriter.invalidTagOutput.

(Later, we might want to provide a utility message to wrap messages.error and invalidTagOutput

// "self-inheritors" and supertypes that do not contain a method
// that this method overrides
messages.error(inheritDocPath, "doclet.inheritDocBadSupertype");
return replacement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Another case for invalidTagOutput ?

@@ -52,7 +52,7 @@ public interface InheritableTaglet extends Taglet {
* In the future, this could be reworked using some other mechanism,
* such as throwing an exception.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should ThrowsTaglet.Failure (eventually?) be declared here in InheritableTaglet

}

@SuppressWarnings("serial")
public static final class NoOverriddenMethodsFound extends Exception {
public static final class NoOverriddenMethodFound extends Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

General comment, for future work:
Maybe we can combine/merge/unify this exception with ThrowsTaglet.Failure

@pavelrappo
Copy link
Member Author

/issue add 6376959, 6934301

@openjdk
Copy link

openjdk bot commented Jun 7, 2023

@pavelrappo
Adding additional issue to issue list: 6376959: Algorithm for Inheriting Method Comments seems to go not as documented.

Adding additional issue to issue list: 6934301: Support directed inheriting of class comments with @inheritDoc.

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

I will only comment on the changes to the java.base classes.

I had a look at the changes to these and they looked right to me. Though I’m not an expert on collections it seemed that you picked the right ‘semantically closer parent’ to inherit from.
Probably @stuart-marks could give a more authoritative opinion.

@pavelrappo
Copy link
Member Author

@Martin-Buchholz, could you please have a look at changes to collections and, in particular, those in java.util.concurrent.*?

@pavelrappo
Copy link
Member Author

Note that the change to "method comments algorithm" uncovers and fixes some bugs to Object- or Object-like- methods.

Using the provided before and after outputs, compare documentation for:

  • toString() in java.time.chrono.{Hijrah,Japanese,Minguo,ThaiBuddhist}Date
  • hashCode() in Hashtable, ConcurrentHashMap.KeySetView, java.util.jar.Attributes, com.sun.net.httpserver.Headers, com.sun.management.GcInfo
  • equals() in ConcurrentHashMap.KeySetView, com.sun.net.httpserver.Headers, com.sun.management.GcInfo
  • clone() in javax.management.ImmutableDescriptor, javax.management.modelmbean.DescriptorSupport, javax.naming.directory.BasicAttribute, javax.naming.directory.BasicAttributes

Perhaps some of those could be further refined using directed documentation inheritance. For example, ConcurrentHashMap.KeySetView is first and foremost a set and only then a collection. That suggests that the documentation for Object-like methods could be inherited from (some) set rather than a "generic" collection.

Also, the javax.management.ImmutableDescriptor and javax.management.modelmbean.DescriptorSupport clone methods require some attention from area experts. It's likely that those methods' doc comments need to fully inherit documentation from Descriptor.clone(), not just its @return tag.

@pavelrappo
Copy link
Member Author

core-libs, client: any reviewers?

Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Look ok for core-libs classes

Copy link
Member

@aivanov-jdk aivanov-jdk 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 to me for client changes.

Copy link
Member

@stuart-marks stuart-marks left a comment

Choose a reason for hiding this comment

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

I reviewed the changes in java.base. They look fine. I support the notion of keeping these changes minimal, with the narrow goal of keeping the resulting javadoc output the same. There are many opportunities for improving the actual docs, but those should be handled separately.

@Martin-Buchholz
Copy link
Member

I reviewed the changes in java.base. They look fine. I support the notion of keeping these changes minimal, with the narrow goal of keeping the resulting javadoc output the same. There are many opportunities for improving the actual docs, but those should be handled separately.

I agree with stuart-marks@

Copy link
Member

@Martin-Buchholz Martin-Buchholz left a comment

Choose a reason for hiding this comment

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

We don't currently have a way to diff rendered javadoc, like my ancient BlenderRev hack?

@@ -1531,7 +1531,7 @@ private void readObject(java.io.ObjectInputStream s)
// ConcurrentMap methods

/**
* {@inheritDoc}
* {@inheritDoc ConcurrentMap}
Copy link
Member

Choose a reason for hiding this comment

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

This clarifies the authors' intent, so is clear progress.

Semantic difficulties remain:

  • it would be nice to somehow declare that we never ever want to inherit doc from AbstractMap (or even at the module level, declare that AbstractFoo classes are specified only for subclass writers, not users). Private inheritance?
  • we never want to inherit AbstractFoo @implNotes
  • ConcurrentMap does not have the same spec as ConcurrentHashMap, e.g. the latter does not permit null values. Therefore one can argue that javadoc should not be inherited here. Right now the main method spec from ConcurrentMap is perfectly suitable for ConcurrentHashMap, but one can imagine a future change to ConcurrentMap::putIfAbsent's spec that changes that, perhaps due to the null value handling difference. We have a distasteful choice - brittle inheritance or copy-pasta. In practice not so bad here, since these classes are maintained together.

Copy link
Member Author

Choose a reason for hiding this comment

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

  • we never want to inherit AbstractFoo @implNotes

@implNote, @apiNote and @implSpec can only be inherited via explicit {@inheritDoc}:

@implSpec {@inheritDoc}
  • ConcurrentMap does not have the same spec as ConcurrentHashMap, e.g. the latter does not permit null values. Therefore one can argue that javadoc should not be inherited here. Right now the main method spec from ConcurrentMap is perfectly suitable for ConcurrentHashMap, but one can imagine a future change to ConcurrentMap::putIfAbsent's spec that changes that, perhaps due to the null value handling difference. We have a distasteful choice - brittle inheritance or copy-pasta. In practice not so bad here, since these classes are maintained together.

That state of affairs predates this PR and is merely highlighted by it. Sadly, I'm not sure how JavaDoc can help here. Annotations, contracts, inspections, and doc tests come to mind; but none of these are supported by JavaDoc at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

(There's nothing wrong with this PR)

Back in the 1980s there was a lot of optimism that OOP would be a big leap forward in software engineering.
But especially the "inheritance" part of OOP has been disappointing - unexpectedly brittle!
javadoc inheritance in collection classes was particularly interesting to me from this perspective.
Especially with the multiple inheritance that java was mostly reluctant to adopt.

@pavelrappo
Copy link
Member Author

We don't currently have a way to diff rendered javadoc, like my ancient BlenderRev hack?

I've generated something you might find helpful: https://cr.openjdk.org/~prappo/8285368/specdiff/overview-summary.html

@pavelrappo
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 15, 2023

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

  • 3eeb681: 8167252: Some of Charset.availableCharsets() does not contain itself
  • 653a8d0: 8310129: SetupNativeCompilation LIBS should match the order of the other parameters
  • 947f149: 8308444: LoadStoreNode::result_not_used() is too conservative
  • 8b4af46: 8309974: some JVMCI tests fail when VM options include -XX:+EnableJVMCI
  • 0038491: 8309978: [x64] Fix useless padding
  • 5f3613e: 8309960: ParallelGC young collections very slow in DelayInducer
  • 83d9267: 8303513: C2: LoadKlassNode::make fails with 'expecting TypeKlassPtr'
  • de8aca2: 8307907: [ppc] Remove RTM locking implementation

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 15, 2023
@openjdk openjdk bot closed this Jun 15, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 15, 2023
@openjdk
Copy link

openjdk bot commented Jun 15, 2023

@pavelrappo Pushed as commit 3e0bbd2.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org compiler compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated javadoc javadoc-dev@openjdk.org
8 participants