flipkart-incubator / zjsonpatch

This is an implementation of RFC 6902 JSON Patch written in Java
Apache License 2.0
523 stars 149 forks source link

Number format exception on Map with key larger than Integer value #131

Open sparkym3 opened 3 years ago

sparkym3 commented 3 years ago

Expected Behavior

No exception thrown when patching. An easy fix may be to just update Integer.parseInt() calls to Long.parseLong() everywhere used.

Actual Behavior

NumberFormatException thrown.

Steps to Reproduce the Problem

On a map with a key that is numeric but larger than an Integer, attempt to generate a patch.

Specifications

On versions after 0.4.6, on the below line in JsonDiff, it calls into isArrayIndex() rather than doing the previous instanceOf check. Since there is no validation check that this is in fact an array or that it is an Integer it will fail. https://github.com/flipkart-incubator/zjsonpatch/blob/581a547e794290802e9d5a3377c69c303f069d4a/src/main/java/com/flipkart/zjsonpatch/JsonDiff.java#L291

Stack trace from 0.4.11 java.lang.NumberFormatException: For input string: "235234235616" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:583) at java.lang.Integer.parseInt(Integer.java:615) at com.flipkart.zjsonpatch.JsonPointer$RefToken.isArrayIndex(JsonPointer.java:302) at com.flipkart.zjsonpatch.JsonDiff.updatePath(JsonDiff.java:291) at com.flipkart.zjsonpatch.JsonDiff.computeRelativePath(JsonDiff.java:260) at com.flipkart.zjsonpatch.JsonDiff.introduceMoveOperation(JsonDiff.java:211) at com.flipkart.zjsonpatch.JsonDiff.asJson(JsonDiff.java:64) at com.flipkart.zjsonpatch.JsonDiff.asJson(JsonDiff.java:46)

Library Version:
Language (e.g. Java 1.8, Scala, etc): Java