JDK-8040209 : Ambiguous API document for JTree.setSelectionPaths
  • Type: Bug
  • Component: client-libs
  • Affected Version: 7
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-04-14
  • Updated: 2021-12-20
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Alex found below API document is ambiguous during a code review:

* The lead path is set to the last unique path. 

Which has been added after the fix JDK-6210002 Undefined behavior of DefaultTreeSelectionModel.getSelectionPath() after setSelectionPaths.

Before the fix the javadoc was:
http://docs.oracle.com/javase/6/docs/api/javax/swing/tree/DefaultTreeSelectionModel.html#setSelectionPaths%28javax.swing.tree.TreePath[]%29
    "The lead path is set to the last path in pPaths."

It was found that the setSelectionPaths method works differently for the duplicated paths.
For example:
  ----------------
  model.setSelectionPaths(new TreePath[] {path1, path2, path1});
   // lead path is path2 (last set path is path1)
  ----------------

It was decided not to change the setSelectionPaths method algorithm to not break the already written applications and just update the specification from "The lead path is set to the last path in pPaths." to "The lead path is set to the last unique path."
  So "unique path" refers to paths in the current setSelectionPaths arguments.

This comment contradicts with the:
http://docs.oracle.com/javase/7/docs/api/javax/swing/tree/TreeSelectionModel.html
   The lead TreePath is the last path that was added (or set).
and with:
http://docs.oracle.com/javase/7/docs/api/javax/swing/tree/DefaultTreeSelectionModel.html#leadPath
  protected TreePath leadPath
  Last path that was added.

Comments
- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

Note, we need to clarify below behaviors for setSelectionPaths, are they expected behavior? 1) In case user making multi-selection of nodes through <Shift+ Cursor Up>, if user selected a tree node "path3" first, pressed <Shift+Cursor up> to select other tree nodes: <path2>, then <path1>, the lead path is always set to anchor node <"path3" in this example> in setSelectionPaths because the anchor node is always the last path in the passed in pPaths 2) In case user making multi-selection of nodes through <Shift+ Cursor Down>, the lead path is set to the last selected node in setSelectionPaths, because the last selected node is always the last path in the passed in pPaths
15-04-2014