Skip to content

Commit 7535fc4

Browse files
committed
prevent NPE in AbstractBean.firePropertyChange when pcs is null
1 parent a599bc0 commit 7535fc4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

swingx-common/src/main/java/org/jdesktop/beans/AbstractBean.java

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.beans.PropertyVetoException;
2525
import java.beans.VetoableChangeListener;
2626
import java.beans.VetoableChangeSupport;
27+
import java.util.logging.Logger;
2728

2829
/**
2930
* <p>
@@ -130,6 +131,8 @@
130131
*/
131132
public abstract class AbstractBean {
132133

134+
private static final Logger LOG = Logger.getLogger(AbstractBean.class.getName());
135+
133136
/**
134137
* Helper class that manages all the property change notification machinery.
135138
* PropertyChangeSupport cannot be extended directly because it requires
@@ -146,6 +149,7 @@ public abstract class AbstractBean {
146149
/** Creates a new instance of AbstractBean */
147150
protected AbstractBean() {
148151
pcs = new PropertyChangeSupport(this);
152+
// LOG.finest("this:"+this+" pcs=[" + pcs + "]");
149153
vcs = new VetoableChangeSupport(this);
150154
}
151155

@@ -294,6 +298,12 @@ public final PropertyChangeListener[] getPropertyChangeListeners(String property
294298
* @param newValue The new value of the property.
295299
*/
296300
protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
301+
// in some cases pcs is null, then we do nothing
302+
// see org.jdesktop.swingx.painter.AbstractPainterTest with DummyPainter
303+
if(pcs==null) {
304+
LOG.warning("Cannot fire PropertyChange for "+propertyName + " because PropertyChangeSupport instance is null.");
305+
return;
306+
}
297307
pcs.firePropertyChange(propertyName, oldValue, newValue);
298308
}
299309

0 commit comments

Comments
 (0)