Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7138665

JOptionPane.getValue() unexpected change between JRE 1.6 and JRE 1.7

XMLWordPrintable

    • b27
    • x86
    • windows_vista

        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.

              rupashka Pavel Porvatov (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: