Skip to content

Commit 9953b76

Browse files
Sean LearySean Leary
authored andcommitted
max-number-length-config sonarqube fixes
1 parent a28328c commit 9953b76

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎src/main/java/org/json/JSONObject.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,18 @@ static BigInteger objectToBigInteger(Object val, BigInteger defaultValue,
14841484
|| val instanceof Short || val instanceof Byte){
14851485
return BigInteger.valueOf(((Number) val).longValue());
14861486
}
1487+
return attemptConversionToBigInteger(val, defaultValue, maxNumberLength);
1488+
}
1489+
1490+
/**
1491+
* Convenience method to attempt conversion of value to BigInteger.
1492+
* Added to reduce complexity of objectToBigInteger()
1493+
* @param val the value to be converted
1494+
* @param defaultValue the default value to use if conversion is not attempted or fails
1495+
* @param maxNumberLength the max length allowed for BigIntegers
1496+
* @return the converted value, or the defaultValue
1497+
*/
1498+
private static BigInteger attemptConversionToBigInteger(Object val, BigInteger defaultValue, int maxNumberLength) {
14871499
// don't check if it's a string in case of unchecked Number subclasses
14881500
try {
14891501
/**
@@ -2799,7 +2811,7 @@ public static Object stringToValue(String string, JSONParserConfiguration jsonPa
27992811
jsonParserConfiguration = new JSONParserConfiguration();
28002812
}
28012813
// user declines max number checking
2802-
if (jsonParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
2814+
if (jsonParserConfiguration.getMaxNumberLength() == ParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
28032815
return stringToNumber(string);
28042816
}
28052817
if (string.length() <= jsonParserConfiguration.getMaxNumberLength()) {

‎src/main/java/org/json/ParserConfiguration.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public ParserConfiguration() {
5858
*
5959
* @param keepStrings A boolean indicating whether to preserve strings during parsing.
6060
* @param maxNestingDepth An integer representing the maximum allowed nesting depth.
61-
* @deprecated
61+
* @deprecated Use the with*() methods instead
6262
*/
63+
@Deprecated
6364
protected ParserConfiguration(final boolean keepStrings, final int maxNestingDepth) {
6465
this.keepStrings = keepStrings;
6566
this.maxNestingDepth = maxNestingDepth;

‎src/main/java/org/json/XML.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ public static Object stringToValue(String string, XMLParserConfiguration xmlPars
667667
if ((initial >= '0' && initial <= '9') || initial == '-') {
668668
try {
669669
// user declines max number checking
670-
if (xmlParserConfiguration.getMaxNumberLength() == JSONParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
670+
if (xmlParserConfiguration.getMaxNumberLength() == ParserConfiguration.UNDEFINED_MAXIMUM_NUMBER_LENGTH) {
671671
return stringToNumber(string);
672672
}
673673
if(string.length() <= xmlParserConfiguration.getMaxNumberLength()) {

0 commit comments

Comments
 (0)