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

8313239: InetAddress.getCanonicalHostName may return ip address if reverse lookup fails #15134

Closed
wants to merge 10 commits into from

Conversation

jaikiran
Copy link
Member

@jaikiran jaikiran commented Aug 3, 2023

Can I please get a review of this change which updates the javadoc of java.net.InetAddress.getCanonicalHostName() method to clarify its semantics? This addresses https://bugs.openjdk.org/browse/JDK-8313239.

This a javadoc only change and the documentation is updated to match the current implementation. A CSR will be drafted for this change.


Progress

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

Issues

  • JDK-8313239: InetAddress.getCanonicalHostName may return ip address if reverse lookup fails (Bug - P3)
  • JDK-8313677: InetAddress.getCanonicalHostName may return ip address if reverse lookup fails (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15134

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 3, 2023

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

openjdk bot commented Aug 3, 2023

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

  • net

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.

@openjdk openjdk bot added the net net-dev@openjdk.org label Aug 3, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 3, 2023

@jaikiran
Copy link
Member Author

jaikiran commented Aug 3, 2023

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Aug 3, 2023
@openjdk
Copy link

openjdk bot commented Aug 3, 2023

@jaikiran has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@jaikiran please create a CSR request for issue JDK-8313239 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 3, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 3, 2023
* Gets the fully qualified domain name for this
* {@linkplain InetAddress#getAddress() IP address} using the system-wide
* {@linkplain InetAddressResolver resolver}. This is a best effort method,
* meaning we may not be able to return the fully qualified domain name; in
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'll need to replace "we" with "it" here. It may also be useful to expand this sentence a bit, maybe with an example of why it may fail.

I also wonder (and I'm in two minds on this) is if this method should include an impNote to say what it actually does.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello Alan,

I also wonder (and I'm in two minds on this) is if this method should include an impNote to say what it actually does.

I'm guessing that you are thinking of having the implNote state that a reverse name lookup will be performed by this method using the system-wide resolver. Right now, the getHostName() says this:

* <p>If this InetAddress was created with a host name,
     * this host name will be remembered and returned;
     * otherwise, a reverse name lookup will be performed
     * and the result will be returned based on the system
     * configured resolver. If a lookup of the name service
     * is required, call
     * {@link #getCanonicalHostName() getCanonicalHostName}.

I think we could update the getCanonicalName() to mention the reverse name lookup. However, I'm unsure if it should be an implNote or just formal API javadoc.

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 have now updated the PR to add a few more details on what this method does and why it might fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing that you are thinking of having the implNote state that a reverse name lookup will be performed by this method using the system-wide resolver.

I was thinking more about the caching and attempting the lookup only on first usage. So my comment was wondering out loud if we should note this behavior in an implNote.

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 was thinking more about the caching and attempting the lookup only on first usage.

If we do have to make a mention of that, then I think we would have to probably change the implementation to actually do the lookup only on first usage. Right now, the canonicalHostName field isn't volatile and there isn't any construct in place which will ensure that multiple concurrent calls to this method will ensure only one lookup happens. It's harmless in the current form, but if we add an implNote about this, then I think we would have to make it actually behave that way.

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.

The updated verbiage looks much better to me.

@@ -814,7 +822,7 @@ public String getCanonicalHostName() {
}

/**
* Returns the hostname for this address.
* Returns the fully qualified domain for this address.
Copy link
Member

Choose a reason for hiding this comment

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

Both getHostName and getCanonicalHostName talk about fully qualified domain name, and how the system-wide resolver is used to determine it. But InetAddressResolver.lookupByAddress talks about host name, maybe it should be updated to use FQDN term?

name is missing here: fully qualified domain -> fully qualified domain name

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello Aleksei,

But InetAddressResolver.lookupByAddress talks about host name, maybe it should be updated to use FQDN term?

Should we address that in this PR or a separate one?

name is missing here: fully qualified domain -> fully qualified domain name

Good catch. Fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Should we address that in this PR or a separate one?

I'm good with both, but having it as a separate PR might require an additional CSR if docs modifications alter the semantics:

Q: If the text of the javadoc of a public exported API is changing, is a CSR request needed?
A: A CSR request is required if the specification of a public exported API. Not all javadoc updates are specification changes. For example, typo fixes and rephrasings that do not alter the semantics of the API in question do not require CSR review.

[CSR FAQ]

Good catch. Fixed.

Thank you

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 spoke to Aleksei about the InetAddressResolver javadoc and whether it should be updated in this PR. We agreed that we will take it up separately. I've created https://bugs.openjdk.org/browse/JDK-8313947 to track that discussion.

The PR in the current state has all other reviews implemented and I've updated and finalized the CSR with the text that's in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for creating a separate bug to track terms used in the InetAddressResolver and InetAddress classes. This PR looks good to me.

* {@linkplain InetAddress#getAddress() IP address} using the system-wide
* {@linkplain InetAddressResolver resolver}.
*
* <p>The system-wide resolver will be used to do a reverse name lookup of the IP address.
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording in this paragraph seems a bit different to getHostName and I think we should try to use the same terms in both methods if possible, e.g. getHostName talks about the "system configured resolver" where here it uses "system-wide resolve". We have have "used" vs. "performed". So maybe look at the methods again as I think we should be a bit more consistent with the wording if we can.

Copy link
Member Author

@jaikiran jaikiran Aug 8, 2023

Choose a reason for hiding this comment

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

Hello Alan, except for a couple of places in InetAddress javadoc, the rest of the javadoc (and code comments) in InetAddress use the term system-wide resolver instead of system configured resolver. Furthermore, the java.net.spi.InetAddressResolver itself uses the system-wide resolver term. So I've now updated these two places in InetAddress to replace the use of "system configured resolver" to "system-wide resolver".

* The lookup may fail for reasons such as the host not being registered with the name
* service. In such cases, where the resolver isn't able to determine the fully qualified
* domain name, this method returns the {@linkplain #getHostAddress() textual representation}
* of the IP address.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to say that the lookup can fail for many reasons that include the host not being registered with the name service.

A suggestion for "In such cases .." is to say "If the resolver is unable to determine ...". I think that would be a bit easer to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds good. I've updated the PR to use this suggestion.

@openjdk
Copy link

openjdk bot commented Aug 9, 2023

@jaikiran 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:

8313239: InetAddress.getCanonicalHostName may return ip address if reverse lookup fails

Reviewed-by: dfuchs, aefimov, alanb

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 70 new commits pushed to the master branch:

  • c822183: 8313768: Reduce interaction with volatile field in j.u.l.StreamHandler
  • cd16158: 8314075: Update JCov version for JDK 22
  • c307391: 8307184: Incorrect/inconsistent specification and implementation for Elements.getDocComment
  • 593ba2f: 8313693: Introduce an internal utility for the Damerau–Levenshtein distance calculation
  • 360f65d: 8314022: Problem-list tests failing with jtreg 7.3
  • 0eb0997: 8288936: Wrong lock ordering writing G1HeapRegionTypeChange JFR event
  • 19ae62a: 8311170: Simplify and modernize equals and hashCode in security area
  • e9f751a: 8311247: Some cpp files are compiled with -std:c11 flag
  • 213d3c4: 8313891: JFR: Incorrect exception message for RecordedObject::getInt
  • 0e2c72d: 8313796: AsyncGetCallTrace crash on unreadable interpreter method pointer
  • ... and 60 more: https://git.openjdk.org/jdk/compare/3c920f9cc61566b7bd08d2bf8773d39a616082d3...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 ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Aug 9, 2023
@@ -814,7 +822,7 @@ public String getCanonicalHostName() {
}

/**
* Returns the hostname for this address.
* Returns the fully qualified domain name for this address.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe in the followup issue we could change "this address" to "the given address" considering it's a static method. It's not part of the spec regardless, so only a minor nit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello Michael, that's a good catch. I've now pushed an update in this PR which fixes that.

@jaikiran
Copy link
Member Author

jaikiran commented Aug 10, 2023

Thank you everyone for the reviews. The CSR for this change has been approved and all review comments have been implemented. I'll go ahead and integrate this later today.

@jaikiran
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Aug 10, 2023

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

  • 028b3ae: 8313874: JNI NewWeakGlobalRef throws exception for null arg
  • 83adaf5: 8313421: [JVMCI] avoid locking class loader in CompilerToVM.lookupType
  • 35b60f9: 8298095: Refine implSpec for SegmentAllocator
  • 6dba202: 8313670: Simplify shared lib name handling code in some tests
  • 8f28809: 8299790: os::print_hex_dump is racy
  • e080a0b: 8311508: ZGC: RAII use of IntelJccErratumAlignment
  • 242a2e6: 8308843: Generational ZGC: Remove gc/z/TestHighUsage.java
  • c822183: 8313768: Reduce interaction with volatile field in j.u.l.StreamHandler
  • cd16158: 8314075: Update JCov version for JDK 22
  • c307391: 8307184: Incorrect/inconsistent specification and implementation for Elements.getDocComment
  • ... and 67 more: https://git.openjdk.org/jdk/compare/3c920f9cc61566b7bd08d2bf8773d39a616082d3...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 10, 2023

@jaikiran Pushed as commit 0cb9ab0.

💡 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
integrated Pull request has been integrated net net-dev@openjdk.org
5 participants