RFR: 8261290: Improve error message for NumberFormatException on null input

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

RFR: 8261290: Improve error message for NumberFormatException on null input

Joe Darcy-2
In Integer and Long, several of the parsing methods are specified to throw NumberFormatException on a null input rather than an NPE. That behavior is not proposed to be modified. However, I think it is reasonable for the NumberFormatException to have a more informative error message than just "null" -- specifically "Cannot parse null string" is proposed here.

All four prior occurrences of

throw new NumberFormatException("null")

have be updated; there were no other instances of this idiom in the java.lang package.

All java/lang/{Integer, Long} regression tests pass with this change.

-------------

Commit messages:
 - Initial commit.

Changes: https://git.openjdk.java.net/jdk/pull/2663/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2663&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8261290
  Stats: 6 lines in 2 files changed: 0 ins; 0 del; 6 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2663.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2663/head:pull/2663

PR: https://git.openjdk.java.net/jdk/pull/2663
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8261290: Improve error message for NumberFormatException on null input

Attila Szegedi-3
On Sat, 20 Feb 2021 21:44:12 GMT, Joe Darcy <[hidden email]> wrote:

> In Integer and Long, several of the parsing methods are specified to throw NumberFormatException on a null input rather than an NPE. That behavior is not proposed to be modified. However, I think it is reasonable for the NumberFormatException to have a more informative error message than just "null" -- specifically "Cannot parse null string" is proposed here.
>
> All four prior occurrences of
>
> throw new NumberFormatException("null")
>
> have be updated; there were no other instances of this idiom in the java.lang package.
>
> All java/lang/{Integer, Long} regression tests pass with this change.

Rather straightforward 👍

-------------

Marked as reviewed by attila (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/2663
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8261290: Improve error message for NumberFormatException on null input

Alan Bateman-2
In reply to this post by Joe Darcy-2
On Sat, 20 Feb 2021 21:44:12 GMT, Joe Darcy <[hidden email]> wrote:

> In Integer and Long, several of the parsing methods are specified to throw NumberFormatException on a null input rather than an NPE. That behavior is not proposed to be modified. However, I think it is reasonable for the NumberFormatException to have a more informative error message than just "null" -- specifically "Cannot parse null string" is proposed here.
>
> All four prior occurrences of
>
> throw new NumberFormatException("null")
>
> have be updated; there were no other instances of this idiom in the java.lang package.
>
> All java/lang/{Integer, Long} regression tests pass with this change.

Marked as reviewed by alanb (Reviewer).

-------------

PR: https://git.openjdk.java.net/jdk/pull/2663
Reply | Threaded
Open this post in threaded view
|

Integrated: 8261290: Improve error message for NumberFormatException on null input

Joe Darcy-2
In reply to this post by Joe Darcy-2
On Sat, 20 Feb 2021 21:44:12 GMT, Joe Darcy <[hidden email]> wrote:

> In Integer and Long, several of the parsing methods are specified to throw NumberFormatException on a null input rather than an NPE. That behavior is not proposed to be modified. However, I think it is reasonable for the NumberFormatException to have a more informative error message than just "null" -- specifically "Cannot parse null string" is proposed here.
>
> All four prior occurrences of
>
> throw new NumberFormatException("null")
>
> have be updated; there were no other instances of this idiom in the java.lang package.
>
> All java/lang/{Integer, Long} regression tests pass with this change.

This pull request has now been integrated.

Changeset: 564011cf
Author:    Joe Darcy <[hidden email]>
URL:       https://git.openjdk.java.net/jdk/commit/564011cf
Stats:     6 lines in 2 files changed: 0 ins; 0 del; 6 mod

8261290: Improve error message for NumberFormatException on null input

Reviewed-by: attila, alanb

-------------

PR: https://git.openjdk.java.net/jdk/pull/2663