From 6900fd587cffa5d94581ddab5e6911a3924b4d87 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 24 Dec 2018 18:15:56 +0300 Subject: [PATCH] Fix Float/Double.parse for strings like '123.' --- .../src/main/java/org/teavm/classlib/java/lang/TDouble.java | 5 +++-- .../src/main/java/org/teavm/classlib/java/lang/TFloat.java | 6 ++++-- .../test/java/org/teavm/classlib/java/lang/DoubleTest.java | 2 ++ .../test/java/org/teavm/classlib/java/lang/FloatTest.java | 2 ++ .../java/org/teavm/idea/devserver/TeaVMProcessHandler.java | 1 - 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java index 65cad8dba..80857e9b2 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java @@ -87,7 +87,9 @@ public class TDouble extends TNumber implements TComparable { long mantissa = 0; int exp = 0; + boolean hasOneDigit = false; if (c != '.') { + hasOneDigit = true; if (c < '0' || c > '9') { throw new TNumberFormatException(); } @@ -111,7 +113,6 @@ public class TDouble extends TNumber implements TComparable { } if (index < string.length() && string.charAt(index) == '.') { ++index; - boolean hasOneDigit = false; while (index < string.length()) { c = string.charAt(index); if (c < '0' || c > '9') { @@ -142,7 +143,7 @@ public class TDouble extends TNumber implements TComparable { ++index; } int numExp = 0; - boolean hasOneDigit = false; + hasOneDigit = false; while (index < string.length()) { c = string.charAt(index); if (c < '0' || c > '9') { diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java index 96fa205cf..fdfa6fc12 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java @@ -120,7 +120,10 @@ public class TFloat extends TNumber implements TComparable { int mantissa = 0; int exp = 0; + + boolean hasOneDigit = false; if (c != '.') { + hasOneDigit = true; if (c < '0' || c > '9') { throw new TNumberFormatException(); } @@ -146,7 +149,6 @@ public class TFloat extends TNumber implements TComparable { if (index < string.length() && string.charAt(index) == '.') { ++index; - boolean hasOneDigit = false; while (index < string.length()) { c = string.charAt(index); if (c < '0' || c > '9') { @@ -177,7 +179,7 @@ public class TFloat extends TNumber implements TComparable { ++index; } int numExp = 0; - boolean hasOneDigit = false; + hasOneDigit = false; while (index < string.length()) { c = string.charAt(index); if (c < '0' || c > '9') { diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java index 75d4aab04..24b858258 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/DoubleTest.java @@ -34,6 +34,8 @@ public class DoubleTest { assertEquals(23, Double.parseDouble("00230000e-4"), 1E-12); assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12); assertEquals(23, Double.parseDouble("2300000000000000000000e-20"), 1E-12); + assertEquals(23, Double.parseDouble("23."), 1E-12); + assertEquals(0.1, Double.parseDouble("0.1"), 0.001); assertEquals(0.1, Double.parseDouble(".1"), 0.001); } diff --git a/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java b/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java index 852da9cf4..37377f12e 100644 --- a/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/lang/FloatTest.java @@ -35,7 +35,9 @@ public class FloatTest { assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F); assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F); assertEquals(23, Float.parseFloat("2300000000000000000000e-20"), 1E-12F); + assertEquals(23, Float.parseFloat("23."), 1E-12F); assertEquals(0.1F, Float.parseFloat("0.1"), 0.001F); + assertEquals(0.1F, Float.parseFloat(".1"), 0.001F); } @Test diff --git a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMProcessHandler.java b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMProcessHandler.java index a82c30410..87ba1ffcc 100644 --- a/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMProcessHandler.java +++ b/tools/idea/plugin/src/main/java/org/teavm/idea/devserver/TeaVMProcessHandler.java @@ -37,7 +37,6 @@ class TeaVMProcessHandler extends ProcessHandler implements DevServerRunnerListe void start() throws IOException { info = DevServerRunner.start(DaemonUtil.detectClassPath().toArray(new String[0]), config, this); console.setServerManager(info.server); - startNotify(); Runtime.getRuntime().addShutdownHook(new Thread(() -> info.process.destroy())); }