Skip to content

Commit 64e25b2

Browse files
committed
review comments
1 parent 2ffce6e commit 64e25b2

File tree

4 files changed

+64
-36
lines changed

4 files changed

+64
-36
lines changed

src/main/java/com/fasterxml/jackson/core/io/NumberInput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public static double parseDouble(final String s, final boolean useFastParser) th
405405
* @param useFastParser whether to use {@code FastDoubleParser}
406406
* @return closest matching double
407407
* @throws NumberFormatException if value cannot be represented by a double
408-
* @since v2.18
408+
* @since 2.18
409409
*/
410410
public static double parseDouble(final char[] array, final boolean useFastParser) throws NumberFormatException {
411411
return parseDouble(array, 0, array.length, useFastParser);
@@ -418,7 +418,7 @@ public static double parseDouble(final char[] array, final boolean useFastParser
418418
* @param useFastParser whether to use {@code FastDoubleParser}
419419
* @return closest matching double
420420
* @throws NumberFormatException if value cannot be represented by a double
421-
* @since v2.18
421+
* @since 2.18
422422
*/
423423
public static double parseDouble(final char[] array, final int offset,
424424
final int len, final boolean useFastParser) throws NumberFormatException {
@@ -459,7 +459,7 @@ public static float parseFloat(final String s, final boolean useFastParser) thro
459459
* @param useFastParser whether to use {@code FastDoubleParser}
460460
* @return closest matching float
461461
* @throws NumberFormatException if value cannot be represented by a float
462-
* @since v2.18
462+
* @since 2.18
463463
*/
464464
public static float parseFloat(final char[] array, final boolean useFastParser) throws NumberFormatException {
465465
return parseFloat(array, 0, array.length, useFastParser);
@@ -472,7 +472,7 @@ public static float parseFloat(final char[] array, final boolean useFastParser)
472472
* @param useFastParser whether to use {@code FastDoubleParser}
473473
* @return closest matching float
474474
* @throws NumberFormatException if value cannot be represented by a float
475-
* @since v2.18
475+
* @since 2.18
476476
*/
477477
public static float parseFloat(final char[] array, final int offset,
478478
final int len, final boolean useFastParser) throws NumberFormatException {

src/main/java/com/fasterxml/jackson/core/util/ReadConstrainedTextBuffer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,4 @@ protected void validateStringLength(int length) throws StreamConstraintsExceptio
2626
{
2727
_streamReadConstraints.validateStringLength(length);
2828
}
29-
30-
/**
31-
* {@inheritDoc}
32-
*/
33-
@Override
34-
protected void validateFPLength(int length) throws StreamConstraintsException
35-
{
36-
_streamReadConstraints.validateFPLength(length);
37-
}
3829
}

src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ public double contentsAsDouble(final boolean useFastParser) throws NumberFormatE
539539
if (_resultString == null) {
540540
// Has array been requested? Can make a shortcut, if so:
541541
if (_resultArray != null) {
542-
validateFPLength(_resultArray.length);
543542
return NumberInput.parseDouble(_resultArray, useFastParser);
544543
} else {
545544
// Do we use shared array?
@@ -548,7 +547,6 @@ public double contentsAsDouble(final boolean useFastParser) throws NumberFormatE
548547
_resultString = "";
549548
throw new NumberFormatException("empty content");
550549
}
551-
validateFPLength(_inputLen);
552550
return NumberInput.parseDouble(_inputBuffer, _inputStart, _inputLen, useFastParser);
553551
} else { // nope... need to copy
554552
// But first, let's see if we have just one buffer
@@ -560,7 +558,6 @@ public double contentsAsDouble(final boolean useFastParser) throws NumberFormatE
560558
_resultString = "";
561559
throw new NumberFormatException("empty content");
562560
} else {
563-
validateFPLength(currLen);
564561
return NumberInput.parseDouble(_currentSegment, 0, currLen, useFastParser);
565562
}
566563
}
@@ -618,7 +615,6 @@ public float contentsAsFloat(final boolean useFastParser) throws NumberFormatExc
618615
if (_resultString == null) {
619616
// Has array been requested? Can make a shortcut, if so:
620617
if (_resultArray != null) {
621-
validateFPLength(_resultArray.length);
622618
return NumberInput.parseFloat(_resultArray, useFastParser);
623619
} else {
624620
// Do we use shared array?
@@ -627,7 +623,6 @@ public float contentsAsFloat(final boolean useFastParser) throws NumberFormatExc
627623
_resultString = "";
628624
throw new NumberFormatException("empty content");
629625
}
630-
validateFPLength(_inputLen);
631626
return NumberInput.parseFloat(_inputBuffer, _inputStart, _inputLen, useFastParser);
632627
} else { // nope... need to copy
633628
// But first, let's see if we have just one buffer
@@ -639,7 +634,6 @@ public float contentsAsFloat(final boolean useFastParser) throws NumberFormatExc
639634
_resultString = "";
640635
throw new NumberFormatException("empty content");
641636
} else {
642-
validateFPLength(currLen);
643637
return NumberInput.parseFloat(_currentSegment, 0, currLen, useFastParser);
644638
}
645639
}
@@ -1253,21 +1247,4 @@ protected void validateStringLength(int length) throws IOException
12531247
{
12541248
// no-op
12551249
}
1256-
1257-
/**
1258-
* Convenience method that can be used to verify that a number
1259-
* of specified length does not exceed maximum specific by this
1260-
* constraints object: if it does, a
1261-
* {@link JsonParseException}
1262-
* is thrown.
1263-
*
1264-
* @param length Length of number in input units
1265-
*
1266-
* @throws IOException If length exceeds maximum
1267-
* @since 2.15
1268-
*/
1269-
protected void validateFPLength(int length) throws IOException
1270-
{
1271-
// no-op
1272-
}
12731250
}

src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.jupiter.api.Test;
44

5+
import java.io.IOException;
6+
57
import static org.junit.jupiter.api.Assertions.*;
68

79
class TestTextBuffer
@@ -211,4 +213,62 @@ void getSizeFinishCurrentSegmentAndResetWith() throws Exception {
211213
assertEquals(2, textBuffer.size());
212214
}
213215

216+
public void testEmptyContentsAsFloat() {
217+
TextBuffer textBuffer = new TextBuffer(null);
218+
assertThrows(NumberFormatException.class, () -> {
219+
textBuffer.contentsAsFloat(false);
220+
});
221+
}
222+
223+
public void testEmptyContentsAsFloatFastParser() {
224+
TextBuffer textBuffer = new TextBuffer(null);
225+
assertThrows(NumberFormatException.class, () -> {
226+
textBuffer.contentsAsFloat(true);
227+
});
228+
}
229+
230+
public void testContentsAsFloat() throws IOException {
231+
TextBuffer textBuffer = new TextBuffer(null);
232+
textBuffer.resetWithString("1.2345678");
233+
assertEquals(1.2345678f, textBuffer.contentsAsFloat(false));
234+
}
235+
236+
public void testContentsAsFloatFastParser() throws IOException {
237+
TextBuffer textBuffer = new TextBuffer(null);
238+
textBuffer.resetWithString("1.2345678");
239+
assertEquals(1.2345678f, textBuffer.contentsAsFloat(true));
240+
}
241+
242+
public void testEmptyContentsAsDouble() {
243+
TextBuffer textBuffer = new TextBuffer(null);
244+
assertThrows(NumberFormatException.class, () -> {
245+
textBuffer.contentsAsDouble(false);
246+
});
247+
}
248+
249+
public void testEmptyContentsAsDoubleFastParser() {
250+
TextBuffer textBuffer = new TextBuffer(null);
251+
assertThrows(NumberFormatException.class, () -> {
252+
textBuffer.contentsAsDouble(true);
253+
});
254+
}
255+
256+
public void testContentsAsDouble() throws IOException {
257+
TextBuffer textBuffer = new TextBuffer(null);
258+
textBuffer.resetWithString("1.234567890123456789");
259+
assertEquals(1.234567890123456789d, textBuffer.contentsAsDouble(false));
260+
}
261+
262+
public void testContentsAsDoubleFastParser() throws IOException {
263+
TextBuffer textBuffer = new TextBuffer(null);
264+
textBuffer.resetWithString("1.234567890123456789");
265+
assertEquals(1.234567890123456789d, textBuffer.contentsAsDouble(true));
266+
}
267+
268+
public void testEmptyContentsAsDecimal() {
269+
TextBuffer textBuffer = new TextBuffer(null);
270+
assertThrows(NumberFormatException.class, () -> {
271+
textBuffer.contentsAsDecimal();
272+
});
273+
}
214274
}

0 commit comments

Comments
 (0)