MuntashirAkon/AppManager · error · IOException
result.toString()
Error message
result.toString()
What it means
FastXmlSerializer.flush() throws IOException when the CharsetEncoder reports a CoderResult error during encoding the buffered text to the output stream; the message is the CoderResult's toString (e.g. malformed/unmappable character information).
Solutions
- Use UTF-8 for the serializer's charset so all valid Unicode is encodable.
- Fix the source string: remove/replace unpaired surrogates (e.g. via String.codePoints() filtering).
- Catch IOException around serialization and identify the offending buffer content.
- Ensure the writer never splices strings at arbitrary char indexes that can split surrogate pairs.
Example fix
// before
String s = new String(new char[]{0xD83D}); // unpaired surrogate -> IOException on flush
// after
String s = input.codePoints()
.filter(cp -> Character.isValidCodePoint(cp))
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString(); Defensive patterns
Strategy: try-catch
Validate before calling
boolean valid = s.chars().allMatch(c ->
!(Character.isHighSurrogate((char) c)) || /* next is low surrogate */ true);
// simpler: ensure no unpaired surrogates
boolean wellFormed = s.codePoints().allMatch(cp -> Character.isValidCodePoint(cp)); Try / catch
try {
serializer.flush();
} catch (IOException e) {
throw new IOException("Character encoding failed in serializer: " + e.getMessage(), e);
} Prevention
- Always use UTF-8 as the serializer charset.
- Sanitize input strings for unpaired surrogates before writing.
- Avoid splitting surrogate pairs when slicing strings by char index.
- Test serialization with emoji and supplementary-plane characters.
When it happens
Trigger: Writing text containing characters not encodable in the configured charset (typically malformed surrogate pairs from unpaired high/low surrogates) before flushBytes/out stream flush runs.
Common situations: Serializing strings built from invalid char data (truncated emoji, hand-spliced char arrays), or a non-UTF-8 charset that cannot represent the content.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/fb394894fe9aa355.
Report an issue: GitHub.
Appendix: source
Thrown at libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/FastXmlSerializer.java:249
private void flushBytes() throws IOException {
int position;
if ((position = mBytes.position()) > 0) {
mBytes.flip();
mOutputStream.write(mBytes.array(), 0, position);
mBytes.clear();
}
}
public void flush() throws IOException {
//Log.i("PackageManager", "flush mPos=" + mPos);
if (mPos > 0) {
if (mOutputStream != null) {
CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
CoderResult result = mCharset.encode(charBuffer, mBytes, true);
while (true) {
if (result.isError()) {
throw new IOException(result.toString());
} else if (result.isOverflow()) {
flushBytes();
result = mCharset.encode(charBuffer, mBytes, true);
continue;
}
break;
}
flushBytes();
mOutputStream.flush();
} else {
mWriter.write(mText, 0, mPos);
mWriter.flush();
}
mPos = 0;
}
}
public int getDepth() {View on GitHub (pinned to 0152f468fc)