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

ArrayIndexOutOfBoundsException when deserializing certain double values #283

Open
eduard-vasinskyi opened this issue Jan 17, 2025 · 1 comment

Comments

@eduard-vasinskyi
Copy link

Hi. I have encountered ArrayIndexOutOfBoundsException when deserializing double values.
Here is a code that reproduces the problem:

public static void main(String[] args) throws IOException {
	double number = 2E15;

	DslJson<?> dslJson = new DslJson<>();
	JsonWriter jsonWriter = dslJson.newWriter();
	NumberConverter.serialize(number, jsonWriter);
	String string = jsonWriter.toString();

	System.out.println(string);
	System.out.println(number);

	JsonReader<?> jsonReader = dslJson.newReader();

	ByteArrayInputStream bais = new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8));
	jsonReader.process(bais);
	jsonReader.getNextToken();

	double deserialized = NumberConverter.deserializeDouble(jsonReader); 
	System.out.println(deserialized);
}

Here is the output:

2000000000000000.0
2.0E15
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at com.dslplatform.json.NumberConverter.approximateDouble(NumberConverter.java:519)
	at com.dslplatform.json.NumberConverter.parseDouble(NumberConverter.java:497)
	at com.dslplatform.json.NumberConverter.deserializeDouble(NumberConverter.java:398)
        ...

I got this error on dsl-json-java8 v1.10.0. But it is also reproducible in the current 'master' branch.
It also fails for numbers 3E15, 4E15, 5E15, 6E15, 7E15.
Originally, it failed on deserializing number 2670986322885633.0
Tested on Java 8 and 23

@zapov
Copy link
Member

zapov commented Feb 18, 2025

Tnx for the bug report. I will look into fixing it when I find some time (unless someone else provides a fix in the meantime)

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

2 participants