Skip to content

Creating a Geography with very small coordinates causes a NumberFormatException #2820

@amuttsch

Description

@amuttsch

Driver version

12.10.1 & latest main branch

SQL Server version

2019 (but does not matter)

Client Operating System

macOS / Linux

JAVA/JVM version

Java 21

Table schema

Problem description

When creating a Geography object for a spacial column, the parsing of the values fail with an NumberFormatException when using very small coordinates that have 3 or more zeros after the decimal dot:

Geography g = Geography.point(0.0001234, 1.234, 4326);

Java converts this double value to the string 1.234E-4, which cannot be parsed correctly by SQLServerSpatialDatatype.readPointWkt. When iterating the wkt to find the end of the number, it does not take the - into account and tries to parse 1.234E only. BigDecimal cannot parse this and throws the exception.

Expected behavior

g should be instantiated correctly.

Actual behavior

The code crashed with a NumberFormatException.

Error message/stack trace

Any other details that can be helpful

I have already analysed and fixed the issue :) PR: #2819

JDBC trace logs

n/a

Metadata

Metadata

Assignees

Labels

Under ReviewUsed for pull requests under review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions