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

8270058: Use Objects.check{Index,FromIndexSize} for java.desktop #4718

Closed
wants to merge 4 commits into from

Conversation

@kelthuzadx
Copy link
Member

@kelthuzadx kelthuzadx commented Jul 8, 2021

After JDK-8265518(#3615), it's possible to replace all variants of checkIndex by Objects.checkIndex/Objects.checkFromToIndex/Objects.checkFromIndexSize in the whole JDK codebase.

As Mandy suggested, I create this PR for changes involving client code:

src/java.desktop/share/classes/com/sun/media/sound/AudioFloatInputStream.java
src/java.desktop/share/classes/javax/swing/JTabbedPane.java
test/jdk/java/awt/print/PrinterJob/ImagePrinting/ClippedImages.java
test/jdk/javax/imageio/AppletResourceTest.java
test/jdk/javax/imageio/ImageReaderReadAll.java
test/jdk/javax/imageio/metadata/IIOMetadataFormat/UserPluginMetadataFormatTest.java


Progress

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

Issue

  • JDK-8270058: Use Objects.check{Index,FromIndexSize} for java.desktop

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4718

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

Using diff file

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jul 8, 2021

👋 Welcome back yyang! 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 label Jul 8, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jul 8, 2021

@kelthuzadx The following labels will be automatically applied to this pull request:

  • 2d
  • awt
  • sound
  • swing

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

@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Jul 8, 2021

/label remove sound
/label remove 2d

@openjdk openjdk bot removed the sound label Jul 8, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jul 8, 2021

@kelthuzadx
The sound label was successfully removed.

@openjdk openjdk bot removed the 2d label Jul 8, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jul 8, 2021

@kelthuzadx
The 2d label was successfully removed.

@mlbridge
Copy link

@mlbridge mlbridge bot commented Jul 8, 2021

@@ -81,8 +82,7 @@ public long getFrameLength() {
public int read(float[] b, int off, int len) throws IOException {
if (b == null)
throw new NullPointerException();
if (off < 0 || len < 0 || len > b.length - off)
throw new IndexOutOfBoundsException();
Objects.checkFromIndexSize(len, off, b.length);
Copy link
Member

@mrserb mrserb Jul 21, 2021

Choose a reason for hiding this comment

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

Should it be (off, len, b.length)?

Copy link
Member Author

@kelthuzadx kelthuzadx Jul 21, 2021

Choose a reason for hiding this comment

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

Well, it seems they are equivalent forms. But yes, (off, len, b.length) would be more reasonable.

     * <ul>
     *  <li>{@code fromIndex < 0}</li>
     *  <li>{@code size < 0}</li>
     *  <li>{@code fromIndex + size > length}, taking into account integer overflow</li>
     *  <li>{@code length < 0}, which is implied from the former inequalities</li>
     * </ul>

@@ -87,8 +88,7 @@ public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 1 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 1);
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();
Copy link
Contributor

@prsadhuk prsadhuk Jul 22, 2021

Choose a reason for hiding this comment

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

Can't we use checkFromToIndex​ for this IOOBE too? Used in many other places in this PR...

Please also confirm all tests modified are green after this modification..

Copy link
Member Author

@kelthuzadx kelthuzadx Jul 22, 2021

Choose a reason for hiding this comment

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

checkFromToIndex​ has different semantice with checkIndex:

  • checkFromToIndex
     * <ul>
     *  <li>{@code fromIndex < 0}</li>
     *  <li>{@code fromIndex > toIndex}</li>
     *  <li>{@code toIndex > length}</li>
     *  <li>{@code length < 0}, which is implied from the former inequalities</li>
     * </ul>
  • checkIndex
     * <ul>
     *  <li>{@code index < 0}</li>
     *  <li>{@code index >= length}</li>
     *  <li>{@code length < 0}, which is implied from the former inequalities</li>
     * </ul>

The following tests are passed after applying this patch:

test/jdk/javax/imageio/AppletResourceTest.java
test/jdk/javax/imageio/ImageReaderReadAll.java
test/jdk/javax/imageio/metadata/IIOMetadataFormat/UserPluginMetadataFormatTest.java

ClippedImages.java is a manual test, I have no environment to test it, but since it's a trivial replacement, I think it's okay..

Copy link
Contributor

@prsadhuk prsadhuk Jul 22, 2021

Choose a reason for hiding this comment

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

I meant

if (imageIndex < minIndex)
                    throw new IndexOutOfBoundsException();

can't it be replaced with Objects.checkFromToIndex(minIndex, imageIndex, ..

Copy link
Member Author

@kelthuzadx kelthuzadx Jul 27, 2021

Choose a reason for hiding this comment

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

Hi, sorry for the late response. checkFromToIndex has many constraints, this code may not satisfy those constraints, so I don't think we should do that in this PR.(Maybe we can file a new PR to do replacement carefully)

Copy link
Contributor

@prsadhuk prsadhuk Jul 30, 2021

Choose a reason for hiding this comment

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

OK...The subject line of this PR states that checkFromToIndex will also be used but I see only checkIndex so I intervened. Anyways, the code in question is in test so not much of an issue.

Copy link
Member Author

@kelthuzadx kelthuzadx Jul 30, 2021

Choose a reason for hiding this comment

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

Thanks @prsadhuk for review! I've updated the title to exclude checkFromToIndex.

@openjdk
Copy link

@openjdk openjdk bot commented Jul 30, 2021

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

8270058: Use Objects.check{Index,FromIndexSize} for java.desktop

Reviewed-by: psadhukhan, pbansal, jdv

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

  • 6c8441f: 8271878: UnProblemList jdk/jfr/event/gc/detailed/TestEvacuationFailedEvent.java in JDK18
  • 7728423: 8271895: UnProblemList javax/swing/JComponent/7154030/bug7154030.java in JDK18
  • cd6b54e: Merge
  • cebcc07: 8271894: ProblemList javax/swing/JComponent/7154030/bug7154030.java in JDK17
  • 5f547e8: 8271877: ProblemList jdk/jfr/event/gc/detailed/TestEvacuationFailedEvent.java in JDK17
  • 181483b: 8271064: ZGC several jvm08 perf regressions after JDK-8268372
  • a007cb1: 8271863: ProblemList serviceability/sa/TestJmapCore.java on linux-x64 with ZGC
  • d62fbea: 8271898: disable os.release_multi_mappings_vm on macOS-X64
  • 359c708: 8271893: mark hotspot runtime/PerfMemDestroy/PerfMemDestroy.java test as ignoring external VM flags
  • a3b0143: 8271887: mark hotspot runtime/CDSCompressedKPtrs tests which ignore external VM flags
  • ... and 429 more: https://git.openjdk.java.net/jdk/compare/06d26208c5604c0c640eff4da94ef814c2ebebf0...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 label Jul 30, 2021
@kelthuzadx kelthuzadx changed the title 8270058: Use Objects.check{Index,FromToIndex,FromIndexSize} for java.desktop 8270058: Use Objects.check{Index,FromIndexSize} for java.desktop Jul 30, 2021
if (index < 0 || index >= pages.size()) {
throw new IndexOutOfBoundsException("Index: "+index+", Tab count: "+pages.size());
}
Objects.checkIndex(index, pages.size());
Copy link
Member

@jayathirthrao jayathirthrao Jul 30, 2021

Choose a reason for hiding this comment

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

I think we should not replace IOOBE checks with messages. Its better to keep it old way.

Choose a reason for hiding this comment

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

Objects.checkIndex itself throws exceptions for wrong values. So this should be ok. No?

Copy link
Member

@jayathirthrao jayathirthrao Jul 30, 2021

Choose a reason for hiding this comment

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

We have specific message here like "Tab count" which we are not passing and will be helpful for debugging in future.

Copy link
Member Author

@kelthuzadx kelthuzadx Aug 5, 2021

Choose a reason for hiding this comment

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

Restored.

Copy link

@pankaj-bansal pankaj-bansal left a comment

Looks ok to me

@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Aug 5, 2021

@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Aug 5, 2021

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Aug 5, 2021

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

  • 64d18d4: 4819544: SwingSet2 JTable Demo throws NullPointerException
  • 6c8441f: 8271878: UnProblemList jdk/jfr/event/gc/detailed/TestEvacuationFailedEvent.java in JDK18
  • 7728423: 8271895: UnProblemList javax/swing/JComponent/7154030/bug7154030.java in JDK18
  • cd6b54e: Merge
  • cebcc07: 8271894: ProblemList javax/swing/JComponent/7154030/bug7154030.java in JDK17
  • 5f547e8: 8271877: ProblemList jdk/jfr/event/gc/detailed/TestEvacuationFailedEvent.java in JDK17
  • 181483b: 8271064: ZGC several jvm08 perf regressions after JDK-8268372
  • a007cb1: 8271863: ProblemList serviceability/sa/TestJmapCore.java on linux-x64 with ZGC
  • d62fbea: 8271898: disable os.release_multi_mappings_vm on macOS-X64
  • 359c708: 8271893: mark hotspot runtime/PerfMemDestroy/PerfMemDestroy.java test as ignoring external VM flags
  • ... and 430 more: https://git.openjdk.java.net/jdk/compare/06d26208c5604c0c640eff4da94ef814c2ebebf0...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Aug 5, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Aug 5, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Aug 5, 2021

@kelthuzadx Pushed as commit ea9a595.

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

@kelthuzadx kelthuzadx deleted the checkindex_java_desktop branch Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants