{"record":{"id":"18bc340614558382","repo":"apple/pkl","slug":"adhocevalerror","errorCode":null,"errorMessage":"adhocEvalError","messagePattern":"adhocEvalError","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/StringNodes.java","lineNumber":1006,"sourceCode":"    }\n  }\n\n  public abstract static class base64 extends ExternalPropertyNode {\n    @TruffleBoundary\n    @Specialization\n    protected String eval(String self) {\n      return ByteArrayUtils.base64(self.getBytes(StandardCharsets.UTF_8));\n    }\n  }\n\n  public abstract static class base64Decoded extends ExternalPropertyNode {\n    @TruffleBoundary\n    @Specialization\n    protected String eval(String self) {\n      try {\n        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)","sourceCodeStart":988,"sourceCodeEnd":1024,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/StringNodes.java#L988-L1024","documentation":"Thrown by String.fromBase64() (decoded as UTF-8 text) when the input is not valid Base64. Java's Base64 decoder rejects illegal characters, incorrect padding, or lengths that are not a multiple of 4; the decoder's message is surfaced with the offending string attached.","triggerScenarios":"Calling `\"not~base64!\".fromBase64()`, a Base64 string with wrong padding (e.g. \"YWJ\"), URL-safe base64 (- and _) fed to the standard decoder, or an empty/malformed payload from an API.","commonSituations":"Copying tokens or credentials that got truncated or whitespace-mangled; receiving base64url (JWT segments) instead of standard base64; data-URI prefixes (\"data:...;base64,\") left in the string.","solutions":["Verify the string is valid Base64 (length multiple of 4, correct padding, alphabet A–Z a–z 0–9 + /)","Strip any data-URI prefix and whitespace before decoding","Convert URL-safe characters: replace '-' with '+' and '_' with '/' for JWT-style payloads","Re-encode the source data if the payload is truncated or corrupt"],"exampleFix":"// before\nval text = jwtPayload.fromBase64()\n// after\nval text = jwtPayload.replace(\"-\", \"+\").replace(\"_\", \"/\").fromBase64()","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":["Validate the Base64 alphabet and padding before decoding","Strip data-URI prefixes and whitespace","Convert base64url (-, _) to standard base64 first"],"tags":["string","base64","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"}