Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

prsadhuk
Copy link
Contributor

@prsadhuk prsadhuk commented Jun 19, 2024

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

  • 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-8334509: Cancelling PageDialog does not return the same PageFormat object (Bug - P2)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 19, 2024

👋 Welcome back psadhukhan! 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
Copy link

openjdk bot commented Jun 19, 2024

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

8334509: Cancelling PageDialog does not return the same PageFormat object

Reviewed-by: aivanov, prr

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 master branch:

  • 8e1d2b0: 8334441: Mark tests in jdk_security_infra group as manual
  • 93d9802: 8334715: [riscv] Mixed use of tab and whitespace in riscv.ad
  • c41293a: 8334695: Fix build failure without zgc after JDK-8333300
  • 75bea28: 8333867: SHA3 performance can be improved
  • 9f8de22: 8327793: Deprecate jstatd for removal
  • dbf5a9a: 8334706: [JVMCI] APX registers incorrectly exposed on AMD64
  • 08ace27: 8332314: Add window size configuration option to JavaShellToolBuilder interface
  • 711e723: 6967482: TAB-key does not work in JTables after selecting details-view in JFileChooser
  • d2bebff: 8327370: (ch) sun.nio.ch.Poller.register throws AssertionError
  • ed14906: 8333361: ubsan,test : libHeapMonitorTest.cpp:518:9: runtime error: null pointer passed as argument 2, which is declared to never be null
  • ... and 118 more: https://git.openjdk.org/jdk/compare/3a01b47ac97714608356ce3faf797c37dc63e9af...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 rfr Pull request is ready for review label Jun 19, 2024
@openjdk
Copy link

openjdk bot commented Jun 19, 2024

@prsadhuk 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 19, 2024
@mlbridge
Copy link

mlbridge bot commented Jun 19, 2024

Webrevs

* @test
* @bug 8334366
* @key printer
* @summary Verifies oriignal pageobject is returned unmodified
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @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);
Copy link
Contributor

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?

Comment on lines 60 to 64
boolean result = newFormat.equals(oldFormat);
if (result) {
System.out.println("Test Passed");
} else {
throw new RuntimeException("Original PageFormat not returned on cancelling PageDialog");
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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..

Copy link
Contributor

@TejeshR13 TejeshR13 left a 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......

Comment on lines 47 to 57
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);
});
Copy link
Member

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.

Copy link
Contributor Author

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..

Comment on lines +59 to +60
PageFormat newFormat = pj.pageDialog(oldFormat);
if (!newFormat.equals(oldFormat)) {
Copy link
Member

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.

Copy link
Contributor Author

@prsadhuk prsadhuk Jun 20, 2024

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

Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor Author

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..

Copy link
Member

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.

Copy link
Contributor

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 ?

Copy link
Contributor Author

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?

Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor Author

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..

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

@prsadhuk
Copy link
Contributor Author

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......

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;
Copy link
Member

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();
Copy link
Member

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.

Comment on lines +59 to +60
PageFormat newFormat = pj.pageDialog(oldFormat);
if (!newFormat.equals(oldFormat)) {
Copy link
Member

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();
Copy link
Member

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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 20, 2024
@prsadhuk
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 21, 2024

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

  • 8e1d2b0: 8334441: Mark tests in jdk_security_infra group as manual
  • 93d9802: 8334715: [riscv] Mixed use of tab and whitespace in riscv.ad
  • c41293a: 8334695: Fix build failure without zgc after JDK-8333300
  • 75bea28: 8333867: SHA3 performance can be improved
  • 9f8de22: 8327793: Deprecate jstatd for removal
  • dbf5a9a: 8334706: [JVMCI] APX registers incorrectly exposed on AMD64
  • 08ace27: 8332314: Add window size configuration option to JavaShellToolBuilder interface
  • 711e723: 6967482: TAB-key does not work in JTables after selecting details-view in JFileChooser
  • d2bebff: 8327370: (ch) sun.nio.ch.Poller.register throws AssertionError
  • ed14906: 8333361: ubsan,test : libHeapMonitorTest.cpp:518:9: runtime error: null pointer passed as argument 2, which is declared to never be null
  • ... and 118 more: https://git.openjdk.org/jdk/compare/3a01b47ac97714608356ce3faf797c37dc63e9af...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 21, 2024
@openjdk openjdk bot closed this Jun 21, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 21, 2024
@openjdk
Copy link

openjdk bot commented Jun 21, 2024

@prsadhuk Pushed as commit 689cee3.

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

@prsadhuk prsadhuk deleted the print-fix branch June 21, 2024 18:03
Comment on lines -580 to +581
return JNI_FALSE;
return doIt;
Copy link
Member

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;
Copy link
Member

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();
Copy link
Member

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.

@prsadhuk
Copy link
Contributor Author

/backport jdk23-dev

@openjdk
Copy link

openjdk bot commented Jun 24, 2024

@prsadhuk The target repository jdk23-dev is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk21u, openjdk/jdk21u-dev, openjdk/jdk22u, openjdk/jdk23u, openjdk/jdk7u, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/jfx, openjdk/jfx17u, openjdk/jfx21u, openjdk/jfx22u, openjdk/lilliput-jdk17u, openjdk/lilliput-jdk21u, openjdk/shenandoah-jdk21u, openjdk/shenandoah-jdk8u.
Supplying the organization/group prefix is optional.

@prsadhuk
Copy link
Contributor Author

/backport openjdk/jdk23u

@openjdk
Copy link

openjdk bot commented Jun 24, 2024

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

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 689cee3d from the openjdk/jdk repository.

The commit being backported was authored by Prasanta Sadhukhan on 21 Jun 2024 and was reviewed by Alexey Ivanov and Phil Race.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk23u.git backport-prsadhuk-689cee3d-master:backport-prsadhuk-689cee3d-master
$ git checkout backport-prsadhuk-689cee3d-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk23u.git backport-prsadhuk-689cee3d-master

⚠️ @prsadhuk You are not yet a collaborator in my fork openjdk-bots/jdk23u. An invite will be sent out and you need to accept it before you can proceed.

@aivanov-jdk
Copy link
Member

/backport openjdk/jdk23u

@prsadhuk You should backport it to 23 which corresponds to jdk23 branch in jdk repo. The command should look like this: /backport :jdk23 or /backport jdk jdk23, see the /backport command.

@prsadhuk
Copy link
Contributor Author

/backport jdk jdk23

@openjdk
Copy link

openjdk bot commented Jun 24, 2024

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

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 689cee3d from the openjdk/jdk repository.

The commit being backported was authored by Prasanta Sadhukhan on 21 Jun 2024 and was reviewed by Alexey Ivanov and Phil Race.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk.git backport-prsadhuk-689cee3d-jdk23:backport-prsadhuk-689cee3d-jdk23
$ git checkout backport-prsadhuk-689cee3d-jdk23
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk.git backport-prsadhuk-689cee3d-jdk23

⚠️ @prsadhuk You are not yet a collaborator in my fork openjdk-bots/jdk. An invite will be sent out and you need to accept it before you can proceed.

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
Development

Successfully merging this pull request may close these issues.

5 participants