Skip to content

Commit 80b8f89

Browse files
committed
Fixing some NPE's in FPP-Node (e.g. when Asset is outside of the root path)
This closes jme-core PR #421
1 parent ccf5e32 commit 80b8f89

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

jme3-core/src/com/jme3/gde/core/filters/FilterPostProcessorNode.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2010 jMonkeyEngine
2+
* Copyright (c) 2009-2016 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,8 @@
4545
import java.util.List;
4646
import java.util.concurrent.Callable;
4747
import java.util.concurrent.ExecutionException;
48+
import java.util.logging.Level;
49+
import java.util.logging.Logger;
4850
import javax.swing.Action;
4951
import org.openide.nodes.AbstractNode;
5052
import org.openide.nodes.Children;
@@ -63,8 +65,9 @@
6365
public class FilterPostProcessorNode extends AbstractNode {
6466

6567
private FilterDataObject dataObject;
66-
private static Image smallImage = IconList.eyeOpen.getImage();
68+
private final static Image smallImage = IconList.eyeOpen.getImage();
6769
private FilterPostProcessor fpp;
70+
private static final Logger logger = Logger.getLogger(FilterPostProcessorNode.class.getName());
6871

6972
public FilterPostProcessorNode(FilterDataObject dataObject) {
7073
super(new FilterChildren(dataObject), Lookups.singleton(new FilterIndexSupport()));
@@ -74,7 +77,6 @@ public FilterPostProcessorNode(FilterDataObject dataObject) {
7477
setName(dataObject.getName());
7578
getLookup().lookup(FilterIndexSupport.class).setFilterPostProcessorNode(this);
7679
((FilterChildren) getChildren()).setFilterPostProcessorNode(this);
77-
7880
}
7981

8082
@Override
@@ -89,7 +91,9 @@ public Image getOpenedIcon(int type) {
8991

9092
public FilterPostProcessor getFilterPostProcessor() {
9193
if (fpp == null) {
92-
this.fpp = dataObject.loadAsset();
94+
fpp = dataObject.loadAsset();
95+
if (fpp == null)
96+
logger.log(Level.SEVERE, "Cannot load Filter. Maybe it's not in the Asset Path?");
9397
}
9498
return fpp;
9599
}
@@ -130,7 +134,9 @@ public void addFilter(final Filter filter) {
130134
SceneApplication.getApplication().enqueue(new Callable<Object>() {
131135

132136
public Object call() throws Exception {
133-
getFilterPostProcessor().addFilter(filter);
137+
FilterPostProcessor fp = getFilterPostProcessor();
138+
if (fp != null)
139+
fp.addFilter(filter);
134140
return null;
135141
}
136142
});
@@ -142,7 +148,10 @@ public void removeFilter(final Filter filter) {
142148
SceneApplication.getApplication().enqueue(new Callable<Object>() {
143149

144150
public Object call() throws Exception {
145-
getFilterPostProcessor().removeFilter(filter);
151+
FilterPostProcessor fp = getFilterPostProcessor();
152+
if (fp != null)
153+
fp.removeFilter(filter);
154+
146155
return null;
147156
}
148157
});
@@ -163,8 +172,8 @@ public void run() {
163172
public Action[] getActions(boolean context) {
164173
// return super.getActions(context);
165174
return new Action[]{
166-
new NewFilterPopup(this)
167-
};
175+
new NewFilterPopup(this)
176+
};
168177
}
169178

170179
public static class FilterChildren extends Children.Keys<Object> {
@@ -184,7 +193,9 @@ public void setFilterPostProcessorNode(FilterPostProcessorNode node) {
184193
@Override
185194
protected void addNotify() {
186195
super.addNotify();
187-
setKeys(createKeys());
196+
List<Object> keys = createKeys();
197+
if (keys != null)
198+
setKeys(keys);
188199
}
189200

190201
protected void doRefresh() {
@@ -201,7 +212,11 @@ protected List<Object> createKeys() {
201212

202213
public List<Object> call() throws Exception {
203214
List<Object> keys = new LinkedList<Object>();
204-
for (Iterator it = node.getFilterPostProcessor().getFilterIterator(); it.hasNext();) {
215+
FilterPostProcessor fp = node.getFilterPostProcessor();
216+
if (fp == null) /* e.g. Filter not in Asset Path */
217+
return null;
218+
219+
for (Iterator it = fp.getFilterIterator(); it.hasNext();) {
205220
Filter filter = (Filter) it.next();
206221
keys.add(filter);
207222
}
@@ -219,10 +234,15 @@ public List<Object> call() throws Exception {
219234
@Override
220235
protected Node[] createNodes(Object t) {
221236
Filter filter = (Filter) t;
222-
//get JmeFilter, the only FilterNode spi
223-
FilterNode di = Lookup.getDefault().lookup(FilterNode.class);
224-
Node[] ret = di.createNodes(filter, dataObject, readOnly);
225-
return ret;
237+
for (FilterNode di : Lookup.getDefault().lookupAll(FilterNode.class)) {
238+
if (di.getExplorerObjectClass().getName().equals(filter.getClass().getName())) {
239+
Node[] ret = di.createNodes(filter, dataObject, readOnly);
240+
if (ret != null) {
241+
return ret;
242+
}
243+
}
244+
}
245+
return new Node[]{};
226246
}
227247
}
228248
}

0 commit comments

Comments
 (0)