pgjdbc: Query with integer overflow produces different exception after five times
I’m submitting a …
- bug report
- feature request
Describe the issue
Executing a query which produces integer overflow repeatedly will fail with a different exception, java.lang.ArithmeticException, after five times. The problem did not occur in driver version 42.2.11, but exist in the latest version (42.5.1).
Driver Version? 42.5.1
Java Version? 11
OS Version? Ubuntu Desktop 22.04
PostgreSQL Version? 14.5
To Reproduce
import org.junit.jupiter.api.Test;
import org.postgresql.util.PSQLException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import static org.junit.jupiter.api.Assertions.*;
class PostgresTest {
static final String DB_URL = ""; // TODO set DB URL here
static final String DB_USERNAME = ""; // TODO set DB user here
static final String DB_PASSWORD = ""; // TODO set DB password here
@Test
void testSelectIntegerOverflow() throws SQLException {
try (Connection connection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD)) {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE IF EXISTS IntegerOverflowTest;");
statement.execute("CREATE TABLE IntegerOverflowTest (a BIGINT NOT NULL);");
statement.execute("INSERT INTO IntegerOverflowTest (a) VALUES (9223372036854775807);");
statement.execute("INSERT INTO IntegerOverflowTest (a) VALUES (1);");
}
for (int i = 0; i < 100; i++) {
System.out.println("i = " + i);
try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT SUM(a) FROM IntegerOverflowTest;")) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
assertTrue(resultSet.next());
assertThrows(PSQLException.class, () -> resultSet.getLong(1));
assertFalse(resultSet.next());
}
}
}
}
}
}
Expected behaviour
It should throw same exception each time integer overflow occurs, but it switches from org.postgresql.util.PSQLException to java.lang.ArithmeticException after five times.
Logs Did not see anything about this in the Postgres server logs.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (12 by maintainers)
Commits related to this issue
- fix binary transfer floating point overflow https://github.com/pgjdbc/pgjdbc/issues/2696 — committed to bokken/pgjdbc by bokken 2 years ago
- fix binary transfer floating point overflow (#2710) * fix binary transfer floating point overflow https://github.com/pgjdbc/pgjdbc/issues/2696 for float4 and float8 only use BigDecimal for va... — committed to pgjdbc/pgjdbc by bokken a year ago
fixed with #2697