Skip to content

Commit 71b956b

Browse files
committed
fix: lint fixes for NullAssignment
1 parent b551b57 commit 71b956b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/BaseTreeNode.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@
1919
public class BaseTreeNode extends TreeNode {
2020
private ImageDescriptor imageDescriptor;
2121
private String text = "";
22+
private Object value;
2223

2324
public BaseTreeNode(Object value) {
2425
super(value);
2526
if (value instanceof String)
2627
this.text = value.toString();
2728
}
2829

29-
public void setValue(Object value) {
30-
this.value = value;
31-
}
32-
3330
public void addChild(BaseTreeNode child) {
3431
TreeNode[] children = getChildren();
3532
List<BaseTreeNode> list = new ArrayList<BaseTreeNode>();
@@ -41,7 +38,12 @@ public void addChild(BaseTreeNode child) {
4138
}
4239
child.setParent(this);
4340
list.add(child);
44-
this.setChildren(list.toArray(new BaseTreeNode[list.size()]));
41+
42+
// Calls to a collection's `toArray(E[])` method should specify a target array
43+
// of zero size. This allows the JVM
44+
// to optimize the memory allocation and copying as much as possible.
45+
// https://shipilev.net/blog/2016/arrays-wisdom-ancients/
46+
this.setChildren(list.toArray(new BaseTreeNode[0]));
4547
}
4648

4749
public void removeChildren() {
@@ -104,6 +106,10 @@ public void setText(String text) {
104106
this.text = text;
105107
}
106108

109+
public void setValue(Object value) {
110+
this.value = value;
111+
}
112+
107113
@Override
108114
public String toString() {
109115
return this.value.toString();
@@ -112,8 +118,6 @@ public String toString() {
112118
public void reset() {
113119
this.removeChildren();
114120
this.text = "";
115-
this.value = null;
116-
this.imageDescriptor = null;
117121
}
118122

119123
/**

0 commit comments

Comments
 (0)