`CBORParser.getText(Writer)` writes stale text for numeric tokens, NPE for binary
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- backend-api-design
Research direction
Start by locating CBORParser.getText(Writer) and compare it with getText() and the suggested Smile fix in #835. Add regression coverage for numeric tokens and VALUE_EMBEDDED_OBJECT using the supplied reproduction, verifying writer output and returned lengths match the expected behavior without an exception.
Written by the indexing model from the issue text.
Description
Same problem as #835 (Smile), in CBORParser.getText(Writer):
- For numeric tokens, it writes the contents of
_textBuffer(or_sharedString). CBOR never decodes numbers into_textBuffer, so whatever text was last decoded gets written, usually the previous String value. The return value is that text's length. - For
VALUE_EMBEDDED_OBJECT(binary),t.asCharArray()returnsnull, sowriter.write(null)throwsNullPointerException.getText()returnsnullfor the same token.
getText() handles both cases correctly.
Reproduction
CBORFactory f = new CBORFactory();
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try (JsonGenerator g = f.createGenerator(bo)) {
g.writeStartArray();
g.writeString("abcdefghijklmnopqrstuvwxyz0123456789");
g.writeNumber(42);
g.writeNumber(1.25);
g.writeNumber(new BigInteger("123456789012345678901234567890"));
g.writeBinary(new byte[] { 1, 2, 3 });
g.writeEndArray();
}
try (JsonParser p = f.createParser(bo.toByteArray())) {
JsonToken t;
while ((t = p.nextToken()) != null) {
if (t.isScalarValue()) {
StringWriter w = new StringWriter();
int n = p.getText(w);
System.out.println(t + ": getText()=" + p.getText() + ", getText(Writer)=" + w + " (" + n + ")");
}
}
}
Observed (2.x; same code on 2.21), for both byte[] and InputStream input:
| Token | getText() |
getText(Writer) |
|---|---|---|
VALUE_STRING |
"abcdefghij..." |
"abcdefghij..." (36) |
VALUE_NUMBER_INT 42 |
"42" |
"abcdefghij..." (36) |
VALUE_NUMBER_FLOAT 1.25 |
"1.25" |
"abcdefghij..." (36) |
VALUE_NUMBER_INT (BigInteger) |
"1234567890..." |
"abcdefghij..." (36) |
VALUE_EMBEDDED_OBJECT |
null |
NullPointerException |
Suggested fix
As in #835: handle VALUE_STRING (and FIELD_NAME) directly, and fall back to super.getText(writer) for everything else. jackson-core's default goes through getText() and writes nothing for null.
- Dominant language
- Java
- Stars
- 348
- Forks
- 159
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 44
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FasterXML/jackson-dataformats-binary
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
FasterXML/jackson-dataformats-binary#790 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
FasterXML/jackson-dataformats-binary#789 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
FasterXML/jackson-dataformats-binary#788 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
FasterXML/jackson-dataformats-binary#766 ·
Maintainers usually reply within 1 day
-
protobuf
Difficulty 4/5 3-5 days Newbie friendliness 35/100
FasterXML/jackson-dataformats-binary#630 · 3 comments ·
Maintainers usually reply within 1 day
All issues in FasterXML/jackson-dataformats-binary
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
refinedmods/refinedstorage2#1421 ·
-
StepExamBenchmarkTest runs a loop and prints a timing but asserts nothingPossibly taken A pull request linked to this issue is open or already merged. Openjules
Difficulty 1/5 Under an hour Newbie friendliness 82/100
open-learning-exchange/myplanet#18199 · 1 comment ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Scheme-less stream URLs throw NullPointerException instead of URISyntaxExceptionPossibly taken @blihio claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
pedroSG94/RootEncoder#2218 ·
Maintainers usually reply within 3 days
-
[Bug] The producer summary calls a multi-group client a duplicatePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/rocketmq-dashboard#6872 ·
Maintainers usually reply within 3 days