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

8258006: Replaces while cycles with iterator with enhanced for in java.desktop #1574

Conversation

@turbanoff
Copy link
Contributor

@turbanoff turbanoff commented Dec 2, 2020

There are few places in code where manual while loop is used with Iterator to iterate over Collection.
Instead of manual while cycles it's preferred to use enhanced-for cycle instead: it's less verbose, makes code easier to read and it's less error-prone.
It doesn't have any performance impact: java compiler generates similar code when compiling enhanced-for cycle.

See similar cleanup in C++ code - #1707


Progress

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

Issue

  • JDK-8258006: Replaces while cycles with iterator with enhanced for in java.desktop

Reviewers

Download

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Dec 2, 2020

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

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Dec 2, 2020

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

  • 2d
  • awt
  • beans
  • 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.

Loading

@mrserb
Copy link
Member

@mrserb mrserb commented Dec 9, 2020

Loading

@turbanoff turbanoff changed the title [PATCH] Replaces while cycles with iterator with enhanced for in java.desktop 8258006: Replaces while cycles with iterator with enhanced for in java.desktop Dec 11, 2020
@openjdk openjdk bot added the rfr label Dec 11, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Dec 11, 2020

Webrevs

Loading

@prrace
Copy link
Contributor

@prrace prrace commented Dec 12, 2020

Whilst this looks "reasonable" I am not impressed by the complete lack of description of

  1. why this is being proposed
  2. what are the benefits
  3. what testing has been done
    etc etc.
    The bug repoert is even more content free. It also deserves a meaningful description

Loading

@turbanoff
Copy link
Contributor Author

@turbanoff turbanoff commented Dec 14, 2020

I've added few words in description.

About testing: as I can see testing is done via Github Actions. tier1 builds are ok.

Loading

@prrace
Copy link
Contributor

@prrace prrace commented Dec 14, 2020

I've added few words in description.

About testing: as I can see testing is done via Github Actions. tier1 builds are ok.

OK that's better But about testing. The github actions won't run a single test that touches any code with these changes
All the client tests are in tier3-> tier5.

Loading

@turbanoff turbanoff force-pushed the use_enhanced_for_instead_of_while_java.desktop branch from 94d465d to 32824c3 Dec 15, 2020
@turbanoff
Copy link
Contributor Author

@turbanoff turbanoff commented Dec 15, 2020

I've run test-tier3. 15 tests failed. Looks like they are not related to my changes:

JT Harness : Tests that failed
Tests are grouped by their final status message.
Execution failed: `main' threw exception: TestFailedException: TEST FAILED: ; nested exception is: TestFailedException: TEST FAILED: Rmid process exited with status 1 after 100ms.

    java/rmi/activation/ActivationSystem/modifyDescriptor/ModifyDescriptor.java: synopsis: need to modify registered ActivationDesc and ActivationGroupDesc 

Execution failed: `main' threw exception: TestFailedException: TEST FAILED: ; nested exception is: TestFailedException: TEST FAILED: Test1 failed: a service would not restart

    java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java: synopsis: Activatable objects cannot be restarted. 

Execution failed: `main' threw exception: TestFailedException: TEST FAILED: ; nested exception is: java.rmi.activation.ActivateFailedException: activation failed; nested exception is: java.rmi.activation.ActivationException: timeout creating child process

    java/rmi/activation/Activatable/checkAnnotations/CheckAnnotations.java: rmid should annotate child process output
    java/rmi/activation/Activatable/inactiveGroup/InactiveGroup.java: synopsis: rmid should not destroy group when it reports inactiveGroup 

Execution failed: `main' threw exception: java.lang.Error: text should be 1.1

    java/beans/PropertyEditor/TestDoubleClassValue.java: Tests PropertyEditor for value of type Double
    java/beans/PropertyEditor/TestDoubleTypeValue.java: Tests PropertyEditor for value of type double 

Execution failed: `main' threw exception: java.lang.Error: values are not equal

    java/beans/PropertyEditor/TestDoubleClassJava.java: Tests PropertyEditor for value of type Double
    java/beans/PropertyEditor/TestDoubleTypeJava.java: Tests PropertyEditor for value of type double 

Execution failed: `main' threw exception: java.lang.Exception: failures: 1

    sanity/client/SwingSet/src/ColorChooserDemoTest.java: Verifies SwingSet3 ColorChooserDemo by performing simple interaction with all the controls that are shown in the ColorChooserDialog. 

Execution failed: `main' threw exception: java.lang.StackOverflowError

    java/beans/XMLEncoder/Test6531597.java: Tests encoding of arrays of primitives
    java/beans/XMLEncoder/Test6989223.java: Tests Rectangle2D.Double encoding
    java/beans/XMLEncoder/java_awt_GridBagConstraints.java: Tests GridBagConstraints encoding
    java/beans/XMLEncoder/java_awt_LinearGradientPaint.java: Tests LinearGradientPaint encoding
    java/beans/XMLEncoder/java_awt_RadialGradientPaint.java: Tests RadialGradientPaint encoding
    java/beans/XMLEncoder/java_awt_geom_AffineTransform.java: Tests AffineTransform encoding 

Loading

@prrace
Copy link
Contributor

@prrace prrace commented Dec 15, 2020

These tests more or less never fail so how are you sure it is not your changes ?
And 8 beans tests failed and you made 3 changes in beans code so I'd like to see some evidence
to show these failures are unrelated and an explanation as to why these stable tests now fail ?
I don't think they are problem listed.

Loading

@turbanoff
Copy link
Contributor Author

@turbanoff turbanoff commented Dec 16, 2020

Oops. I also had changes from https://bugs.openjdk.java.net/browse/JDK-4511638 in my working tree.
After I reverted them only 3 tests failed in test-tier3:

==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR
>> jtreg:test/jdk:tier3                               1192  1189     3     0 <<
   jtreg:test/langtools:tier3                            0     0     0     0
   jtreg:test/jaxp:tier3                                 0     0     0     0
==============================
TEST FAILURE
JT Harness : Tests that failed
Tests are grouped by their final status message.
Execution failed: `main' threw exception: TestFailedException: TEST FAILED: ; nested exception is: java.rmi.activation.ActivateFailedException: activation failed; nested exception is: java.rmi.activation.ActivationException: timeout creating child process

    java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java: rmid does not handle group restart for latecomer objects 

