Skip to content

Commit e01cbd8

Browse files
committed
Try to repro FasterXML#181 on 2.4 but passes as well
1 parent 41bbcd8 commit e01cbd8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/test/java/com/fasterxml/jackson/core/json/TestNumericValues.java

+56
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,48 @@ private void _testIssue160LongNumbers(JsonFactory f, String doc, boolean useStre
473473
assertEquals(doc, v.toString());
474474
}
475475

476+
// for [jackson-core#181]
477+
/**
478+
* Method that tries to test that number parsing works in cases where
479+
* input is split between buffer boundaries.
480+
*/
481+
public void testParsingOfLongerSequencesWithNonNumeric() throws Exception
482+
{
483+
JsonFactory factory = new JsonFactory();
484+
factory.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS);
485+
double[] values = new double[] {
486+
0.01, -10.5, 2.1e9, 4.0e-8,
487+
Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY
488+
};
489+
for (int i = 0; i < values.length; ++i) {
490+
int COUNT = 4096;
491+
// Don't see the failure with a multiple of 1
492+
int VCOUNT = 2 * COUNT;
493+
String arrayJson = toJsonArray(values[i], VCOUNT);
494+
StringBuilder sb = new StringBuilder(COUNT + arrayJson.length() + 20);
495+
for (int j = 0; j < COUNT; ++j) {
496+
sb.append(' ');
497+
}
498+
sb.append(arrayJson);
499+
String DOC = sb.toString();
500+
for (int input = 0; input < 2; ++input) {
501+
JsonParser jp;
502+
if (input == 0) {
503+
jp = createParserUsingStream(factory, DOC, "UTF-8");
504+
} else {
505+
jp = factory.createParser(DOC);
506+
}
507+
assertToken(JsonToken.START_ARRAY, jp.nextToken());
508+
for (int j = 0; j < VCOUNT; ++j) {
509+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, jp.nextToken());
510+
assertEquals(values[i], jp.getDoubleValue());
511+
}
512+
assertToken(JsonToken.END_ARRAY, jp.nextToken());
513+
jp.close();
514+
}
515+
}
516+
}
517+
476518
/*
477519
/**********************************************************
478520
/* Tests for invalid access
@@ -506,4 +548,18 @@ public void testInvalidIntAccess() throws Exception
506548
}
507549
jp.close();
508550
}
551+
552+
/*
553+
/**********************************************************
554+
/* Helper methods
555+
/**********************************************************
556+
*/
557+
558+
private String toJsonArray(double v, int n) {
559+
StringBuilder sb = new StringBuilder().append('[').append(v);
560+
for (int i = 1; i < n; ++i) {
561+
sb.append(',').append(v);
562+
}
563+
return sb.append(']').toString();
564+
}
509565
}

0 commit comments

Comments
 (0)