JDK-4786415 : JCK1.4a-runtime api/javax_swing/interactive/JPMenuTests.html#JPMenuTests fails
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    linux,solaris_8,solaris_9,windows_2000 linux,solaris_8,solaris_9,windows_2000
  • CPU: x86,sparc,itanium
  • Submitted: 2002-11-29
  • Updated: 2004-11-01
  • Resolved: 2004-11-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b11Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: iaR10016			Date: 11/28/2002


Filed By       : J2SE-SQA [###@###.###
JDK            : JDK1.4.2-b08, JDK1.4.0, JDK1.4.1
JCK            : JCK1.4a-runtime
Platform[s]    : RedHat Linux 7.3 (GNOME), Windows 2000, Solaris 9 (sparc) (CDE), Solaris 8 (x86)
switch/Mode    : default
JCK test owner : http://javaweb.eng/jck/usr/owners.jto
Falling test[s]: api/javax_swing/interactive/JPMenuTests.html#JPMenuTests
                 [JPMenuTests0006, JPMenuTests0007, JPMenuTests0008]

JCK1.4a-runtime api/javax_swing/interactive/JPMenuTests.html#JPMenuTests test
fails with JDK1.4.0, JDK1.4.1, JDK1.4.2.

JPopupMenu.setLocation(int, int), JPopupMenu.setPopupSize(int, int) and
JPopupMenu.setPopupSize(Dimention) methods do not work as expected when their integer
parameters are big enough.

Please run api/javax_swing/interactive/JPMenuTests.html#JPMenuTests test on RedHat Linux
(GNOME) with JDK1.4.2-b08. Here are examples of incorrect JPopupMenu behaviour:

1. Testcases JPMenuTests0007, JPMenuTests0008 test JPopupMenu.setPopupSize(int, int) and
JPopupMenu.setPopupSize(Dimention) methods correspondingly. If JPopupMenu size is less then
screen size (for example, 100), it behaves correctly: it has correct width and height
and appears in the place where mouse pointer is located.

In testcase JPMenu0007 set Width to 2147483647 (max integer number). Right-click mouse on
tested panel several times. The JPopupMenu is redrawn incorrectly or sometimes does not appear.

Set Width to 10000 and right-click on the tested panel. JPopupMenu width is more then the tested
panel width, so the menu left upper corner is located at the left border of the screen. It is OK.
Now set Width to 100 (as at the begining of the testing). It is expected that the menu left upper
corner will appear inside the tested panel, but actually it is outside the panel - it is still
located at the left screen border. If you right-click once more, the location of JPopupMenu
becomes correct.

2. Testcase JPMenuTests0006 tests JPopupMenu.setLocation(int, int) method.
Please, set XCoord and YCoord parameters to 10000 (it is more then the screen size) and then
right-click on tested panel. JPopupMenu appears in the right bottom corner of the screen. Now set
XCoord and YCoord to 2147483647 (max integer number). It is expected that the JPopupMenu will
appear in the right bottom corner too, bat actually it is in the upper left corner now.

Test source location:
=====================
/java/re/jck/1.4a/promoted/fcs/binaries/JCK-runtime-14a/tests/api/javax_swing/interactive/JPMenuTests.java

jtr file location:
==================
/net/jtgb4u4c.sfbay/export/sail15/results/mantis/b08/jck14a/x86/sol8_x86_server_linux-10/workDir/api-interactive/javax_swing/interactive/JPMenuTests_JPMenuTests.jtr

How to reproduce:
=================
Run the following script (you may need to change its variables)

--- script start ---
#!/bin/bash
JCK="/java/re/jck/1.4a/promoted/fcs/binaries/JCK-runtime-14a"
JDK="/net/jdk/export/disk8/local.java/jdk1.4/linux-i386"
export CLASSPATH="$JCK/classes:$JCK/lib/javatest.jar"
$JDK/bin/java javasoft.sqe.tests.api.javax.swing.interactive.JPMenu.JPMenuTests -TestCaseID JPMenuTests0007 JPMenuTests0008 JPMenuTests0006
--- script end ---

Specific machine info:
======================
Hostname: linux-19
OS: RedHat Linux 7.3 (GNOME)

Hostname: linux-2
OS: Windows 2000

Hostname: linux-10
OS: Solaris 8 (x86)

Hostname: novo48
OS: Solaris 9 (sparc) (CDE)

======================================================================
###@###.### 10/13/04 17:27 GMT

Comments
SUGGESTED FIX Name: azR10139 Date: 12/04/2002 ------- JPopupMenu.java ------- *** /tmp/sccs.A_ai5E Tue Dec 3 20:48:55 2002 --- JPopupMenu.java Tue Dec 3 19:55:31 2002 *************** *** 358,367 **** size = JPopupMenu.this.getPreferredSize(); ! if( (p.x + size.width) > screenBounds.x + scrWidth ) p.x = screenBounds.x + scrWidth - size.width; ! if( (p.y + size.height) > screenBounds.y + scrHeight) p.y = screenBounds.y + scrHeight - size.height; /* Change is made to the desired (X,Y) values, when the --- 358,371 ---- size = JPopupMenu.this.getPreferredSize(); ! // Use long variables to prevent overflow ! long pw = (long) p.x + (long) size.width; ! long ph = (long) p.y + (long) size.height; ! ! if( pw > screenBounds.x + scrWidth ) p.x = screenBounds.x + scrWidth - size.width; ! if( ph > screenBounds.y + scrHeight) p.y = screenBounds.y + scrHeight - size.height; /* Change is made to the desired (X,Y) values, when the ------- PopupFactory.java ------- *** /tmp/sccs.xFaq7E Tue Dec 3 20:52:34 2002 --- PopupFactory.java Tue Dec 3 20:52:03 2002 *************** *** 494,501 **** r.y += i.top; r.width -= (i.left + i.right); r.height -= (i.top + i.bottom); ! return SwingUtilities.isRectangleContainingRectangle( ! r, new Rectangle(x, y, width, height)); } else if (parent instanceof JApplet) { Rectangle r = parent.getBounds(); --- 494,500 ---- r.y += i.top; r.width -= (i.left + i.right); r.height -= (i.top + i.bottom); ! return r.contains(x, y, width, height); } else if (parent instanceof JApplet) { Rectangle r = parent.getBounds(); *************** *** 503,510 **** r.x = p.x; r.y = p.y; ! return SwingUtilities.isRectangleContainingRectangle( ! r, new Rectangle(x, y, width, height)); } else if (parent instanceof Window || parent instanceof Applet) { // No suitable swing component found --- 502,508 ---- r.x = p.x; r.y = p.y; ! return r.contains(x, y, width, height); } else if (parent instanceof Window || parent instanceof Applet) { // No suitable swing component found ======================================================================
25-09-2004

EVALUATION Name: azR10139 Date: 12/04/2002 Long bug description needs long evaluation. So, be it. 1) The tests are invalid. In the class JPMenuTester$myMouse size of the popup must be changed BEFORE popup is shown, otherwise they will be shown at a location determined by popup's old size. JPopupMenu.setPopupSize does not change location of the popup, only its size. 2) The problem with the MAXINT is the overflow errors in SwingUtilities.isRectangleContainingRectangle() and JPopupMenu.adjustPopupLocationToFitScreen() methods. The idea of suggested fix is as follows: a) To use 'long' variables in the JPopupMenu.adjustPopupLocationToFitScreen() method to calculate position of the right bottom point of the popup to avoid overflowing; b) In the PopupFactory$ContainerPopup.fitsOnScreen() method to use java.awt.Rectangle.contains() method instead of SwingUtilities.isRectangleContainingRectangle() to check if popup is not exceeds size of the invoker and can be painted lightweightly. As this is not a major issue this problem will be resolved in tiger release. ###@###.### 12/03/2002 ======================================================================
03-12-2002