-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8334509: Cancelling PageDialog does not return the same PageFormat object #19786
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
Conversation
👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into |
@prsadhuk 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 128 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. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
* @test | ||
* @bug 8334366 | ||
* @key printer | ||
* @summary Verifies oriignal pageobject is returned unmodified |
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.
* @summary Verifies oriignal pageobject is returned unmodified | |
* @summary Verifies original pageobject is returned unmodified |
PageFormat oldFormat = new PageFormat(); | ||
Robot robot = new Robot(); | ||
Thread t1 = new Thread(() -> { | ||
robot.delay(2000); |
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.
usually we keep a delay of 1000 ms, any specific reason for longer delay?
boolean result = newFormat.equals(oldFormat); | ||
if (result) { | ||
System.out.println("Test Passed"); | ||
} else { | ||
throw new RuntimeException("Original PageFormat not returned on cancelling PageDialog"); |
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.
result
variable may not be required as newFormat.equals(oldFormat)
can be evaluated in if condition. I guess there is no need to log "Test Passed", we can check for the failure condition and throw the run time exception.
robot.keyPress(KeyEvent.VK_TAB); | ||
robot.keyRelease(KeyEvent.VK_TAB); | ||
robot.waitForIdle(); | ||
robot.delay(500); |
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 think shorter delay of 100ms should be ok here and below as well.
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 might be ok for statndalone test but jtreg execution is failing sometimes with shorter delay so kept that way..
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.
Have you ever noticed focus going out of dialog/frame when application starts in CI system? In this test, since you are directly using TAB to navigate till Cancel button, any changes that focus might not be on the Dialog on startup? I roughly remember a test where the focus was not on the Frame and we then setFocus or something was used......
for (int i = 0; i < 8; i++) { | ||
robot.keyPress(KeyEvent.VK_TAB); | ||
robot.keyRelease(KeyEvent.VK_TAB); | ||
robot.waitForIdle(); | ||
robot.delay(500); | ||
} | ||
robot.keyPress(KeyEvent.VK_ENTER); | ||
robot.keyRelease(KeyEvent.VK_ENTER); | ||
robot.waitForIdle(); | ||
robot.delay(500); | ||
}); |
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.
These key presses are sent to whatever window has focus… before the Page Dialog is shown and after it's hidden. Is pressing VK_ESCAPE
not enough? Pressing Esc is the same as clicking Cancel button.
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.
Yes, VK_ESCAPE worked..Modified to use that...Thanks..
PageFormat newFormat = pj.pageDialog(oldFormat); | ||
if (!newFormat.equals(oldFormat)) { |
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.
You should interrupt the t1
thread after pj.pageDialog
returns to stop robot from sending keyPress
and keyRelease
after the dialog is hidden. You can even use Thread.sleep
instead of Robot.delay
so that interrupting the thread throws InterruptedException
and its handler just exits. (Robot.delay
catches InterruptedException
and then restores the interrupted flag.)
I wonder if any AWT event is sent when the Page Dialog is shown on the screen, an event is more reliable and key presses won't be sent to an arbitrary window in the system.
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 am not sure I understand this..I guess this thread execution will be a one-time activity so I guess we dont need to do any thread cleanup specially when the dialog is modal so it will only be cancelled (ie pageDialog will return) by VK_ESCAPE in the 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.
You've resolved the problem.
In previous iteration, the keys were sent in a loop, which meant that the thread could continue to run even after the page dialog was closed.
Now the t1
thread presses VK_ESCAPE
once and exits.
@@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer) | |||
} | |||
::GlobalUnlock(setup.hDevMode); | |||
} | |||
doIt = JNI_TRUE; |
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.
Another option would be to return JNI_TRUE
here and to return JNI_FALSE
in the end of the function.
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.
Yes, it could have been done that way and my intiial fix in JBS is that only but I wanted to reinstate the flag as it is before JDK-8307160 which was working till now..
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.
The only problem with the flag is that the data flow is not as clear.
I'm not insisting, it worked before and it will work in the future.
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.
The way it was "before" is that we always returned the value of "doIt". Why not restore that for consistency ?
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 believe that's what this PR is doing, it returns value of "doIt" at end, isn't it?
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.
The way it was "before" is that we always returned the value of "doIt". Why not restore that for consistency ?
I think it's clearer with explicit JNI_FALSE
even though it's inconsistent. You don't have to track in your mind what value doIt
has.
I believe that's what this PR is doing, it returns value of "doIt" at end, isn't it?
Yes, it does now. You changed it after Phil had left his comment.
@@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer) | |||
} | |||
::GlobalUnlock(setup.hDevMode); | |||
} | |||
doIt = JNI_TRUE; | |||
} | |||
|
|||
AwtDialog::CheckUninstallModalHook(); |
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 wonder why the block of code at lines 697–709 is not needed if JNI_FALSE
is returned as a result of an error condition.
No, it is not directly connected to the bug you're fixing, yet it doesn't look right to me.
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.
We can have a followup bug on this I guess since it was existing before JDK-8307160 also..
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.
All I wanted is to bring up the inconsistency so that a few people would take a look at it while reviewing this change.
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 does look odd. Focus would need transferring in both cases I'd expect.
It goes back to the very beginning of open source JDK so I can't see a changeset to point to in order to explain it.
And I also can't find any bug reports that might be related - either one about adding it, or one about things not working because it is not always executed.
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 looked at the history before what's available in Git. I looks this has always been this way. Yet it doesn't look right.
AwtDialog::CheckInstallModalHook()
is called right before the page dialog is displayed by using ::PageSetupDlg
. I expect AwtDialog::CheckUninstallModalHook()
needs to be called after it.
Likely, the early returns (inside if (ret)
) are very rare, if any of these has ever occurred at all.
I'll submit a bug to include calling AwtDialog::CheckUninstallModalHook()
in error cleanup. The done
label which were before JDK-8307160 should've been before the line which calls CheckUninstallModalHook
.
It works on CI...Job link in JBS.. |
@@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer) | |||
} | |||
::GlobalUnlock(setup.hDevMode); | |||
} | |||
doIt = JNI_TRUE; |
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.
The only problem with the flag is that the data flow is not as clear.
I'm not insisting, it worked before and it will work in the future.
@@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer) | |||
} | |||
::GlobalUnlock(setup.hDevMode); | |||
} | |||
doIt = JNI_TRUE; | |||
} | |||
|
|||
AwtDialog::CheckUninstallModalHook(); |
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.
All I wanted is to bring up the inconsistency so that a few people would take a look at it while reviewing this change.
PageFormat newFormat = pj.pageDialog(oldFormat); | ||
if (!newFormat.equals(oldFormat)) { |
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.
You've resolved the problem.
In previous iteration, the keys were sent in a loop, which meant that the thread could continue to run even after the page dialog was closed.
Now the t1
thread presses VK_ESCAPE
once and exits.
robot.delay(2000); | ||
robot.keyPress(KeyEvent.VK_ESCAPE); | ||
robot.keyRelease(KeyEvent.VK_ESCAPE); | ||
robot.waitForIdle(); |
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 think waitForIdle
is redundant here: the thread doesn't do anything after pressing VK_ESCAPE
.
/integrate |
Going to push as commit 689cee3.
Your commit was automatically rebased without conflicts. |
return JNI_FALSE; | ||
return doIt; |
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'd rather keep JNI_FALSE
here — it's more explicit and therefore clearer. You don't have to keep track of the value of doIt
flag while reading the code.
In fact, I'd prefer no doIt
flag at all… yet it makes handling the code below if (ret)
slightly harder.
@@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer) | |||
} | |||
::GlobalUnlock(setup.hDevMode); | |||
} | |||
doIt = JNI_TRUE; |
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.
The way it was "before" is that we always returned the value of "doIt". Why not restore that for consistency ?
I think it's clearer with explicit JNI_FALSE
even though it's inconsistent. You don't have to track in your mind what value doIt
has.
I believe that's what this PR is doing, it returns value of "doIt" at end, isn't it?
Yes, it does now. You changed it after Phil had left his comment.
@@ -690,6 +691,7 @@ Java_sun_awt_windows_WPageDialogPeer__1show(JNIEnv *env, jobject peer) | |||
} | |||
::GlobalUnlock(setup.hDevMode); | |||
} | |||
doIt = JNI_TRUE; | |||
} | |||
|
|||
AwtDialog::CheckUninstallModalHook(); |
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 looked at the history before what's available in Git. I looks this has always been this way. Yet it doesn't look right.
AwtDialog::CheckInstallModalHook()
is called right before the page dialog is displayed by using ::PageSetupDlg
. I expect AwtDialog::CheckUninstallModalHook()
needs to be called after it.
Likely, the early returns (inside if (ret)
) are very rare, if any of these has ever occurred at all.
I'll submit a bug to include calling AwtDialog::CheckUninstallModalHook()
in error cleanup. The done
label which were before JDK-8307160 should've been before the line which calls CheckUninstallModalHook
.
/backport jdk23-dev |
@prsadhuk The target repository |
/backport openjdk/jdk23u |
@prsadhuk the backport was successfully created on the branch backport-prsadhuk-689cee3d-master in my personal fork of openjdk/jdk23u. To create a pull request with this backport targeting openjdk/jdk23u:master, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk23u:
|
@prsadhuk You should backport it to 23 which corresponds to |
/backport jdk jdk23 |
@prsadhuk the backport was successfully created on the branch backport-prsadhuk-689cee3d-jdk23 in my personal fork of openjdk/jdk. To create a pull request with this backport targeting openjdk/jdk:jdk23, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk:
|
On cancelling PageDialog, same PageFormat object should be returned which stopped working after JDK-8307160.
Fix is made to reinstate "doIt" flag removed in JDK-8307160 so that correct value is returned from PageDialog.show action..
An automated printing testcase is created since the issue was caught by manual test and so having another manual test run the risk of not being executed during CI testing..
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19786/head:pull/19786
$ git checkout pull/19786
Update a local copy of the PR:
$ git checkout pull/19786
$ git pull https://git.openjdk.org/jdk.git pull/19786/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19786
View PR using the GUI difftool:
$ git pr show -t 19786
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19786.diff
Webrev
Link to Webrev Comment