-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
👋 Welcome back Renjithkannath! A progress list of the required criteria for merging this PR into |
@Renjithkannath The following label will be automatically applied to this pull request:
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. |
Webrevs
|
SwingUtilities.convertPointToScreen(p, c); | ||
r.x = p.x; | ||
r.y = p.y; | ||
AtomicReference<Point> p = new AtomicReference<>(); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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".
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
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 |
I have updated documentation of all entry points, @prrace thank you for your review. |
There was a problem hiding this 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?
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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))); | |||
} | |||
} | |||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
Thank you @aivanov-jdk for the review, I have sorted imports and updated java docs. |
There was a problem hiding this 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:
jdk/test/jdk/javax/swing/regtesthelpers/JRobot.java
Lines 24 to 34 in b482a9c
/** | |
* 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 bothDEFAULT_DELAY
andINTERNAL_DELAY
. ⇈
These are the two constants declared at lines 46–47:
jdk/test/jdk/javax/swing/regtesthelpers/JRobot.java
Lines 46 to 47 in b482a9c
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 |
There was a problem hiding this comment.
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.
Updated those changes, please review and let me know your comments. |
final private static int DEFAULT_DELAY = 550; | ||
final private static int INTERNAL_DELAY = 250; |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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>
There was a problem hiding this 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.
|
@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:
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
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 |
@Renjithkannath |
/integrate |
@Renjithkannath |
/sponsor |
Going to push as commit 9d2e0b2.
Your commit was automatically rebased without conflicts. |
@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. |
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
Issue
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