Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

JSONLexerBase类中存在bug #2628

@biticcf

Description

@biticcf

发现bug的版本:1.2.58
涉及到得类:JSONLexerBase
涉及到的方法:
public BigInteger scanFieldBigInteger(char[] fieldName) { .... }
涉及到的代码段:
if (count < 20 || (negative && count < 21)) { value = BigInteger.valueOf(negative ? -intVal : intVal); }

Bug复现:
`
public static void main(String[] args) {
long MAX_LONG = Long.MAX_VALUE; //9223372036854775807
long MIN_LONG = Long.MIN_VALUE; //-9223372036854775808

	String s1 = "9423372036854775807"; //-9423372036854775808
	BigInteger bi1 = JSON.parseObject(s1, BigInteger.class); //没问题
	System.out.println("bi1 = " + bi1);
	
	BigInteger bi2 = new BigInteger(s1); //没问题
	System.out.println("bi2 = " + bi2);
	
	Tobject tobj1 = new Tobject();
	tobj1.setBi(bi2); //没问题
	System.out.println("bi3 = " + tobj1.getBi());
	
	String s2 = JSON.toJSONString(tobj1);
	Tobject tobj2 = JSON.parseObject(s2, Tobject.class);  //有问题
	System.out.println("bi4 = " + tobj2.getBi());
}

static class Tobject {
	private BigInteger bi;
	
	public BigInteger getBi() {
		return bi;
	}
	public void setBi(BigInteger bi) {
		this.bi = bi;
	}
}

`

会出现bug的情况:
[9223372036854775808, 10000000000000000000)和(-10000000000000000000,9223372036854775809]这些数值在作为间接对象的时候,如果用JSON.parseObject(...)转化出来的结果是有bug的。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions