Skip to content

8177100: APIs duplicated in JavaDoc #25123

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

nizarbenalla
Copy link
Member

@nizarbenalla nizarbenalla commented May 8, 2025

Please review this patch to fix a bug where a method can be documented multiple times
Consider these 4 classes

                    A       (interface)
                   / \
                  /   \
(abstract class)  C     B   ( interface)
                  \   /
                   \ /
                    D       (class)

Where A declares testA(), C implements it public final void testA(), B extends A but does not override it, D extends C and implements B

In the generated javadoc, testA() is documented twice.

Screenshot 2025-05-08 at 15 51 19

After the patch, testA() is only documented once:

Screenshot 2025-05-08 at 15 52 16


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Committer)

Issue

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25123

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 8, 2025

👋 Welcome back nbenalla! 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
Copy link

openjdk bot commented May 8, 2025

@nizarbenalla This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 8, 2025
@openjdk
Copy link

openjdk bot commented May 8, 2025

@nizarbenalla The following label will be automatically applied to this pull request:

  • javadoc

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

@mlbridge
Copy link

mlbridge bot commented May 8, 2025

@@ -689,10 +689,15 @@ private boolean allowInheritedMethod(ExecutableElement inheritedMethod,
if (inInterface) {
List<ExecutableElement> list = overriddenByTable.get(inheritedMethod);
if (list != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we change this to if (list != null && !list.isEmpty) return false;?

Comments can be to update the overall block comment to indicate that there is no contention - when a method overrides multiple superinterfaces' methods, including when it is final from superclasses, the superclass method always prevails due to method resolution rules in Java. All interface methods have low resolution priority.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this simplification works just fine.

Copy link
Member

@liach liach 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, thanks!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 9, 2025
@hns
Copy link
Member

hns commented May 9, 2025

I'm not sure about this. @nizarbenalla have you tested whether this changes the output for JDK docs?

@hns
Copy link
Member

hns commented May 9, 2025

There's a problem with character encoding in this patch, please do not integrate:

 /Users/runner/work/jdk/jdk/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/VisibleMemberTable.java:681: error: unmappable character (0x80) for encoding ascii
        // Multiple-Inheritance: No Contention. In Java???s method resolution,

@liach
Copy link
Member

liach commented May 9, 2025

/reviewers 2 committer

@openjdk
Copy link

openjdk bot commented May 9, 2025

@liach
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Committer).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 9, 2025
@hns
Copy link
Member

hns commented May 9, 2025

As I suspected, this removes methods from the "Methods declared in interface XY" sections. For example, in the java.lang.StringBuilder doc page section for methods declared in java.lang.CharSequence it removes all methods except isEmpty(). So this is not the right place to fix this. I think we should only eliminate these overridden methods when they are to be documented in the subclass (when the declaring class is undocumented).

@nizarbenalla
Copy link
Member Author

Hannes suggested in offline discussion where the check can be instead of the old approach.
I have checked that there is no change in the current JDK doc build after applying this patch.

Thanks for catching this oversight during the review.

@nizarbenalla
Copy link
Member Author

nizarbenalla commented May 12, 2025

Please don't review this yet, I plan on pushing an other update.

@nizarbenalla
Copy link
Member Author

I've updated the test as the name was not accurate, and simplified the code in VisibleMemberTable

@nizarbenalla nizarbenalla requested a review from liach May 15, 2025 13:00
@hns
Copy link
Member

hns commented May 28, 2025

I have to apologize for my previous review. When I noticed that JDK documentation had changed, my knee-jerk reaction was to assume that the change was wrong. But it is indeed the current documentation that is wrong.

For example in StringBuilder, the methods overridden in the hidden AbstractStringBuilder class should not be shown as declared in CharSequence as they are documented as local methods in StringBuilder (even though they are implemented in a hidden superclass).

Similarly (but without the hidden superclass), the equals and hashCode methods in HashMap should not be documented as declared in interface Map, but only in AbstractMap where they override the default implementation.

So your first solution (in the simplified form) was actually correct after all.

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

Looks identical to the initial version.

@hns
Copy link
Member

hns commented Jun 10, 2025

Looks identical to the initial version.

@liach I realized the first version was right after all (see my comment above). We should not document a method as inherited from some interface when it is implemented in the local class or some superclass. So this gets rid of duplicate inherited methods, such as equals(Object) in HashMap appearing as inherited both from class AbstractMap and interface Map.

"sb");
checkExit(Exit.OK);

checkOutput("sb/U.html", false,
Copy link
Member

@hns hns Jun 10, 2025

Choose a reason for hiding this comment

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

Could you add a positive check to this test and testHashMapInheritance that the method is documented as expected (as local method in this test, and as inherited from the public abstract class in testHashMapInheritance), and that the method details has a "Specified by: ..." entry pointing to the interface method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javadoc [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants