Skip to content

Commit 5ccb155

Browse files
authored
Fix #1433: change Javadoc for JsonParser.getNumberType() (#1436)
1 parent 76c3a9c commit 5ccb155

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

release-notes/VERSION-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ a pure JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.18.5 (not yet released)
18+
19+
#1433: `JsonParser#getNumberType()` throws `JsonParseException` when
20+
the current token is non-numeric instead of returning null
21+
(reported by @CrazySqueak)
22+
1723
2.18.4 (06-May-2025)
1824

1925
No changes since 2.18.3

src/main/java/com/fasterxml/jackson/core/JsonParser.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,12 +1772,18 @@ public Object getNumberValueDeferred() throws IOException {
17721772
* If current token is of type
17731773
* {@link JsonToken#VALUE_NUMBER_INT} or
17741774
* {@link JsonToken#VALUE_NUMBER_FLOAT}, returns
1775-
* one of {@link NumberType} constants; otherwise returns {@code null}.
1775+
* one of {@link NumberType} constants; otherwise throws
1776+
* a {@link JsonParseException}.
1777+
*<p>
1778+
* NOTE: before 2.18 was documented to return {@code null} for non-numeric
1779+
* tokens, but this has never been the case.
17761780
*
1777-
* @return Type of current number, if parser points to numeric token; {@code null} otherwise
1781+
* @return Type of current number, if parser points to numeric token.
17781782
*
1779-
* @throws IOException for low-level read issues, or
1780-
* {@link JsonParseException} for decoding problems
1783+
* @throws IOException {@link JsonParseException} if
1784+
* the current token is not numeric, or if decoding of the value fails
1785+
* (invalid format for numbers); plain {@link IOException} if underlying
1786+
* content read fails (possible if numbers are decoded lazily).
17811787
*/
17821788
public abstract NumberType getNumberType() throws IOException;
17831789

0 commit comments

Comments
 (0)