Execution failed: `main' threw exception: java.lang.Exception: failures: 1

    sanity/client/SwingSet/src/ColorChooserDemoTest.java: Verifies SwingSet3 ColorChooserDemo by performing simple interaction with all the controls that are shown in the ColorChooserDialog.
    sanity/client/SwingSet/src/SwingSet2DemoTest.java: Verifies check box menu item, radio button menu item, nested menus and themes using SwingSet2 main window. 

Report generated on Dec 16, 2020 5:54:22 PM
Using JT Harness 6.0; built on November 30, 2020 at 12:00:00 AM MSK with java version "1.8.0_172"

Loading

@turbanoff
Copy link
Contributor Author

@turbanoff turbanoff commented Dec 16, 2020

I tried to run this 3 tests separately - all passed. Looks like inference from other tests in test suite.

user@WORK-PC /cygdrive/f/Projects/official_openjdk
$ make test TEST="jtreg:test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java"
Building target 'test' in configuration 'windows-x86_64-server-release'
Running tests using JTREG control variable 'VM_OPTIONS=-Duser.language=en -Duser.country=US'
Test selection 'jtreg:test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java', will run:
* jtreg:test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java

Running test 'jtreg:test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java'
Passed: sanity/client/SwingSet/src/SwingSet2DemoTest.java
Test results: passed: 1
Report written to F:\Projects\official_openjdk\build\windows-x86_64-server-release\test-results\jtreg_test_jdk_sanity_client_SwingSet_src_SwingSet2DemoTest_java\html\report.html
Results written to F:\Projects\official_openjdk\build\windows-x86_64-server-release\test-support\jtreg_test_jdk_sanity_client_SwingSet_src_SwingSet2DemoTest_java
Finished running test 'jtreg:test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java'
Test report is stored in build/windows-x86_64-server-release/test-results/jtreg_test_jdk_sanity_client_SwingSet_src_SwingSet2DemoTest_java

==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR
   jtreg:test/jdk/sanity/client/SwingSet/src/SwingSet2DemoTest.java
                                                         1     1     0     0
==============================
TEST SUCCESS

Finished building target 'test' in configuration 'windows-x86_64-server-release'
user@WORK-PC /cygdrive/f/Projects/official_openjdk
$ make test TEST="jtreg:test/jdk/sanity/client/SwingSet/src/ColorChooserDemoTest.java"
Building target 'test' in configuration 'windows-x86_64-server-release'
Running tests using JTREG control variable 'VM_OPTIONS=-Duser.language=en -Duser.country=US'
Test selection 'jtreg:test/jdk/sanity/client/SwingSet/src/ColorChooserDemoTest.java', will run:
* jtreg:test/jdk/sanity/client/SwingSet/src/ColorChooserDemoTest.java

Running test 'jtreg:test/jdk/sanity/client/SwingSet/src/ColorChooserDemoTest.java'
Passed: sanity/client/SwingSet/src/ColorChooserDemoTest.java
Test results: passed: 1
Report written to F:\Projects\official_openjdk\build\windows-x86_64-server-release\test-results\jtreg_test_jdk_sanity_client_SwingSet_src_ColorChooserDemoTest_java\html\report.html
Results written to F:\Projects\official_openjdk\build\windows-x86_64-server-release\test-support\jtreg_test_jdk_sanity_client_SwingSet_src_ColorChooserDemoTest_java
Finished running test 'jtreg:test/jdk/sanity/client/SwingSet/src/ColorChooserDemoTest.java'
Test report is stored in build/windows-x86_64-server-release/test-results/jtreg_test_jdk_sanity_client_SwingSet_src_ColorChooserDemoTest_java

==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR
   jtreg:test/jdk/sanity/client/SwingSet/src/ColorChooserDemoTest.java
                                                         1     1     0     0
==============================
TEST SUCCESS

Finished building target 'test' in configuration 'windows-x86_64-server-release'
user@WORK-PC /cygdrive/f/Projects/official_openjdk
$ make test TEST="jtreg:test/jdk/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java"
Building target 'test' in configuration 'windows-x86_64-server-release'
Running tests using JTREG control variable 'VM_OPTIONS=-Duser.language=en -Duser.country=US'
Test selection 'jtreg:test/jdk/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java', will run:
* jtreg:test/jdk/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java

Running test 'jtreg:test/jdk/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java'
Passed: java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java
Test results: passed: 1
Report written to F:\Projects\official_openjdk\build\windows-x86_64-server-release\test-results\jtreg_test_jdk_java_rmi_activation_Activatable_restartLatecomer_RestartLatecomer_java\html\report.html
Results written to F:\Projects\official_openjdk\build\windows-x86_64-server-release\test-support\jtreg_test_jdk_java_rmi_activation_Activatable_restartLatecomer_RestartLatecomer_java
Finished running test 'jtreg:test/jdk/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java'
Test report is stored in build/windows-x86_64-server-release/test-results/jtreg_test_jdk_java_rmi_activation_Activatable_restartLatecomer_RestartLatecomer_java

==============================
Test summary
==============================
   TEST                                              TOTAL  PASS  FAIL ERROR
   jtreg:test/jdk/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java
                                                         1     1     0     0
==============================
TEST SUCCESS

Finished building target 'test' in configuration 'windows-x86_64-server-release'

Loading

prrace
prrace approved these changes Dec 16, 2020
Copy link
Contributor

@prrace prrace left a comment

Ok. Approved.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Dec 16, 2020

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

8258006: Replaces while cycles with iterator with enhanced for in java.desktop

Reviewed-by: prr, serb

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

  • dc7f01f: 8257584: [macos] NullPointerException originating from LWCToolkit.java
  • c7c53d0: 8258554: javax/swing/JTable/4235420/bug4235420.java fails in GTK L&F
  • c50b464: 8258715: [JVMCI] separate JVMCI code install timers for CompileBroker and hosted compilations
  • 64644a1: 8253881: Hotspot/Serviceability Terminology Refresh
  • 6a78b2a: 8258645: Bring Jemmy 1.3.11 to JDK test base
  • 7f92d18: 8258553: Limit number of fields in instance to be considered for scalar replacement
  • adf0e23: 8257800: CompileCommand TypedMethodOptionMatcher::parse_method_pattern() may over consume
  • 06c24e1: 8256213: Remove os::split_reserved_memory
  • be41468: 8258696: Temporarily revert use of pattern match instanceof until docs-reference is fixed
  • a4f393c: 8258661: Inner class ResponseCacheEntry could be static
  • ... and 72 more: https://git.openjdk.java.net/jdk/compare/a372be4ba2216adb325f7616e54c1d58ac8fdf2a...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 (@prrace, @mrserb) 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).

Loading

@openjdk openjdk bot added the ready label Dec 16, 2020
@turbanoff
Copy link
Contributor Author

@turbanoff turbanoff commented Dec 16, 2020

/integrate

Loading

@openjdk openjdk bot added the sponsor label Dec 16, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 16, 2020

@turbanoff
Your change (at version 32824c3) is now ready to be sponsored by a Committer.

Loading

@mrserb
Copy link
Member

@mrserb mrserb commented Dec 18, 2020

I'll run some other automated tests, in progress.

Loading

mrserb
mrserb approved these changes Dec 19, 2020
@mrserb
Copy link
Member

@mrserb mrserb commented Dec 19, 2020

/sponsor

Loading

@openjdk openjdk bot closed this Dec 19, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 19, 2020

@mrserb @turbanoff Since your change was applied there have been 82 commits pushed to the master branch:

  • dc7f01f: 8257584: [macos] NullPointerException originating from LWCToolkit.java
  • c7c53d0: 8258554: javax/swing/JTable/4235420/bug4235420.java fails in GTK L&F
  • c50b464: 8258715: [JVMCI] separate JVMCI code install timers for CompileBroker and hosted compilations
  • 64644a1: 8253881: Hotspot/Serviceability Terminology Refresh
  • 6a78b2a: 8258645: Bring Jemmy 1.3.11 to JDK test base
  • 7f92d18: 8258553: Limit number of fields in instance to be considered for scalar replacement
  • adf0e23: 8257800: CompileCommand TypedMethodOptionMatcher::parse_method_pattern() may over consume
  • 06c24e1: 8256213: Remove os::split_reserved_memory
  • be41468: 8258696: Temporarily revert use of pattern match instanceof until docs-reference is fixed
  • a4f393c: 8258661: Inner class ResponseCacheEntry could be static
  • ... and 72 more: https://git.openjdk.java.net/jdk/compare/a372be4ba2216adb325f7616e54c1d58ac8fdf2a...master

Your commit was automatically rebased without conflicts.

Pushed as commit 580af49.

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

Loading

@openjdk openjdk bot removed the rfr label Dec 19, 2020
@turbanoff turbanoff deleted the use_enhanced_for_instead_of_while_java.desktop branch Sep 15, 2021
@openjdk openjdk bot added the client label Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants