Skip to content

Commit 3ac0a04

Browse files
committed
PDFBOX-5660: refactor, avoid leaking this in constructor; remove unused
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1934034 13f79535-47bb-0310-9956-ffa450edef68
1 parent ade08f8 commit 3ac0a04

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ private void initComponents()
377377
jSplitPane = new javax.swing.JSplitPane();
378378
JScrollPane jScrollPaneLeft = new JScrollPane();
379379
tree = new Tree();
380+
tree.init();
380381
jScrollPaneRight = new JScrollPane();
381382
jTextPane = new javax.swing.JTextPane();
382383

debugger/src/main/java/org/apache/pdfbox/debugger/treestatus/TreeStatus.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@
3434
*/
3535
public final class TreeStatus
3636
{
37-
private Object rootNode;
37+
private final Object rootNode;
3838

39-
private TreeStatus()
40-
{
41-
}
42-
4339
/**
4440
* Constructor.
4541
*

debugger/src/main/java/org/apache/pdfbox/debugger/ui/Tree.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public class Tree extends JTree
5959
{
6060
// No logging possible in this class because it is created before the "LogDialog.init()" call
6161
private final JPopupMenu treePopupMenu;
62-
private final Object rootNode;
6362

6463
// Temporary files are stored in a private temp directory with restricted permissions,
6564
// which is deleted on exit using a shutdown hook.
@@ -72,8 +71,14 @@ public class Tree extends JTree
7271
public Tree()
7372
{
7473
treePopupMenu = new JPopupMenu();
74+
}
75+
76+
/**
77+
* Initialization, to be called immediately after construction.
78+
*/
79+
public void init()
80+
{
7581
setComponentPopupMenu(treePopupMenu);
76-
rootNode = getModel().getRoot();
7782
int treeRowHeight = Integer.parseInt(PDFDebugger.configuration.getProperty(
7883
"treeRowHeight", Integer.toString(getRowHeight())));
7984
setRowHeight(treeRowHeight);
@@ -159,7 +164,8 @@ private JMenuItem getTreePathMenuItem(final TreePath path)
159164
copyPathMenuItem.addActionListener(actionEvent ->
160165
{
161166
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
162-
clipboard.setContents(new StringSelection(new TreeStatus(rootNode).getStringForPath(path)), null);
167+
String pathString = new TreeStatus(getModel().getRoot()).getStringForPath(path);
168+
clipboard.setContents(new StringSelection(pathString), null);
163169
});
164170
return copyPathMenuItem;
165171
}

0 commit comments

Comments
 (0)