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

JDK-8261422: Adjust problematic String.format calls in jdk/internal/util/Preconditions.java outOfBoundsMessage #2483

Closed
wants to merge 1 commit into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Feb 9, 2021


Progress

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

Issue

  • JDK-8261422: Adjust problematic String.format calls in jdk/internal/util/Preconditions.java outOfBoundsMessage

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2483/head:pull/2483
$ git checkout pull/2483

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 9, 2021

👋 Welcome back mbaesken! 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 Feb 9, 2021

@MBaesken 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 core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review labels Feb 9, 2021
@MBaesken
Copy link
Member Author

MBaesken commented Feb 9, 2021

The method outOfBoundsMessage has a few problematic calls to String.format.
Those calls use "%d" however the arguments are of type Number, so we should better use %s .

Example :

https://sonarcloud.io/project/issues?id=shipilev_jdk&languages=java&open=AXcqM87A8sPJZZzON5wY&resolved=false&severities=BLOCKER&types=BUG

return String.format("Index %d out of bounds for length %d",
args.get(0), args.get(1));

Sonar error :
An 'int' is expected rather than a .

@mlbridge
Copy link

mlbridge bot commented Feb 9, 2021

Webrevs

args.get(0), args.get(1), args.get(2));
case "checkFromIndexSize":
return String.format("Range [%d, %<d + %d) out of bounds for length %d",
return String.format("Range [%s, %<s + %s) out of bounds for length %s",
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we have a code coverage here and that we need tests to exercise these code paths.

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 haven't written the class Preconditions.java, this question should probably go to the authors .
I found the String.format syntax a bit unusual, should this be rewritten ?

Choose a reason for hiding this comment

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

AFAIK, Preconditions was introduced in https://bugs.openjdk.java.net/browse/JDK-8155794

Copy link
Member

Choose a reason for hiding this comment

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

It looks like java/util/Objects/CheckIndex should adequately cover this change.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

As we're potentially formatting any "Number" type here, theoretically floats could be passed which would result in an Exception. In fact, only decimal types are passed by the callers so this should not happen. Unfortunately there's no super type specifying decimal numbers.

And as we're not doing some fancy formatting but just %d, I think replacing this with %s should be ok.

@openjdk
Copy link

openjdk bot commented Feb 12, 2021

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

8261422: Adjust problematic String.format calls in jdk/internal/util/Preconditions.java outOfBoundsMessage

Reviewed-by: clanger

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

  • 682e78e: 8261071: AArch64: Refactor interpreter native wrappers
  • ebaa58d: 8261505: Test test/hotspot/jtreg/gc/parallel/TestDynShrinkHeap.java killed by Linux OOM Killer
  • 3210095: 8261079: Fix support for @hidden in classes and interfaces
  • 9c0ec8d: 8260941: Remove the conc_scan parameter for CardTable
  • da9895a: 8261499: Simplify HTML for javadoc links
  • 0779add: 8255059: Regressions >5% in all Javadoc benchmarks in 16-b19
  • 6a84ec6: 8260044: Parallel GC: Concurrent allocation after heap expansion may cause unnecessary full gc
  • 92ff891: 8261593: Do not use NULL pointer as write buffer parameter in jfrEmergencyDump.cpp write_repository_files
  • 60a2072: 8260431: com/sun/jdi/JdbOptions.java failed with "RuntimeException: 'prop[boo] = >foo<' missing from stdout/stderr"
  • bf47a47: 8261282: Lazy initialization of built-in ICC_Profile/ColorSpace classes is too lazy
  • ... and 42 more: https://git.openjdk.java.net/jdk/compare/8ebed28403afa1fae2505a1937694c90d27c6d6b...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 the ready Pull request is ready to be integrated label Feb 12, 2021
@MBaesken
Copy link
Member Author

/integrate

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

openjdk bot commented Feb 16, 2021

@MBaesken Since your change was applied there have been 87 commits pushed to the master branch:

  • cdc874d: 8261601: free memory in early return in Java_sun_nio_ch_sctp_SctpChannelImpl_receive0
  • e2d52ae: 8261413: Shenandoah: Disable class-unloading in I-U mode
  • 34ae7ae: 8261609: remove remnants of XML-driven builders
  • 6badd22: 8261351: Create implementation for NSAccessibilityRadioButton protocol
  • 849f4c0: 8260291: The case instruction is not visible in dark mode
  • 2e610f5: 8260687: Inherited font size is smaller than expected when using StyleSheet to add styles
  • 3882fda: 8260414: Remove unused set_single_threaded_mode() method in task executor
  • c6eedda: 8261500: Shenandoah: reconsider region live data memory ordering
  • df0897e: 8261504: Shenandoah: reconsider ShenandoahJavaThreadsIterator::claim memory ordering
  • 745c0b9: 8261493: Shenandoah: reconsider bitmap access memory ordering
  • ... and 77 more: https://git.openjdk.java.net/jdk/compare/8ebed28403afa1fae2505a1937694c90d27c6d6b...master

Your commit was automatically rebased without conflicts.

Pushed as commit 219b115.

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

@AlanBateman
Copy link
Contributor

I see this change been integrated but there is further work required on the test coverage. Are you planing to do code coverage and create a follow-on issue to add more tests?

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.

5 participants