JDK-7138665 : JOptionPane.getValue() unexpected change between JRE 1.6 and JRE 1.7
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2012-01-28
  • Updated: 2013-04-22
  • Resolved: 2012-02-21
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 7 JDK 8
7u4Fixed 8 b27Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows Vista (32 bit)

A DESCRIPTION OF THE PROBLEM :
JOptionPane behavior has change in JDK 1.7,
and can break existing applications (typically illegal cast exception),
because for some scenarios, JOptionPane.getValue() now returns JOptionPane.UNINITIALIZED_VALUE while it was returning Integer(0) before.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the  following program.
Enter some text in the the dialog and *press enter key*.
(If you click a button, this bug is not triggered.)



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"Resut => 0"
(like JRE 1.6)

ACTUAL -
"Resut => uninitializedValue"


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
        JOptionPane  pane = new JOptionPane("Enter value", JOptionPane.QUESTION_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION, null,null, null);
        pane.setWantsInput(true);
        JDialog dialog = pane.createDialog(null, "My Dialog");
        dialog.setVisible(true);
        Object result = pane.getValue();
        System.out.println("Resut => " + result);
        dialog.dispose();
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
In client code, check if result is JOptionPane.UNINITIALIZED_VALUE and use 0 instead.

Comments
EVALUATION We should revert 6428694 ( http://javaweb.sfbay.sun.com/jcg/1.7.0-dolphin/swing/6428694/src/share/classes/javax/swing/JOptionPane.java.udiff.html) and refix it by another way.
06-02-2012