{"record":{"id":"c243a86dec349bbb","repo":"apple/pkl","slug":"e-getmessage-c243a8","errorCode":null,"errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/StringNodes.java","lineNumber":1022,"sourceCode":"        return new String(Base64.getDecoder().decode(self), StandardCharsets.UTF_8);\n      } catch (IllegalArgumentException e) {\n        throw exceptionBuilder()\n            .adhocEvalError(e.getMessage())\n            .withProgramValue(\"String\", self)\n            .withCause(e)\n            .build();\n      }\n    }\n  }\n\n  public abstract static class base64DecodedBytes extends ExternalPropertyNode {\n    @TruffleBoundary\n    @Specialization\n    protected VmBytes eval(String self) {\n      try {\n        return new VmBytes(Base64.getDecoder().decode(self));\n      } catch (IllegalArgumentException e) {\n        throw exceptionBuilder()\n            .adhocEvalError(e.getMessage())\n            .withProgramValue(\"String\", self)\n            .withCause(e)\n            .build();\n      }\n    }\n  }\n\n  public abstract static class encodeToBytes extends ExternalMethod1Node {\n    @TruffleBoundary\n    @Specialization\n    protected VmBytes eval(String self, String charsetName) {\n      try {\n        var bytes = self.getBytes(charsetName);\n        return new VmBytes(bytes);\n      } catch (UnsupportedEncodingException e) {\n        throw PklBugException.unreachableCode();\n      }","sourceCodeStart":1004,"sourceCodeEnd":1040,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/StringNodes.java#L1004-L1040","documentation":"Thrown by the Bytes variant of fromBase64 (String.toBytes via Base64 decoding) when the input is not valid Base64. Identical decoder rules as the text variant: illegal characters, bad padding, or invalid length cause the decoder's IllegalArgumentException to be raised as an eval error.","triggerScenarios":"Calling the bytes-returning Base64 decoder on a malformed string: wrong padding (\"YWJ\"), non-Base64 characters, or URL-safe alphabet without conversion.","commonSituations":"Decoding binary blobs from HTTP responses or files that were truncated; mixing base64 and base64url encodings; copying values that lost trailing '=' padding.","solutions":["Validate Base64 syntax (padding, alphabet, length % 4) before decoding","Translate URL-safe '-'/'_' to '+/' when the source is base64url","Strip whitespace/newlines that may have been inserted by wrapping","Check the source encoding of the blob — it may not be Base64 at all"],"exampleFix":"// before\nval bytes = blob.toBytes()\n// after\nval bytes = blob.replace(\"-\", \"+\").replace(\"_\", \"/\").toBytes()","handlingStrategy":"validation","validationCode":"function isStandardBase64(s: String): Boolean = s.replaceAll(\"\\n\", \"\").isRegexMatch(/^[A-Za-z0-9+/]*={0,2}$/, _) && s.replaceAll(\"\\n\", \"\").length % 4 == 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check padding correctness (length % 4) before decoding bytes","Translate URL-safe characters before the standard decoder","Verify the source truly is Base64 and was not truncated in transit"],"tags":["string","base64","bytes","decoding"],"backgroundTag":"invalid-base64","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}