Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`ValueEncoderFactory.getScalarEncoder()` fails for values longer than 64 chars

Closed Beginner friendly
#41 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
api, backend

Research direction

Start by locating ValueEncoderFactory.getScalarEncoder(), AsciiValueEncoder.MIN_CHARS_WITHOUT_FLUSH, and StringEncoder.encodeMore(char[], ...). Review the encoder paths for values over 64 characters, then verify that long BigInteger and BigDecimal values work for both char[] and byte[] output, including cases where the remaining buffer is too small.

Written by the indexing model from the issue text.

Description

Note: I can also provide a unit test, but since the repository doesn't seem to have any test infrastructure, I'm not sure what to do with it.

Summary

ValueEncoderFactory.getScalarEncoder(String) chooses the wrong encoder. Values longer than AsciiValueEncoder.MIN_CHARS_WITHOUT_FLUSH (64) get TokenEncoder, which writes the whole value in one call and ignores the end of the buffer. When such a value doesn't fit in the space left in the output buffer, encoding throws StringIndexOutOfBoundsException (char[] output) or ArrayIndexOutOfBoundsException (byte[] output).

A second bug was hidden behind the first: StringEncoder.encodeMore(char[], ...) passes a length to String.getChars() where an end index is expected, so any output after the first chunk is wrong or throws.

Both bugs date back to the initial import.

Impact

Woodstox uses this encoder for writeInteger(BigInteger), writeDecimal(BigDecimal) and their attribute variants. Writing a value whose toString() is longer than 64 characters fails whenever the writer's buffer has at least 64 characters free but not enough for the whole value. That depends on what was written before, so the failure looks intermittent. The exception is unchecked, not an XMLStreamException.

Example: a 100-digit BigInteger fails when 64–99 characters of the output buffer are free.

Fix
  • Use TokenEncoder only for values of 64 characters or fewer; longer values go to the chunked StringEncoder.
  • Pass the correct end index to getChars() in StringEncoder.
Workaround

Write the value as text: writeCharacters(value.toString()).

Dominant language
Java
Stars
42
Forks
21
Avg merge
1d 2h
Merged PRs (30d)
7

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from FasterXML/stax2-api

All issues in FasterXML/stax2-api

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.