Description:
MySQL Server: 8.0.36
Driver Name & Ver: MySQL Connector/Jmysql-connector-j-8.0.33 (Revision: 7d6b0800528b6b25c68b52dc10d6c1c8429c100c)
Exception is thrown in Java with the following testcase generated from SQLancer.
DROP DATABASE IF EXISTS database3;
CREATE DATABASE database3;
USE database3;
CREATE TABLE IF NOT EXISTS t0(c0 FLOAT ZEROFILL);
INSERT INTO t0(c0) VALUES("-0");
SELECT t0.c0 FROM t0; --0000000000-0
Seems to be a parsing error of "0000000000-0" returned due to a column with ZEROFILL and a negative 0
Stack trace:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0000000000-0"
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.base/java.lang.Double.parseDouble(Double.java:651)
at com.mysql.cj.protocol.a.MysqlTextValueDecoder.getDouble(MysqlTextValueDecoder.java:249)
at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeDouble(MysqlTextValueDecoder.java:134)
at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeFloat(MysqlTextValueDecoder.java:130)
at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:116)
at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:243)
at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91)
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:883)
at Main.main(Main.java:19)
How to repeat:
Reproducible with this java code
import java.sql.*;
public class Main {
public static void main(String[] args) throws Exception {
try (Connection con = getMySqlConnection()) {
Statement statement = con.createStatement();
statement.execute("DROP DATABASE IF EXISTS database3;");
statement.execute("CREATE DATABASE database3;");
statement.execute("USE database3;");
statement.execute("CREATE TABLE IF NOT EXISTS t0(c0 FLOAT ZEROFILL);");
statement.execute("INSERT INTO t0(c0) VALUES(\"-0\");");
ResultSet result = statement.executeQuery("SELECT t0.c0 FROM t0;");
result.next();
System.out.println(result.getString(1));
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getMySqlConnection() throws Exception {
String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://localhost/databaseconnectiontest?user=root&password=root&rewriteBatchStatements=true";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url);
DatabaseMetaData meta = conn.getMetaData();
System.out.println("MySQL Server: " + meta.getDatabaseProductVersion());
System.out.println("Driver Name & Ver: " + meta.getDriverName() + meta.getDriverVersion());
return conn;
}
}