diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java index cf5f5ea07..ef69c6885 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java @@ -5,6 +5,7 @@ import java.io.ObjectStreamException; import java.io.Serializable; +import java.math.BigInteger; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; @@ -426,15 +427,14 @@ private static boolean isAllDigits(String s) { int length = s.length(); // empty string doesn't count as a number + // string longer than "max number of digits in a long" cannot be parsed as a long if (length == 0) return false; for (int i = 0; i < length; ++i) { char c = s.charAt(i); - if (Character.isDigit(c)) - continue; - else + if (!Character.isDigit(c)) return false; } return true; @@ -449,7 +449,7 @@ public int compare(String a, String b) { boolean aDigits = isAllDigits(a); boolean bDigits = isAllDigits(b); if (aDigits && bDigits) { - return Integer.compare(Integer.parseInt(a), Integer.parseInt(b)); + return new BigInteger(a).compareTo(new BigInteger(b)); } else if (aDigits) { return -1; } else if (bDigits) { diff --git a/config/src/test/resources/test12.conf b/config/src/test/resources/test12.conf new file mode 100644 index 000000000..b7aff622b --- /dev/null +++ b/config/src/test/resources/test12.conf @@ -0,0 +1,43 @@ +// this checks sorting map keys, where keys that look like numbers are treated differently +// specifically tests very long numbers which fit neither in an Integer nor in a Long + +"10" = "42" +sth = 42 +"1" = "42" +"12" = "42" +"123" = "42" +"1234" = "42" +"12345" = "42" +"123456" = "42" +"1234567" = "42" +"12345678" = "42" +"123456789" = "42" +"1234567890" = "42" +"12345678901" = "42" +"123456789012" = "42" +"1234567890123" = "42" +"12345678901234" = "42" +"123456789012345" = "42" +"1234567890123456" = "42" +"12345678901234567" = "42" +"123456789012345678" = "42" +"1234567890123456789" = "42" +"12345678901234567891" = "42" +"123456789012345678912" = "42" +"1234567890123456789123" = "42" +"12345678901234567891234" = "42" +"123456789012345678912345" = "42" +"1234567890123456789123456" = "42" +"12345678901234567891234567" = "42" +"123456789012345678912345678" = "42" +"1234567890123456789123456789" = "42" +"12345678901234567891234567890" = "42" +"123456789012345678912345678901" = "42" +"1234567890123456789123456789012" = "42" +"12345678901234567891234567890123" = "42" +"123456789012345678912345678901234" = "42" +"1234567890123456789123456789012345" = "42" +"12345678901234567891234567890123456" = "42" +"123456789012345678912345678901234567" = "42" +"1234567890123456789123456789012345678" = "42" +"12345678901234567891234567890123456789" = "42" \ No newline at end of file diff --git a/config/src/test/scala/Rendering.scala b/config/src/test/scala/Rendering.scala index 0d8be469e..e1ca3cf6d 100644 --- a/config/src/test/scala/Rendering.scala +++ b/config/src/test/scala/Rendering.scala @@ -33,6 +33,7 @@ object RenderExample extends App { render("test01") render("test06") render("test05") + render("test12") } object RenderOptions extends App { diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala index db593f1de..de97288c3 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigValueTest.scala @@ -982,8 +982,8 @@ class ConfigValueTest extends TestUtils { @Test def renderSorting(): Unit = { - val config = parseConfig("""0=a,1=b,2=c,3=d,10=e,20=f,30=g""") + val config = parseConfig("""0=a,1=b,2=c,999999999999999999999999999999999999999999999=0,3=d,10=e,20a=f,20=g,30=h""") val rendered = config.root.render(ConfigRenderOptions.concise()) - assertEquals("""{"0":"a","1":"b","2":"c","3":"d","10":"e","20":"f","30":"g"}""", rendered) + assertEquals("""{"0":"a","1":"b","2":"c","3":"d","10":"e","20":"g","30":"h","999999999999999999999999999999999999999999999":0,"20a":"f"}""", rendered) } }