Skip to content

Conversation

@stsypanov
Copy link
Contributor

@stsypanov stsypanov commented Apr 19, 2021

As discussed in #3464 we can clean-up null-checks remaining after 8142968 as Class.getPackageName() never returns null.


Progress

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

Issue

  • JDK-8265418: Clean-up redundant null-checks of Class.getPackageName()

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3571

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 19, 2021

👋 Welcome back stsypanov! 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.

@stsypanov stsypanov changed the title 8265418 Clean-up redundant null-checks of Class.getPackageName() 8265418: Clean-up redundant null-checks of Class.getPackageName() Apr 19, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 19, 2021
@openjdk
Copy link

openjdk bot commented Apr 19, 2021

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

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Apr 19, 2021
@mlbridge
Copy link

mlbridge bot commented Apr 19, 2021

Webrevs

Copy link
Member

@cl4es cl4es 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!

@openjdk
Copy link

openjdk bot commented Apr 19, 2021

⚠️ @stsypanov the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout 8265418
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Apr 19, 2021

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

8265418: Clean-up redundant null-checks of Class.getPackageName()

Reviewed-by: redestad

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

  • 41185d3: 8229517: Support for optional asynchronous/buffered logging
  • 7c85f35: 8267123: Remove RMI Activation
  • 0754266: 8267709: Investigate differences between HtmlStyle and stylesheet.css
  • 23189a1: 8191786: Thread-SMR hash table size should be dynamic
  • ef368b3: 8265836: OperatingSystemImpl.getCpuLoad() returns incorrect CPU load inside a container
  • 10a6f5d: 8230623: Extract command-line help for -Xlint sub-options to new --help-lint
  • bea4109: 8187649: ArrayIndexOutOfBoundsException in java.util.JapaneseImperialCalendar
  • ec65cf8: 8240347: remove undocumented options from jlink --help message
  • 3623abb: 8263087: Add a MethodHandle combinator that switches over a set of MethodHandles
  • 85f6165: 8267817: [TEST] Remove unnecessary init in test/micro/org/openjdk/bench/javax/crypto/full/AESGCMBench:setup
  • ... and 2 more: https://git.openjdk.java.net/jdk/compare/37bc4e2e3c2968d7419dae4f421755b6f7d06090...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@cl4es) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 19, 2021
@openjdk
Copy link

openjdk bot commented Apr 19, 2021

⚠️ @stsypanov the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout 8265418
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Apr 19, 2021

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

8265418: Clean-up redundant null-checks of Class.getPackageName()

Reviewed-by: redestad

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

  • d9e40dd: 8199407: Skip Rebuild Remset Phase if there are no rebuild candidates
  • 8dbf7aa: 8241306: Add SignatureMethodParameterSpec subclass for RSASSA-PSS params
  • b14e0ee: 8265371: Change to Visual Studio 2019 16.9.3 for building on Windows at Oracle
  • c887148: 8265079: Implement VarHandle invoker caching
  • b64a3fb: 8265325: Optimize StubRoutines::dpow() for Math.pow(x, 0.5)
  • d1c8c9e: 8197811: Test java/awt/Choice/PopupPosTest/PopupPosTest.java fails on Windows
  • 7d01c98: 8265414: Variable assigned but not used in G1FreeHumongousRegionClosure
  • d9e19f1: 8265226: (dc) API note in DatagramChannel.open should link to StandardProtocolFamily.UNIX
  • 49b9e68: 8262165: NMT report should state how many callsites had been skipped

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@cl4es) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@mlbridge
Copy link

mlbridge bot commented Apr 26, 2021

Mailing list message from Peter Levart on core-libs-dev:

On 4/26/21 1:27 PM, ?????? ??????? wrote:

On Mon, 26 Apr 2021 08:45:52 GMT, Alan Bateman <alanb at openjdk.org> wrote:

@AlanBateman if DL is not responding, will it be ok to just revert the changes related to `java.util.concurrent`?
That should be fine, the null check in Objects.equals is benign with these usages.
One more thing I'm thinking about (not to be done in this PR of course) is to move call to `String.intern()` from where it is now in `Class.getPackageName()`

public String getPackageName() {
String pn = this.packageName;
if (pn == null) {
Class<?> c = this;
while (c.isArray()) {
c = c.getComponentType();
}
if (c.isPrimitive()) {
pn = "java.lang";
} else {
String cn = c.getName();
int dot = cn.lastIndexOf('.');
pn = (dot != -1) ? cn.substring(0, dot).intern() : ""; // <---
}
this.packageName = pn;
}
return pn;
}

