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

JTree.getSelectionPaths() now returns empty array instead of null

    XMLWordPrintable

Details

    • b07
    • 7
    • b14
    • x86
    • windows_vista, windows_7
    • Verified

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.7.0"
        Java(TM) SE Runtime Environment (build 1.7.0-b147)
        Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.0.6002]

        A DESCRIPTION OF THE PROBLEM :
        Documentation specifies that JTree.getSelectionPaths() returns null if there is no selection. This was always the case until 1.7.0, where an empty array is returned instead.

        REGRESSION. Last worked in version 6u26

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the supplied Applet

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        OK should appear in the Applet
        ACTUAL -
        FAIL!! appears in the Applet

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;
        import javax.swing.tree.*;
        import java.awt.*;

        public class GetSelectionPathsBug extends JApplet {

            public void init() {
                SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            JTree t = new JTree();
                            TreePath[] selPaths = t.getSelectionPaths();
                            JLabel lab = new JLabel(selPaths == null ? "OK" : "FAIL!!");
                            getContentPane().add(lab);
                        }});
            }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Use a subclass with:

        @Override
        TreePath[] getSelectionPaths() {
            TreePath[] res = super.getSelectionPaths();
            return res != null && res.length == 0 ? null : res;
        }

        or add explicit test for empty array wherever a null check is currently carried out

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: