diff --git a/build.gradle b/build.gradle index 8ffa1a34..39960a15 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { repositories { mavenCentral() maven { - url "http://repo.springsource.org/plugins-release"; + url "https://repo.springsource.org/plugins-release"; } } dependencies { @@ -31,7 +31,7 @@ buildscript { }; plugins { - id("net.ltgt.errorprone") version "0.8.1" apply false + id("net.ltgt.errorprone") version "1.3.0" apply false } configure(allprojects) { diff --git a/src/main/java/com/github/fge/jsonpatch/AddOperation.java b/src/main/java/com/github/fge/jsonpatch/AddOperation.java index 5e5fb57a..2b104fde 100644 --- a/src/main/java/com/github/fge/jsonpatch/AddOperation.java +++ b/src/main/java/com/github/fge/jsonpatch/AddOperation.java @@ -91,11 +91,20 @@ public JsonNode apply(final JsonNode node) */ final JsonNode parentNode = path.parent().path(node); if (parentNode.isMissingNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.noSuchParent")); - if (!parentNode.isContainerNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.parentNotContainer")); + { + String msg = BUNDLE.getMessage("jsonPatch.noSuchParent"); + if(node!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } + if (!parentNode.isContainerNode()) { + String msg = BUNDLE.getMessage("jsonPatch.parentNotContainer"); + if(node!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } return parentNode.isArray() ? addToArray(path, node) : addToObject(path, node); @@ -119,12 +128,12 @@ private JsonNode addToArray(final JsonPointer path, final JsonNode node) try { index = Integer.parseInt(token.toString()); } catch (NumberFormatException ignored) { - throw new JsonPatchException(BUNDLE.getMessage( + throw new JsonPatchException("[] " + BUNDLE.getMessage( "jsonPatch.notAnIndex")); } if (index < 0 || index > size) - throw new JsonPatchException(BUNDLE.getMessage( + throw new JsonPatchException(node.toString() + " " + BUNDLE.getMessage( "jsonPatch.noSuchIndex")); target.insert(index, value); diff --git a/src/main/java/com/github/fge/jsonpatch/CopyOperation.java b/src/main/java/com/github/fge/jsonpatch/CopyOperation.java index 9a5a75b9..5e5e8f5d 100644 --- a/src/main/java/com/github/fge/jsonpatch/CopyOperation.java +++ b/src/main/java/com/github/fge/jsonpatch/CopyOperation.java @@ -55,9 +55,13 @@ public JsonNode apply(final JsonNode node) throws JsonPatchException { final JsonNode dupData = from.path(node).deepCopy(); - if (dupData.isMissingNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.noSuchPath")); + if(dupData.isMissingNode()){ + String msg = BUNDLE.getMessage("jsonPatch.noSuchPath"); + if(dupData!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } return new AddOperation(path, dupData).apply(node); } } diff --git a/src/main/java/com/github/fge/jsonpatch/MoveOperation.java b/src/main/java/com/github/fge/jsonpatch/MoveOperation.java index 405b737c..b09e7add 100644 --- a/src/main/java/com/github/fge/jsonpatch/MoveOperation.java +++ b/src/main/java/com/github/fge/jsonpatch/MoveOperation.java @@ -79,11 +79,33 @@ public JsonNode apply(final JsonNode node) if (from.equals(path)) return node.deepCopy(); final JsonNode movedNode = from.path(node); - if (movedNode.isMissingNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.noSuchPath")); + if (movedNode.isMissingNode()) { + String msg = BUNDLE.getMessage("jsonPatch.noSuchPath"); + if(node!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } final JsonPatchOperation remove = new RemoveOperation(from); final JsonPatchOperation add = new AddOperation(path, movedNode); - return add.apply(remove.apply(node)); + JsonNode returnNode = null; + try { + returnNode = add.apply(remove.apply(node)); + } + catch(JsonPatchException jpe) + { + String msg = BUNDLE.getMessage("jsonPatch.noSuchParent"); + if(jpe.getMessage().contains(msg)) + { + // Rethrow the JsonPatchException with a new message + msg = node.toString() + " " + msg; + throw new JsonPatchException(msg); + } + else + { + throw jpe; + } + } + return returnNode; } } diff --git a/src/main/java/com/github/fge/jsonpatch/RemoveOperation.java b/src/main/java/com/github/fge/jsonpatch/RemoveOperation.java index 4c528baa..c03436f9 100644 --- a/src/main/java/com/github/fge/jsonpatch/RemoveOperation.java +++ b/src/main/java/com/github/fge/jsonpatch/RemoveOperation.java @@ -55,8 +55,13 @@ public JsonNode apply(final JsonNode node) if (path.isEmpty()) return MissingNode.getInstance(); if (path.path(node).isMissingNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.noSuchPath")); + { + String msg = BUNDLE.getMessage("jsonPatch.noSuchPath"); + if(node!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } final JsonNode ret = node.deepCopy(); final JsonNode parentNode = path.parent().get(ret); final String raw = Iterables.getLast(path).getToken().getRaw(); diff --git a/src/main/java/com/github/fge/jsonpatch/ReplaceOperation.java b/src/main/java/com/github/fge/jsonpatch/ReplaceOperation.java index d4454bdb..72be6663 100644 --- a/src/main/java/com/github/fge/jsonpatch/ReplaceOperation.java +++ b/src/main/java/com/github/fge/jsonpatch/ReplaceOperation.java @@ -62,9 +62,13 @@ public JsonNode apply(final JsonNode node) * If remove is done first, the array is empty and add rightly complains * that there is no such index in the array. */ - if (path.path(node).isMissingNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.noSuchPath")); + if (path.path(node).isMissingNode()) { + String msg = BUNDLE.getMessage("jsonPatch.noSuchPath"); + if(node!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } final JsonNode replacement = value.deepCopy(); if (path.isEmpty()) return replacement; diff --git a/src/main/java/com/github/fge/jsonpatch/TestOperation.java b/src/main/java/com/github/fge/jsonpatch/TestOperation.java index 90f03401..c5794ade 100644 --- a/src/main/java/com/github/fge/jsonpatch/TestOperation.java +++ b/src/main/java/com/github/fge/jsonpatch/TestOperation.java @@ -56,11 +56,15 @@ public JsonNode apply(final JsonNode node) throws JsonPatchException { final JsonNode tested = path.path(node); - if (tested.isMissingNode()) - throw new JsonPatchException(BUNDLE.getMessage( - "jsonPatch.noSuchPath")); + if (tested.isMissingNode()) { + String msg = BUNDLE.getMessage("jsonPatch.noSuchPath"); + if(node!=null) { + msg = node.toString() + " " + msg; + } + throw new JsonPatchException(msg); + } if (!EQUIVALENCE.equivalent(tested, value)) - throw new JsonPatchException(BUNDLE.getMessage( + throw new JsonPatchException(node.toString() + " " + BUNDLE.getMessage( "jsonPatch.valueTestFailure")); return node.deepCopy(); } diff --git a/src/test/java/com/github/fge/jsonpatch/JsonPatchOperationTest.java b/src/test/java/com/github/fge/jsonpatch/JsonPatchOperationTest.java index 5f04d811..90b98c95 100644 --- a/src/test/java/com/github/fge/jsonpatch/JsonPatchOperationTest.java +++ b/src/test/java/com/github/fge/jsonpatch/JsonPatchOperationTest.java @@ -81,12 +81,15 @@ public final void errorsAreCorrectlyReported(final JsonNode patch, throws IOException { final JsonPatchOperation op = reader.readValue(patch); - try { op.apply(node); fail("No exception thrown!!"); } catch (JsonPatchException e) { - assertEquals(e.getMessage(), message); + String msg = message; + if(node!=null) { + msg = node.toString() + " " + msg; + } + assertEquals(e.getMessage(), msg); } }