to `packageName` field assignement like

this.packageName = pn.intern();

this would add two more Strings (`""` and `"java.lang"`) into string table and allow to avoid `String.equals()` in favour of `==` call when comparing package names. What do you think?

I think this is not needed as string constants are all already interned
strings (guaranteed by VM). Also be careful not to return a string which
is not interned (which would happen if you did what you are proposing
above).

Regards, Peter

@stsypanov
Copy link
Contributor Author

Also be careful not to return a string which
is not interned (which would happen if you did what you are proposing
above).

Ok, I'm probably missing something, but when we move String.intern() call to this.packageName = pn.intern(); there is no case when non-interned String is returned: there's only one assignment to the field packageName and the value assigned is always interned, right?

@plevart
Copy link
Contributor

plevart commented Apr 27, 2021

Also be careful not to return a string which
is not interned (which would happen if you did what you are proposing
above).

Ok, I'm probably missing something, but when we move String.intern() call to this.packageName = pn.intern(); there is no case when non-interned String is returned: there's only one assignment to the field packageName and the value assigned is always interned, right?

I see:

return pn;

...in code. The local var is returned. As said, string constants are already interned. Calling .intern() on them will mean unnecessary overhead.

@stsypanov
Copy link
Contributor Author

Oh, now I see my mistake, I believed that after pn.intern() is called variable pn can be used along with returned value. Thanks for explanation!

@bridgekeeper
Copy link

bridgekeeper bot commented May 26, 2021

@stsypanov This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

# Conflicts:
#	src/java.base/share/classes/java/lang/Class.java
@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 27, 2021
@openjdk
Copy link

openjdk bot commented May 27, 2021

@stsypanov
Your change (at version 7d52a13) is now ready to be sponsored by a Committer.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label May 27, 2021
Copy link
Member

@cl4es cl4es left a comment

Choose a reason for hiding this comment

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

LGTM

@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 27, 2021
@openjdk
Copy link

openjdk bot commented May 27, 2021

@stsypanov
Your change (at version dc91091) is now ready to be sponsored by a Committer.

@cl4es
Copy link
Member

cl4es commented May 27, 2021

/sponsor

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

openjdk bot commented May 27, 2021

@cl4es @stsypanov Since your change was applied there have been 12 commits pushed to the master branch:

  • 41185d3: 8229517: Support for optional asynchronous/buffered logging
  • 7c85f35: 8267123: Remove RMI Activation
  • 0754266: 8267709: Investigate differences between HtmlStyle and stylesheet.css
  • 23189a1: 8191786: Thread-SMR hash table size should be dynamic
  • ef368b3: 8265836: OperatingSystemImpl.getCpuLoad() returns incorrect CPU load inside a container
  • 10a6f5d: 8230623: Extract command-line help for -Xlint sub-options to new --help-lint
  • bea4109: 8187649: ArrayIndexOutOfBoundsException in java.util.JapaneseImperialCalendar
  • ec65cf8: 8240347: remove undocumented options from jlink --help message
  • 3623abb: 8263087: Add a MethodHandle combinator that switches over a set of MethodHandles
  • 85f6165: 8267817: [TEST] Remove unnecessary init in test/micro/org/openjdk/bench/javax/crypto/full/AESGCMBench:setup
  • ... and 2 more: https://git.openjdk.java.net/jdk/compare/37bc4e2e3c2968d7419dae4f421755b6f7d06090...master

Your commit was automatically rebased without conflicts.

Pushed as commit ae258f1.

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

@stsypanov stsypanov deleted the 8265418 branch May 27, 2021 20:22
@AlanBateman
Copy link
Contributor

I see this has been integrated but I have concerns that the use-sites now all assume that the package name has been intern'ed. We may some crumbs, maybe in an implNote or comment in the Class::getPackageName code, otherwise we risk breakage if getPackageName changed to return a non-intern'ed string at some point.

@stsypanov
Copy link
Contributor Author

@AlanBateman should I then add an implNote to explicitly specify that returned value must be interned?

@AlanBateman
Copy link
Contributor

@AlanBateman should I then add an implNote to explicitly specify that returned value must be interned?

We need to think about this. It's we are 200% sure it will always be intern'ed then it could be specified. If we aren't sure and document it in an implNote then I've doubt that code outside of the JDK may rely on it and we'll never be able to change it.

@stsypanov
Copy link
Contributor Author

I've looked into history and it appears, that the name of the package has been interned both in NamedPackage and Class since 8142968 where modular system was introduced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants