{"record":{"id":"b48012a8c5251e43","repo":"apple/pkl","slug":"invalidcodepoint","errorCode":"invalidCodePoint","errorMessage":"invalidCodePoint","messagePattern":"invalidCodePoint","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java","lineNumber":395,"sourceCode":"      return self >= start && self <= inclusiveEnd;\n    }\n\n    @Specialization\n    protected boolean evalFloatFloat(long self, double start, double inclusiveEnd) {\n      return self >= start && self <= inclusiveEnd;\n    }\n  }\n\n  public abstract static class toChar extends ExternalMethod0Node {\n    @Specialization\n    protected String eval(long self) {\n      var codePoint = (int) self;\n      if (codePoint == self && Character.isValidCodePoint(codePoint)) {\n        return Character.toString(codePoint);\n      }\n\n      CompilerDirectives.transferToInterpreter();\n      throw exceptionBuilder().evalError(\"invalidCodePoint\", self).build();\n    }\n  }\n}\n","sourceCodeStart":377,"sourceCodeEnd":399,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java#L377-L399","documentation":"IntNodes' codePoint-to-string conversion (Int.prototype.codePointToString or similar) turns an integer into a single-character String only when it is an exact integer and a valid Unicode code point (0..0x10FFFF, excluding the surrogate range per Character.isValidCodePoint semantics). Otherwise it throws the `invalidCodePoint` eval error.","triggerScenarios":"Calling the code point conversion with an Int that is negative, exceeds 0x10FFFF, is non-integral (e.g. 65.5 via a Float-typed Int node), or lands in the surrogate range — thrown at IntNodes.java:395 when `codePoint == self && Character.isValidCodePoint(codePoint)` fails.","commonSituations":"Decoding character codes from external data where offsets are off-by-one or byte-swapped, computing code points from arithmetic that produced 0 or negative values, or accidentally passing a full UTF-16 code unit pair instead of a code point.","solutions":["Ensure the integer is in 0..0x10FFFF before conversion.","Reject/repair negative or fractional values at the data source.","Replace surrogate code units with the combined code point (e.g. 0x1F600 instead of the 0xD83D/0xDE00 pair).","Use String.fromCharCode-style composition at the source for multi-unit characters instead of this API."],"exampleFix":"// before\nch = 0x110000.codePointToString()  // invalidCodePoint\n// after\nch = if (cp >= 0 && cp <= 0x10FFFF) cp.codePointToString() else \"\\uFFFD\"","handlingStrategy":"validation","validationCode":"function isValidCodePoint(n) {\n  return Number.isInteger(n) && n >= 0 && n <= 0x10FFFF && !(n >= 0xD800 && n <= 0xDFFF);\n}","typeGuard":"function isConvertibleCodePoint(n) {\n  return typeof n === \"number\" && Number.isInteger(n) && n >= 0 && n <= 0x10FFFF;\n}","tryCatchPattern":null,"preventionTips":["Validate code point ranges at the data boundary","Avoid surrogate-range values; combine surrogate pairs first","Reject negative or fractional values before conversion"],"tags":["pkl","integer","unicode","code-point"],"backgroundTag":"argument-out-of-range","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}