max-number-length-config sonarqube fixes
This commit is contained in:
@@ -1484,6 +1484,18 @@ public class JSONObject {
|
||||
|| val instanceof Short || val instanceof Byte){
|
||||
return BigInteger.valueOf(((Number) val).longValue());
|
||||
}
|
||||
return attemptConversionToBigInteger(val, defaultValue, maxNumberLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to attempt conversion of value to BigInteger.
|
||||
* Added to reduce complexity of objectToBigInteger()
|
||||
* @param val the value to be converted
|
||||
* @param defaultValue the default value to use if conversion is not attempted or fails
|
||||
* @param maxNumberLength the max length allowed for BigIntegers
|
||||
* @return the converted value, or the defaultValue
|
||||
*/
|
||||
private static BigInteger attemptConversionToBigInteger(Object val, BigInteger defaultValue, int maxNumberLength) {
|
||||
// don't check if it's a string in case of unchecked Number subclasses
|
||||
try {
|
||||
/**
|
||||
@@ -2799,7 +2811,7 @@ public class JSONObject {
|
||||
jsonParserConfiguration = new JSONParserConfiguration();
|
||||
}
|
||||
// user declines max number checking
|
||||
if (jsonParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
|
||||
if (jsonParserConfiguration.getMaxNumberLength() == ParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
|
||||
return stringToNumber(string);
|
||||
}
|
||||
if (string.length() <= jsonParserConfiguration.getMaxNumberLength()) {
|
||||
|
||||
@@ -58,8 +58,9 @@ public class ParserConfiguration {
|
||||
*
|
||||
* @param keepStrings A boolean indicating whether to preserve strings during parsing.
|
||||
* @param maxNestingDepth An integer representing the maximum allowed nesting depth.
|
||||
* @deprecated
|
||||
* @deprecated Use the with*() methods instead
|
||||
*/
|
||||
@Deprecated
|
||||
protected ParserConfiguration(final boolean keepStrings, final int maxNestingDepth) {
|
||||
this.keepStrings = keepStrings;
|
||||
this.maxNestingDepth = maxNestingDepth;
|
||||
|
||||
@@ -667,7 +667,7 @@ public class XML {
|
||||
if ((initial >= '0' && initial <= '9') || initial == '-') {
|
||||
try {
|
||||
// user declines max number checking
|
||||
if (xmlParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
|
||||
if (xmlParserConfiguration.getMaxNumberLength() == ParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
|
||||
return stringToNumber(string);
|
||||
}
|
||||
if(string.length() <= xmlParserConfiguration.getMaxNumberLength()) {
|
||||
|
||||
Reference in New Issue
Block a user