-
Bug
-
Resolution: Fixed
-
P2
-
7
-
b07
-
b14
-
x86
-
windows_vista, windows_7
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2216809 | 7u4 | Pavel Porvatov | P2 | Closed | Fixed | b02 |
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
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
- backported by
-
JDK-2216809 JTree.getSelectionPaths() now returns empty array instead of null
-
- Closed
-
- duplicates
-
JDK-7104607 Java7 Jtree.getSelectionPaths() returned value
-
- Closed
-
- relates to
-
JDK-6210002 Undefined behavior of DefaultTreeSelectionModel.getSelectionPath() after setSelectionPaths
-
- Closed
-