Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Rubezhny2016-12-21 21:16:39 +0000
committerVictor Rubezhny2016-12-21 21:16:39 +0000
commit2c512f9f61b2d92b8ea3d25320a1197c95c3b052 (patch)
treef6bae6525118931d6796d669f635875219c3b20a /bundles
parent9af70b2bcc5fe73ecd5177682370919869f1400f (diff)
downloadwebtools.sourceediting-2c512f9f61b2d92b8ea3d25320a1197c95c3b052.tar.gz
webtools.sourceediting-2c512f9f61b2d92b8ea3d25320a1197c95c3b052.tar.xz
webtools.sourceediting-2c512f9f61b2d92b8ea3d25320a1197c95c3b052.zip
Bug 497261 - JSONEditor: NPE when working with an array of objects
Issue is fixed Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java23
-rw-r--r--bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelParser.java4
-rw-r--r--bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONStructureImpl.java33
3 files changed, 34 insertions, 26 deletions
diff --git a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java
index 28f8d9dc91..0ce7ada54c 100644
--- a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java
+++ b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelImpl.java
@@ -14,8 +14,6 @@
*******************************************************************************/
package org.eclipse.wst.json.core.internal.document;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.wst.json.core.contenttype.ContentTypeIdForJSON;
import org.eclipse.wst.json.core.document.IJSONArray;
import org.eclipse.wst.json.core.document.IJSONDocument;
import org.eclipse.wst.json.core.document.IJSONModel;
@@ -25,7 +23,6 @@ import org.eclipse.wst.json.core.document.IJSONPair;
import org.eclipse.wst.json.core.document.IJSONValue;
import org.eclipse.wst.json.core.internal.Logger;
import org.eclipse.wst.json.core.regions.JSONRegionContexts;
-import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
@@ -586,13 +583,21 @@ public class JSONModelImpl extends AbstractStructuredModel implements
}
}
if (!reloadModel && oldStructuredDocumentRegions != null && oldStructuredDocumentRegions.getLength() > 0) {
- // Reload all the model when the first region that will be
- // replaced is a JSONObject or if more than 3 regions are
- // replaced in the model (a JSONPair is composed by 3 regions,
- // this means more that one JSON Pair are replaced in the model)
- if (oldStructuredDocumentRegions.item(0).getType().equals(JSONRegionContexts.JSON_OBJECT_OPEN)
- || oldStructuredDocumentRegions.getLength() > 3)
+ if (oldStructuredDocumentRegions.getLength() > 3 || oldStructuredDocumentRegions.item(0).getType().equals(JSONRegionContexts.JSON_OBJECT_OPEN)) {
+ // Reload all the model when the first region that will be
+ // replaced is a JSONObject or if more than 3 regions are
+ // replaced in the model (a JSONPair is composed by 3 regions,
+ // this means more that one JSON Pair are replaced in the model)
+
reloadModel = true;
+ } else {
+ // also, always reload the model in case of removing at least one UNDEFINED region
+ for (int i = 0; !reloadModel && i < oldStructuredDocumentRegions.getLength(); i++) {
+ if (oldStructuredDocumentRegions.item(i).getType().equals(JSONRegionContexts.UNDEFINED)) {
+ reloadModel = true;
+ }
+ }
+ }
}
if(reloadModel) {
this.refresh = true;
diff --git a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelParser.java b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelParser.java
index 08948a4e60..421264dda9 100644
--- a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelParser.java
+++ b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONModelParser.java
@@ -93,7 +93,7 @@ public class JSONModelParser {
if(node.getNodeType() == IJSONNode.PAIR_NODE) {
JSONPairImpl pair = (JSONPairImpl) node;
pair.updateValue(value);
- } else if (isJSONValue(node.getFirstStructuredDocumentRegion().getType())) {
+ } else if (node.getFirstStructuredDocumentRegion() != null && isJSONValue(node.getFirstStructuredDocumentRegion().getType())) {
JSONValueImpl oldValue = (JSONValueImpl) node;
oldValue.updateValue(value);
} else if (node instanceof JSONArrayImpl) {
@@ -1765,7 +1765,7 @@ public class JSONModelParser {
}
}
- if(node instanceof JSONPairImpl && ((JSONPairImpl) node).getValue() == null) {
+ if(node instanceof JSONPairImpl && ((JSONPairImpl) node).getValue() != null) {
if(isJSONValue(startStructuredDocumentRegion.getType())) {
// This is a JSONPair and the flatNode might be the pair value
this.context.setCurrentNode(node);
diff --git a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONStructureImpl.java b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONStructureImpl.java
index 39a6a2edbd..5840d3f7f2 100644
--- a/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONStructureImpl.java
+++ b/bundles/org.eclipse.wst.json.core/src/org/eclipse/wst/json/core/internal/document/JSONStructureImpl.java
@@ -15,8 +15,8 @@
package org.eclipse.wst.json.core.internal.document;
import org.eclipse.wst.json.core.document.IJSONDocument;
-import org.eclipse.wst.json.core.document.IJSONStructure;
import org.eclipse.wst.json.core.document.IJSONNode;
+import org.eclipse.wst.json.core.document.IJSONStructure;
import org.eclipse.wst.json.core.document.JSONException;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
@@ -381,7 +381,7 @@ public abstract class JSONStructureImpl extends JSONValueImpl implements
public IJSONNode removeChild(IJSONNode oldChild) throws JSONException {
if (oldChild == null)
return null;
- if (oldChild.getParentNode() != this) {
+ if (oldChild.getParentNode() != null && oldChild.getParentNode() != this) {
// throw new JSONException(JSONException.NOT_FOUND_ERR,
// JSONMessages.NOT_FOUND_ERR);
throw new JSONException();
@@ -400,19 +400,22 @@ public abstract class JSONStructureImpl extends JSONValueImpl implements
}
JSONNodeImpl child = (JSONNodeImpl) oldChild;
- JSONNodeImpl prev = (JSONNodeImpl) child.getPreviousSibling();
- JSONNodeImpl next = (JSONNodeImpl) child.getNextSibling();
-
- // child.setEditable(true, true); // clear ReadOnly flags
-
- if (prev == null)
- this.firstChild = next;
- else
- prev.setNextSibling(next);
- if (next == null)
- this.lastChild = prev;
- else
- next.setPreviousSibling(prev);
+ if (oldChild.getParentNode() == this) {
+ JSONNodeImpl prev = (JSONNodeImpl) child.getPreviousSibling();
+ JSONNodeImpl next = (JSONNodeImpl) child.getNextSibling();
+
+ // child.setEditable(true, true); // clear ReadOnly flags
+
+ if (prev == null)
+ this.firstChild = next;
+ else
+ prev.setNextSibling(next);
+ if (next == null)
+ this.lastChild = prev;
+ else
+ next.setPreviousSibling(prev);
+ }
+
child.setPreviousSibling(null);
child.setNextSibling(null);
child.setParentNode(null);

Back to the top