Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sparkym3 opened this issue Apr 6, 2021 · 0 comments
Open

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

sparkym3 opened this issue Apr 6, 2021 · 0 comments

Comments

@sparkym3
Copy link

sparkym3 commented Apr 6, 2021

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.

if (pseudo.getPath().get(pseudo.getPath().size() - 1).isArrayIndex()) {

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant