Name: saf@russia Date: 09/04/96
This bug was found by St.Petersburg Java SQE team (by Mikhail Gorshenev).
The java.sql.Numeric(String s) constructor works wrong
if s contains two decimal points or a sign between digits
The java.sql specification (JDBC version 1.01) says the following:
"public Numeric(String s)
Creates a numeric from a string.
The string may contain a sign and a decimal point, e.g "-55.12".
Spaces and other non-numeric characters are ignored.
Scientific notation, i.e. mantissa with exponent (3E.05) is supported.
Parameters:
s - the string used to initialize the Numeric.
"
Here is the minimized test demonstrating the bug:
----- java_sql_Numeric_Ctor1.java ---------------------------------------
import java.sql.Numeric;
class java_sql_Numeric_Ctor1 {
public static void main(String argv[]) {
Numeric n1 = new Numeric("1-2");
// will print "-12" instead of "12"
System.out.println("Numeric(\\"1-2\\") = " + n1);
Numeric n2 = new Numeric("1.2.3");
// will print "12.3" instead of "1.23" (?)
System.out.println("Numeric(\\"1.2.3\\") = " + n2);
}
}
----- The output of the test: -------------------------
Numeric("1-2") = -12
Numeric("1.2.3") = 12.3
-------------------------------------------------------
Workaround:
None
======================================================================