[JAVA-529] NumberFormatException parsing should provide exception subclass or better descriptions Created: 06/Mar/12 Updated: 03/Feb/16 Resolved: 28/Mar/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 2.7.3 |
| Fix Version/s: | 2.8.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Jared D. Cottrell | Assignee: | Bryan Reinero |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Java 6 on Mac OS X 10.7.3 (Lion) |
||
| Backwards Compatibility: | Minor Change |
| Description |
|
When trying to JSON.parse() the following String, we get a NumberFormatException. Presumably this is because the number is larger than java.lang.Long.MAX_VALUE. { , java.lang.NumberFormatException: For input string: "109997115319321890123" |
| Comments |
| Comment by Jeffrey Yemin [ 03/Feb/16 ] |
|
aleksey.korolev This issue is closed, so we won't be doing anything further with it. As what you're asking for seems to be a feature request, please open a new issue if you'd like to see it addressed. But before you do that, please consider:
|
| Comment by Aleksey Korolev [ 03/Feb/16 ] |
|
Just caught this exception on MongoDB 3.2 when the number was too big for java.lang.Long and behavior was unexpected for me. |
| Comment by Jeffrey Yemin [ 18/Jun/12 ] |
|
Closing for 2.8.0 release. |
| Comment by Bryan Reinero [ 28/Mar/12 ] |
|
This change may impact applications which have been coded explicitly to catch NumberFormatExceptions. These applications should instead catch JSONParseExceptions. |
| Comment by auto [ 28/Mar/12 ] |
|
Author: {u'login': u'breinero', u'name': u'Bryan Reinero', u'email': u'bryan.reinero@10gen.com'}Message: Jira ticket; |
| Comment by Jeffrey Yemin [ 06/Mar/12 ] |
|
How about we wrap the NumberFormatException in a com.mongodb.util.JSONParseException, which already exists and is thrown for other parsing errors. |
| Comment by Scott Hernandez (Inactive) [ 06/Mar/12 ] |
|
All numbers in javascript are fp (64bit) by default. NumberLong is what you want if you want a signed int (64bit). |
| Comment by Jared D. Cottrell [ 06/Mar/12 ] |
|
Though there does seem to be some inconsistency with how the shell behaves. It will take the number without error, but rounds it. I assume it's turning it into a floating point number. > db.stuff.save( {"foo": 109997115319321890123}) |
| Comment by Jared D. Cottrell [ 06/Mar/12 ] |
|
It would be helpful to have descriptive text as well as an Exception subclass that can reliably be filtered on to pull out user-readable messages. So, one solution might be to throw InvalidJsonExceptions where the message can be counted on to be clean and in this case might say, "The number \"109997115319321890123\" is too large to be stored." |
| Comment by Scott Hernandez (Inactive) [ 06/Mar/12 ] |
|
How would you like this to be handled? An error the number is too long and can't be stored? Or invalid? |