[JAVA-5265] Java driver throws exception for asNumber for BsonDecimal128 Created: 08/Dec/23 Updated: 03/Jan/24 Resolved: 03/Jan/24 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | 5.0.0 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Evan Darke | Assignee: | Jeffrey Yemin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Backwards Compatibility: | Minor Change | ||||
| Documentation Changes: | Needed | ||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||
| Description |
| Comments |
| Comment by Githook User [ 03/Jan/24 ] | ||||||||||||||
|
Author: {'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}Message: Improve BsonNumber support for Decimal128 (#1283)
Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com> | ||||||||||||||
| Comment by Evan Darke [ 12/Dec/23 ] | ||||||||||||||
|
jeff.yemin@mongodb.com I think 5.0.0 would be fine. We're already using JDK 11 and I don't think we rely on any deprecated APIs. | ||||||||||||||
| Comment by Jeffrey Yemin [ 08/Dec/23 ] | ||||||||||||||
|
We should also fix BsonDecimal128 implementation of Number interface. It should just be:
That will guard against Decimal128#bigDecimalValue throwing for NaN, Infinity, etc. | ||||||||||||||
| Comment by Jeffrey Yemin [ 08/Dec/23 ] | ||||||||||||||
|
This looks like a bug, and I can't think why the code was written the way it is. Even the first version of BsonValue, which didn't have Decimal128, has:
instead of just:
| ||||||||||||||
| Comment by Evan Darke [ 08/Dec/23 ] | ||||||||||||||
|
For context, Mongot relies on the Java driver and we're currently working on support for Decimal128 and mixed-type numeric comparisons. Luckily we discovered this behavior through unit tests, and we're working on replacing `value.asNumber()` with `((BsonNumber) value)` throughout our codebase. However, this seems like a really error-prone construct and we don't have a lot of tests using Decimal128, so I'm hoping we can get this patched at the driver level. |