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

8307934 JRobot.moveMouseTo must access component on EDT #14354

Closed
wants to merge 9 commits into from

Conversation

Renjithkannath
Copy link
Contributor

@Renjithkannath Renjithkannath commented Jun 7, 2023

Hi Reviewers,

I have updated the JRobot.java file for enabling EDT support, along with I have removed warning BUTTON1_MASK with 'BUTTON1_DOWN_MASK'.

Regards,
Renjith


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

Issue

  • JDK-8307934: JRobot.moveMouseTo must access component on EDT (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14354

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 7, 2023

👋 Welcome back Renjithkannath! 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 Pull request is ready for review label Jun 7, 2023
@openjdk
Copy link

openjdk bot commented Jun 7, 2023

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

  • client

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 client client-libs-dev@openjdk.org label Jun 7, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 7, 2023

SwingUtilities.convertPointToScreen(p, c);
r.x = p.x;
r.y = p.y;
AtomicReference<Point> p = new AtomicReference<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

So this change must be documented on all affected entry points, so that people understand
what it does.
Also touching Robot means you need to run ALL tests that use this utility and make sure you didn't break any.
Have you done that ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @prrace for the reviews,
I have added EDT support for 'getCenterPoint' and 'convertRectToScreen' functions, executed all the tests which are using this function and confirmed its working.

Copy link
Contributor

Choose a reason for hiding this comment

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

But you seem to have ignored my comment about documenting it on 'all entry points' meaning EVERY exported API from this class which can end up here should say something like
"This method will invoke code on the Event Dispatch Thread".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I didn't ignored your valuable comment regarding documentation.

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

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

I still quibble with the premise of this bug.
No exceptions or any nasty stuff will happen if you don't use the EDT to call getSize().
It is more a case of you may get stale results.

And nothing in the AWT docs say you need to do this.

@@ -153,7 +168,7 @@ public void clickMouse(int buttons) {
* Perform a click with the first mouse button.
*/
public void clickMouse() {
clickMouse(InputEvent.BUTTON1_MASK);
clickMouse(InputEvent.BUTTON1_DOWN_MASK);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this is a different int value than the old MASK constant so it is important that you ran all tests (which you say you did) in case some test is not consistently using the Robot API and will end up mixing old and new which will likely cause failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case presses and release happening inside clickMouse overloaded function, this will not mix old and new key

public void clickMouse(int buttons) {
       mousePress(buttons);
       mouseRelease(buttons);
       delay();
   }

SwingUtilities.convertPointToScreen(p, c);
r.x = p.x;
r.y = p.y;
AtomicReference<Point> p = new AtomicReference<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

But you seem to have ignored my comment about documenting it on 'all entry points' meaning EVERY exported API from this class which can end up here should say something like
"This method will invoke code on the Event Dispatch Thread".

@aivanov-jdk
Copy link
Member

I still quibble with the premise of this bug. No exceptions or any nasty stuff will happen if you don't use the EDT to call getSize(). It is more a case of you may get stale results.

Stale result may lead to a test failure because robot moved mouse to an incorrect location.

I submitted this bug after I noticed it in a code review. It might have been the reason why that test failed intermittently. That test was rewritten without using JRobot if my memory serves me right.

And nothing in the AWT docs say you need to do this.

AWT docs don't say AWT is thread-safe either, at least explicitly.

Yet this case is for Swing components where the docs always say Swing is not thread-safe. The JRobot class is test/jdk/javax/swing/regtesthelpers/ which implies it's used for testing Swing.

@Renjithkannath
Copy link
Contributor Author

I have updated documentation of all entry points, @prrace thank you for your review.

Copy link
Member

@aivanov-jdk aivanov-jdk 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 except for the few comments I've left.

Did you run the tests?

Comment on lines 34 to 42
import java.awt.AWTException;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.SwingUtilities;
import java.util.concurrent.atomic.AtomicReference;
import java.lang.reflect.InvocationTargetException;
Copy link
Member

Choose a reason for hiding this comment

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

Could you sort the imports, please? You IDE should be able to handle it for you.

import javax.swing.SwingUtilities;
import java.util.concurrent.atomic.AtomicReference;
import java.lang.reflect.InvocationTargetException;

public class JRobot extends java.awt.Robot {
private static int DEFAULT_DELAY = 550;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add the final modifier to both DEFAULT_DELAY and INTERNAL_DELAY.

@@ -112,17 +112,35 @@ public void hitKey(int... keys) {

/**
* Move mouse cursor to the center of the Component.
* <p>
* <b>Note:</b> This method is executed on EDT
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* <b>Note:</b> This method is executed on EDT
* <b>Note:</b> This method is executed on EDT.

}

/**
* Click in the center of the given Component
* <p>
* <b>Note:</b> This method uses EDT
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* <b>Note:</b> This method uses EDT
* <b>Note:</b> This method is executed on EDT.

Let's be consistent and use the same phrase.

@@ -153,11 +171,14 @@ public void clickMouse(int buttons) {
* Perform a click with the first mouse button.
*/
public void clickMouse() {
clickMouse(InputEvent.BUTTON1_MASK);
clickMouse(InputEvent.BUTTON1_DOWN_MASK);
}

/**
* Click in the center of the given Component
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Click in the center of the given Component
* Click in the center of the given Component.

Let's fix the javadoc even further and add the full stop.

}

/**
* Click in the center of the given Component
* <p>
* <b>Note:</b> This method uses EDT
*
* @param c the Component to click on
* @param buttons mouse button(s).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param buttons mouse button(s).
* @param buttons mouse button(s)

In description of parameters, there are usually no full stops.

@@ -289,4 +323,4 @@ public boolean comparePixels(Point p0, Point p1) {
public boolean comparePixels(int x0, int y0, int x1, int y1) {
return (getPixelColor(x0, y0).equals(getPixelColor(x1, y1)));
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a blank line to the end of the file, please?

import javax.swing.SwingUtilities;
import java.util.concurrent.atomic.AtomicReference;
import java.lang.reflect.InvocationTargetException;

public class JRobot extends java.awt.Robot {
Copy link
Member

Choose a reason for hiding this comment

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

It would be good if you moved the javadoc for the JRobot class to where it belongs: to the class declaration. Now it precedes the import block.

@Renjithkannath
Copy link
Contributor Author

Renjithkannath commented Jun 27, 2023

Thank you @aivanov-jdk for the review, I have sorted imports and updated java docs.
Yes I did two type of tests running all the test cases which uses this modified function also execute all test case,s did not observed any issue.

Copy link
Member

@aivanov-jdk aivanov-jdk left a comment

Choose a reason for hiding this comment

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

Other comments haven't been addressed.

It would be good if you moved the javadoc for the JRobot class to where it belongs: to the class declaration. Now it precedes the import block.

GitHub doesn't allow adding comments to unmodified lines. The javadoc for the class is at lines 24–33:

/**
* JRobot is a wrapper around java.awt.Robot that provides some convenience
* methods.
* <p>When using jtreg you would include this class via something like:
* <pre>
* @library ../../../regtesthelpers
* @build JRobot
* </pre>
*
*/
import java.awt.AWTException;

That is it's before the imports, but it has to be before the class declaration at line 45.

Can you add the final modifier to both DEFAULT_DELAY and INTERNAL_DELAY.

These are the two constants declared at lines 46–47:

private static int DEFAULT_DELAY = 550;
private static int INTERNAL_DELAY = 250;

@@ -168,10 +190,13 @@ public void clickMouseOn(Component c, int buttons) {

/**
* Click the first mouse button in the center of the given Component
* <p>
* <b>Note:</b> This method uses EDT
Copy link
Member

Choose a reason for hiding this comment

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

This instance still uses the old wording.

In my comment, I meant updating all the notes when I said about being consistent.

The convertRectToScreen method needs updating as well.

@Renjithkannath
Copy link
Contributor Author

Updated those changes, please review and let me know your comments.

Comment on lines 47 to 48
final private static int DEFAULT_DELAY = 550;
final private static int INTERNAL_DELAY = 250;
Copy link
Member

Choose a reason for hiding this comment

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

Please use the blessed modifier order: private static final.

@@ -31,19 +42,10 @@
* </pre>
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add {@code} to avoid IDE warning about wrong javadoc tags?

That is the javadoc comment should look like this:

 * <pre>{@code
 * @library ../../../regtesthelpers
 * @build JRobot
 * }</pre>

Copy link
Member

@aivanov-jdk aivanov-jdk 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 Jun 28, 2023

⚠️ @Renjithkannath 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 8307934-v1
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Jun 28, 2023

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

8307934: JRobot.moveMouseTo must access component on EDT

Reviewed-by: aivanov

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

  • 77e7b6d: 8311074: RISC-V: Fix -Wconversion warnings in some code header files
  • 11fd34e: 8310241: OffsetDateTime compareTo redundant computation
  • d979662: 8311115: Type in java.lang.reflect.AccessFlag.METHOD_PARAMETER
  • a995aa6: 8310232: java.time.Clock$TickClock.millis() fails in runtime when tick is 1 microsecond
  • 26efff7: 8309902: C2: assert(false) failed: Bad graph detected in build_loop_late after JDK-8305189
  • 05c2b6c: 8309979: BootstrapMethods attribute is missing in class files recreated by SA
  • 20f7d05: 8310502: Optimization for j.l.Long.fastUUID()
  • 07734f6: 8310848: Convert ClassDesc and MethodTypeDesc to be stored in static final fields
  • e5744b8: 8310919: runtime/ErrorHandling/TestAbortVmOnException.java times out due to core dumps taking a long time on OSX
  • 98a954e: 8308286: Fix clang warnings in linux code
  • ... and 459 more: https://git.openjdk.org/jdk/compare/2b186e246e8c51d4fd8b659872c95044f15e6951...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, @aivanov-jdk) 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 Jun 28, 2023
@Renjithkannath
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 28, 2023
@openjdk
Copy link

openjdk bot commented Jun 28, 2023

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

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Jun 28, 2023
@Renjithkannath
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 30, 2023
@openjdk
Copy link

openjdk bot commented Jun 30, 2023

@Renjithkannath
Your change (at version 9beebe6) is now ready to be sponsored by a Committer.

@aivanov-jdk
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 3, 2023

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

  • 87c79c0: 8309302: java/net/Socket/Timeouts.java fails with AssertionError on test temporal post condition
  • 8e0ca8e: 8310331: JitTester: Exclude java.lang.Math.random
  • 055b4b4: 8310948: Fix ignored-qualifiers warning in Hotspot
  • 2c29705: 8309660: C2: failed: XMM register should be 0-15 (UseKNLSetting and ConvF2HF)
  • 52ee570: 8309209: C2 failed "assert(_stack_guard_state == stack_guard_reserved_disabled) failed: inconsistent state"
  • faf1b82: 8310656: RISC-V: __builtin___clear_cache can fail silently.
  • 0e3d91d: 8311215: [BACKOUT] JDK-8047998 Abort the vm if MaxNewSize is not the same as NewSize when MaxHeapSize is the same as InitialHeapSize
  • 09a4924: 8311145: Remove check_with_errno duplicates
  • 8abb9f5: 8047998: Abort the vm if MaxNewSize is not the same as NewSize when MaxHeapSize is the same as InitialHeapSize
  • d2e1159: 8311125: Remove unused parameter 'phase' in AllocateNode::Ideal_allocation
  • ... and 483 more: https://git.openjdk.org/jdk/compare/2b186e246e8c51d4fd8b659872c95044f15e6951...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 3, 2023

@aivanov-jdk @Renjithkannath Pushed as commit 9d2e0b2.

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

@Renjithkannath Renjithkannath deleted the 8307934-v1 branch August 2, 2023 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
3 participants