[CONJ-922] DECIMAL overflow for long/int/short not throwing exception Created: 2022-02-01  Updated: 2022-02-10  Resolved: 2022-02-10

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 3.0.3
Fix Version/s: 3.0.4

Type: Bug Priority: Major
Reporter: Ralf Wiebicke Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Linux


Attachments: Java Source File Test.java    

 Description   

Calling ResultSet.getLong on a column that contains a value larger than Long.MAX_VALUE should fail. Instead it wraps around to Long.MIN_VALUE.

The attached test case prints:

MySQL
8.0.27
MariaDB Connector/J
3.0.3
SUM = 9223372036854775807
SUM = -9223372036854775808

The second fetch should fail with some exception.

Replacing getLong by getInt and Long.MAX_VALUE by Integer.MAX_VALUE shows correct behaviour: the second fetch fails with "java.sql.SQLDataException: integer overflow".

This problem was not yet present in version 2.7.5.



 Comments   
Comment by Diego Dupin [ 2022-02-10 ]

corrected with commit https://github.com/mariadb-corporation/mariadb-connector-j/commit/a180c21f4fd870d3c64b7301c4e4cdb8c86d0659

overflow was not handled for DECIMAL value for short/int/long.

correction is available though snapshot:

 
<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>3.0.4-SNAPSHOT</version>
    </dependency>
</dependencies>

Generated at Thu Feb 08 03:19:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.