{"record":{"id":"17925c2a89d1d9c9","repo":"microg/GmsCore","slug":"unsupported-encoding-utf8-this-should-always-be-s","errorCode":null,"errorMessage":"Unsupported encoding UTF8. This should always be supported.","messagePattern":"Unsupported encoding UTF8\\. This should always be supported\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"info","filePath":"play-services-oss-licenses/src/main/java/org/microg/gms/oss/licenses/LicenseUtil.java","lineNumber":101,"sourceCode":"    }\n\n    private static String readStringAndClose(InputStream is, int bytesToRead) {\n        ByteArrayOutputStream bos = new ByteArrayOutputStream();\n        try {\n            byte[] bytes = new byte[1024];\n            int read;\n            while (bytesToRead > 0 && (read = is.read(bytes, 0, Math.min(bytes.length, bytesToRead))) != -1) {\n                bos.write(bytes, 0, read);\n                bytesToRead -= read;\n            }\n            is.close();\n        } catch (IOException e) {\n            throw new RuntimeException(\"Failed to read license or metadata\", e);\n        }\n        try {\n            return bos.toString(\"UTF-8\");\n        } catch (UnsupportedEncodingException e) {\n            throw new RuntimeException(\"Unsupported encoding UTF8. This should always be supported.\", e);\n        }\n    }\n}\n","sourceCodeStart":83,"sourceCodeEnd":105,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-oss-licenses/src/main/java/org/microg/gms/oss/licenses/LicenseUtil.java#L83-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"Essentially never in production; seen only on severely broken/custom runtimes. Usually a red herring when debugging license errors.","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"],"exampleFix":"// before\nreturn bos.toString(\"UTF-8\");\n// after\nreturn new String(bos.toByteArray(), StandardCharsets.UTF_8); // no UnsupportedEncodingException path","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    text = LicenseUtil.getLicenseText(context, license);\n} catch (RuntimeException e) {\n    // effectively unreachable unless the JVM lacks UTF-8; log and use fallback\n    Log.e(\"Licenses\", \"Unexpected charset failure\", e);\n    text = null;\n}","preventionTips":["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"],"tags":["android","encoding","utf-8","licensing"],"backgroundTag":"unsupported-operation","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}