Fix parsing of Geography coordinates with scientific notation #2819 - #2837
Merged
Divang Sharma (divang) merged 6 commits intoNov 26, 2025
Merged
Conversation
Very small coordinates that contain three or more zeros after the dot (like 0.000123) have a string representation of 1.23E-4. The readPointWkt did not account for this and set the end pos to the E, thus the BigDecimal tried to parse "1.23E". This resulted in a NumberFormatException. This fixes the issue by also allowing the minus sign when determining the end of the number.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2837 +/- ##
============================================
+ Coverage 56.33% 56.49% +0.16%
- Complexity 4516 4572 +56
============================================
Files 151 151
Lines 34431 34445 +14
Branches 5736 5741 +5
============================================
+ Hits 19397 19461 +64
+ Misses 12406 12405 -1
+ Partials 2628 2579 -49 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Ananya Garg (Ananya2)
previously approved these changes
Nov 18, 2025
Muskan Gupta (muskan124947)
previously approved these changes
Nov 18, 2025
- Only allow +/- signs after E/e in exponents (more precise validation) - Add comprehensive test coverage for edge cases - Test negative coords, small values, and both Geography/Geometry types
Divang Sharma (divang)
dismissed stale reviews from Muskan Gupta (muskan124947) and Ananya Garg (Ananya2)
via
November 19, 2025 12:24
afa8238
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
Author
|
Rerun CI pipeline was successfully - https://sqlclientdrivers.visualstudio.com/public/_build/results?buildId=130697&view=results |
…c notation with e/E and minus signs
…emove delta checks
Mahendra Chavan (machavan)
approved these changes
Nov 25, 2025
Muskan Gupta (muskan124947)
approved these changes
Nov 25, 2025
Ananya Garg (Ananya2)
approved these changes
Nov 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When creating Geography objects with very small coordinate values (e.g., 0.0001234), a NumberFormatException is thrown. This occurs because coordinates with three or more zeros after the decimal point are represented in scientific notation (e.g., "1.23E-4") when converted to strings.
Root Cause
The readPointWkt() method in SQLServerSpatialDatatype.java parses Well-Known Text (WKT) coordinate strings. The parsing loop that identifies the end position of a numeric value checks for digits, decimal points, and the exponent indicators 'E' and 'e', but does not account for the minus sign (-) that appears in negative exponents.
When parsing "1.23E-4", the loop terminates at the 'E' character instead of continuing through the full scientific notation. This causes BigDecimal to attempt parsing "1.23E" (an incomplete scientific notation), resulting in a NumberFormatException.
Solution
Added support for the minus sign (-) in the character validation loop within readPointWkt(). This allows the parser to correctly identify the complete scientific notation string including negative exponents.
Test
A new test case testGeographySmallCoordinates() has been added to verify that Geography objects can be created with small coordinate values that result in scientific notation.