microg/GmsCore · info · RuntimeException
Unsupported encoding UTF8. This should always be supported.
Error message
Unsupported encoding UTF8. This should always be supported.
What it means
readStringAndClose converts the read bytes to a String via bos.toString("UTF-8") and wraps the impossible-in-practice UnsupportedEncodingException in this RuntimeException. On any compliant Java/Android runtime UTF-8 is guaranteed, so this is effectively an internal invariant violation and almost never the real problem when license reading fails.
Source
Thrown at play-services-oss-licenses/src/main/java/org/microg/gms/oss/licenses/LicenseUtil.java:101
}
private static String readStringAndClose(InputStream is, int bytesToRead) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
byte[] bytes = new byte[1024];
int read;
while (bytesToRead > 0 && (read = is.read(bytes, 0, Math.min(bytes.length, bytesToRead))) != -1) {
bos.write(bytes, 0, read);
bytesToRead -= read;
}
is.close();
} catch (IOException e) {
throw new RuntimeException("Failed to read license or metadata", e);
}
try {
return bos.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Unsupported encoding UTF8. This should always be supported.", e);
}
}
}
View on GitHub (pinned to 157c9d86ac)
Solutions
- Ignore for practical debugging — investigate the sibling 'Failed to read license or metadata' IOException instead
- If ever seen, verify the runtime/JVM actually supports standard charsets (Charset.isSupported("UTF-8"))
- Optionally replace with StandardCharsets.UTF_8 / bos.toString(StandardCharsets.UTF_8) (API 19+) to eliminate the checked exception
Example fix
// before
return bos.toString("UTF-8");
// after
return new String(bos.toByteArray(), StandardCharsets.UTF_8); // no UnsupportedEncodingException path Defensive patterns
Strategy: try-catch
Try / catch
try {
text = LicenseUtil.getLicenseText(context, license);
} catch (RuntimeException e) {
// effectively unreachable unless the JVM lacks UTF-8; log and use fallback
Log.e("Licenses", "Unexpected charset failure", e);
text = null;
} Prevention
- Treat this as an internal invariant; debug the IOException-based messages instead
- Run on standard Android/JVM runtimes where UTF-8 is guaranteed
- Optionally migrate code to StandardCharsets.UTF_8 to remove the encoding failure path entirely
When it happens
Trigger: Only when the runtime's charset infrastructure is broken or a non-standard JVM without UTF-8 support is used; never triggered by input data or license content.
Common situations: Essentially never in production; seen only on severely broken/custom runtimes. Usually a red herring when debugging license errors.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- does not contain res/raw/third_party_licenses
- Failed to read license or metadata
- deleteAll was set to true but keys were also provided
- Element in keys cannot be null or empty
- deleteAll=true but keys are provided
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/17925c2a89d1d9c9.
Report an issue: GitHub.