Skip to content

Spanner: OUT_OF_RANGE error when reading a FLOAT64 Infinity value as a Java float value. #2256

@lukaseder

Description

@lukaseder

Environment details

  1. OS type and version: Microsoft Windows [Version 10.0.26100.6584]
  2. Java version: openjdk version "21.0.2" 2024-01-16 LTS
  3. version(s): com.google.cloud:google-cloud-spanner-jdbc:2.33.0

Steps to reproduce

Read a FLOAT64 Infinity value as Java float value

Code example

Consider this reproducer: ```java try ( Statement s = connection.createStatement(); ResultSet rs = s.executeQuery("select cast('Infinity' as float32), cast('Infinity' as float64)") ) { while (rs.next()) { System.out.println(rs.getString(1)); System.out.println(rs.getDouble(1)); System.out.println(rs.getFloat(1)); System.out.println(rs.getString(2)); System.out.println(rs.getDouble(2)); System.out.println(rs.getFloat(2)); } }

It prints:

Infinity Infinity Infinity Infinity Infinity com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory$JdbcSqlExceptionImpl: OUT_OF_RANGE: Value out of range for float: Infinity	at com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.of(JdbcSqlExceptionFactory.java:247)	at com.google.cloud.spanner.jdbc.AbstractJdbcWrapper.checkedCastToFloat(AbstractJdbcWrapper.java:295)	at com.google.cloud.spanner.jdbc.JdbcResultSet.getFloat(JdbcResultSet.java:467)	at org.jooq.testscripts.JDBC.main(JDBC.java:49) 

Java itself doesn't have this issue. Both types' infinities can be cast to the other type correctly:

jshell> (double) Float.POSITIVE_INFINITY $1 ==> Infinity jshell> (float) Double.POSITIVE_INFINITY $2 ==> Infinity 

Stack trace

com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory$JdbcSqlExceptionImpl: OUT_OF_RANGE: Value out of range for float: Infinity	at com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.of(JdbcSqlExceptionFactory.java:247)	at com.google.cloud.spanner.jdbc.AbstractJdbcWrapper.checkedCastToFloat(AbstractJdbcWrapper.java:295)	at com.google.cloud.spanner.jdbc.JdbcResultSet.getFloat(JdbcResultSet.java:467)	at org.jooq.testscripts.JDBC.main(JDBC.java:49) 

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/java-spanner-jdbc API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions