Skip to content

Am I doing something wrong? #296

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

Closed
luigi-asprino opened this issue Mar 25, 2021 · 1 comment · Fixed by #243
Closed

Am I doing something wrong? #296

luigi-asprino opened this issue Mar 25, 2021 · 1 comment · Fixed by #243

Comments

@luigi-asprino
Copy link

Hi,

I noticed a weird behaviour in parsing numbers (specifically, 0).

package it.cnr.istc.stlab;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import com.jsoniter.JsonIterator;
import com.jsoniter.any.Any;
import com.jsoniter.output.EncodingMode;
import com.jsoniter.output.JsonStream;
import com.jsoniter.spi.DecodingMode;

public class Test {
	
	public static void main(String[] args) throws IOException {
		JsonIterator ij = JsonIterator.parse(new byte[1024]);
		ij.reset(new ByteArrayInputStream("[0]".getBytes()));
		JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
		JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
		ij.readArray();
		Any o = ij.readAny();
		System.out.println(o.toString());
		System.out.println(o.toInt());
		
	}

}

It throws an exception when it tries to transform o to integer.
Here is the stack trace

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by javassist.ClassPool (file:/Users/lgu/.m2/repository/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of javassist.ClassPool
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
0
Exception in thread "main" com.jsoniter.spi.JsonException: readByte: no more to read, head: 1, peek: 0, buf: 0
	at com.jsoniter.JsonIterator.reportError(JsonIterator.java:136)
	at com.jsoniter.IterImplForStreaming.readByte(IterImplForStreaming.java:307)
	at com.jsoniter.IterImplForStreaming.assertNotLeadingZero(IterImplForStreaming.java:619)
	at com.jsoniter.IterImplForStreaming.readLong(IterImplForStreaming.java:596)
	at com.jsoniter.IterImplNumber.readLong(IterImplNumber.java:96)
	at com.jsoniter.JsonIterator.readLong(JsonIterator.java:185)
	at com.jsoniter.any.LongLazyAny.fillCache(LongLazyAny.java:64)
	at com.jsoniter.any.LongLazyAny.toInt(LongLazyAny.java:38)
	at it.cnr.istc.stlab.Test.main(Test.java:22)

I'm not sure if I'm using the library correctly or not.

@svobol13
Copy link
Collaborator

Hi @luigi-asprino this bug is fixed in master. It is related to #243 and #301 .

@svobol13 svobol13 linked a pull request Jan 23, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants