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

8305157: The java.util.Arrays class should be declared final #13221

Closed
wants to merge 1 commit into from

Conversation

minborg
Copy link
Contributor

@minborg minborg commented Mar 29, 2023

Non-instantiable utility classes should be declared final and have a private constructors.

See Effective Java, Third Edition, Joshua Bloch (for example, Item 19 or Item 22).


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-8305158 to be approved

Issues

  • JDK-8305157: The java.util.Arrays class should be declared final
  • JDK-8305158: The java.util.Arrays class should be declared final (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13221

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

Using diff file

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

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
sergeyklay Serghei Iakovlev
@minborg
Copy link
Contributor Author

minborg commented Mar 29, 2023

/csr

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 29, 2023

👋 Welcome back pminborg! 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 csr Pull request needs approved CSR before integration rfr Pull request is ready for review labels Mar 29, 2023
@openjdk
Copy link

openjdk bot commented Mar 29, 2023

@minborg an approved CSR request is already required for this pull request.

@openjdk
Copy link

openjdk bot commented Mar 29, 2023

@minborg 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 Mar 29, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 29, 2023

Webrevs

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Look fine, it can't be subclassed anyway so there is no compatibility impact.

@minborg
Copy link
Contributor Author

minborg commented Mar 29, 2023

Look fine, it can't be subclassed anyway so there is no compatibility impact.

I thought the change would trigger a change in the public API as the modifiers are changed for the class. This would likely be picked up by compatibility checks and so, a CSR would be needed?

@AlanBateman
Copy link
Contributor

I thought the change would trigger a change in the public API as the modifiers are changed for the class. This would likely be picked up by compatibility checks and so, a CSR would be needed?

It's not a compatibility issue but a CSR is needed to track the change to the signature.

@pavelrappo
Copy link
Member

I thought the change would trigger a change in the public API as the modifiers are changed for the class. This would likely be picked up by compatibility checks and so, a CSR would be needed?

It's not a compatibility issue but a CSR is needed to track the change to the signature.

Not that I disagree with this PR, but it would be interesting to see rationale for it in CSR.

@rgiulietti
Copy link
Contributor

Would it make sense to throw an AssertionError in the constructor? Just in case...

@RogerRiggs
Copy link
Contributor

The CSR implies that java.util.Arrays has a non-private constructor but it does.
The CSR should mention that the constructor is private and the Array cannot be subclassed as part of the compatibility comments.

@RogerRiggs
Copy link
Contributor

Would it make sense to throw an AssertionError in the constructor? Just in case...

It hardly seems worth the bytecode; the constructor could only be invoked by breaking in using reflection and the result would be an instance with no instance methods.

@rgiulietti
Copy link
Contributor

In some future, one could mistakenly instantiate the class from some new method in the class itself.
Throwing protects against such mistakes already during testing, avoiding a reviewer to purposely checking that the empty constructor is never invoked.

@jddarcy
Copy link
Member

jddarcy commented Mar 29, 2023

There are numerous examples in the JDK where we have the lone private constructor throw an exception to make sure the class isn't instantiated.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Mar 29, 2023
@openjdk
Copy link

openjdk bot commented Mar 29, 2023

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

8305157: The java.util.Arrays class should be declared final

Reviewed-by: alanb, rriggs, bpb

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

  • be764a7: 8302814: Delete unused CountLoopEnd instruct with CmpX
  • 34f4d7f: 8304759: Add BitMap iterators
  • 42df1a9: 8304991: Redundant hyphen in @param results in double-dash in javadocs
  • e3855d0: 8304840: Dangling CharacterCodingException in a few javadoc descriptions
  • 6727490: 8303161: [vectorapi] VectorMask.cast narrow operation returns incorrect value with SVE
  • f07decb: 8272613: CharsetDecoder.decode(ByteBuffer) throws IllegalArgumentException
  • 014c658: 8305086: G1 Redirty Cards phase printed twice
  • 2fa0933: 8304990: unnecessary dash in @param gives double-dash in docs
  • e56bcb0: 8305095: Update java/net/httpclient/CustomRequestPublisher.java to use new HttpTestServer factory methods
  • 0985288: 8304681: compiler/sharedstubs/SharedStubToInterpTest.java fails after JDK-8304387

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.

➡️ 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 Mar 29, 2023
@minborg
Copy link
Contributor Author

minborg commented Mar 30, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Mar 30, 2023

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

  • b261e6c: 8304445: Remaining uses of NULL in ciInstanceKlass.cpp
  • 2c38e67: 8302644: IGV: Apply filters per graph tab and not globally
  • f0dba21: 8304871: Use default visibility for static library builds
  • 77811fa: 8305222: Change unique_ctrl_out_or_null to unique_ctrl_out in PhaseCFG::convert_NeverBranch_to_Goto
  • 2d607c9: 8262294: java/net/httpclient/ProxyAuthDisabledSchemes.java fails with HTTP/1.1 parser received no bytes
  • b3ff8d1: 8303805: [REDO] JDK-8302189 and JDK-8302799
  • b524a74: 8301106: Allow archived Java strings to be moved by GC
  • 9643f65: 8304436: com/sun/jdi/ThreadMemoryLeakTest.java fails with "OutOfMemoryError: Java heap space" with ZGC
  • 69152c3: 8305202: Fix Copyright Header in ZonedDateTimeFormatterBenchmark
  • 438c969: 8304976: Optimize DateTimeFormatterBuilder.ZoneTextPrinterParser.getTree()
  • ... and 11 more: https://git.openjdk.org/jdk/compare/ff368d504e9101e11c7182185f56255f429d31e3...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 30, 2023

@minborg Pushed as commit 9df2060.

💡 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
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

None yet

7 participants