Skip to content

Commit 6134019

Browse files
committed
fix update always had global listener
1 parent 62935b4 commit 6134019

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.github.leonardofel</groupId>
55
<artifactId>json-java-put-null-fix</artifactId>
6-
<version>3.0.42.unsafe</version>
6+
<version>3.0.43.unsafe</version>
77
<packaging>jar</packaging>
88

99
<name>JSON in Java WITH WORKING .put(null)</name>

src/main/java/org/json/JSONObject.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1845,15 +1845,14 @@ public void addUpdateListener(String key, PropertyChangeListener listener) {
18451845
* If updateListener not initialized.
18461846
*/
18471847
public JSONObject update(String key, Object newValue) throws JSONException {
1848-
if (this.propertyChangeSupport.hasListeners(key)) {
1849-
final JSONObject oldThis = new JSONObject(this.toString());
1850-
final Object oldValue = this.opt(key);
1851-
this.put(key, newValue);
1848+
final JSONObject oldThis = new JSONObject(this.toString());
1849+
final Object oldValue = this.opt(key);
1850+
this.put(key, newValue);
18521851

1853-
this.propertyChangeSupport.firePropertyChange(JSONObject.propertyChangeGlobalKeyword, oldThis, this);
1852+
this.propertyChangeSupport.firePropertyChange(JSONObject.propertyChangeGlobalKeyword, oldThis, this);
1853+
1854+
if (this.propertyChangeSupport.hasListeners(key)) {
18541855
this.propertyChangeSupport.firePropertyChange(key, oldValue, newValue);
1855-
} else {
1856-
throw new JSONException("updateListener on \"" + key + "\" not initialized");
18571856
}
18581857

18591858
return this;

src/test/java/org/json/junit/JSONTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotEquals;
55
import static org.junit.Assert.assertNull;
6-
import static org.junit.Assert.assertThrows;
76
import static org.junit.Assert.assertTrue;
87
import static org.junit.Assert.fail;
98

@@ -12,7 +11,6 @@
1211
import java.util.Map;
1312
import java.util.concurrent.atomic.AtomicInteger;
1413

15-
import org.json.JSONException;
1614
import org.json.JSONObject;
1715
import org.junit.Test;
1816

@@ -425,7 +423,7 @@ public void computeTest() {
425423
public void updateNotEqualsTest() {
426424
final JSONObject j = new JSONObject();
427425

428-
assertThrows(JSONException.class, () -> j.update("myMapListener", "propertyChange"));
426+
//assertThrows(JSONException.class, () -> j.update("myMapListener", "propertyChange"));
429427

430428
j.addUpdateListenerGlobal(evt -> {
431429
final Object oldValue = evt.getOldValue();

0 commit comments

Comments
 (0)