{"record":{"id":"e42cf721dc588a06","repo":"github/copilot-sdk","slug":"incomplete-unicode-escape-at-position-pos-2","errorCode":null,"errorMessage":"Incomplete Unicode escape at position <pos-2>","messagePattern":"Incomplete Unicode escape at position <pos-2>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java","lineNumber":1062,"sourceCode":"                throw new IllegalArgumentException(\"Unterminated string escape at position \" + pos);\n            }\n            char escaped = input.charAt(pos++);\n            return switch (escaped) {\n                case '\"', '\\\\', '/' -> escaped;\n                case 'b' -> '\\b';\n                case 'f' -> '\\f';\n                case 'n' -> '\\n';\n                case 'r' -> '\\r';\n                case 't' -> '\\t';\n                case 'u' -> parseUnicodeEscape();\n                default -> throw new IllegalArgumentException(\n                        \"Invalid escape sequence \\\\\" + escaped + \" at position \" + (pos - 2));\n            };\n        }\n\n        private char parseUnicodeEscape() {\n            if (pos + 4 > input.length()) {\n                throw new IllegalArgumentException(\"Incomplete Unicode escape at position \" + (pos - 2));\n            }\n            int value = 0;\n            for (int i = 0; i < 4; i++) {\n                char hex = input.charAt(pos++);\n                if (!isAsciiHexDigit(hex)) {\n                    throw new IllegalArgumentException(\"Invalid Unicode escape at position \" + (pos - 1));\n                }\n                int digit = Character.digit(hex, 16);\n                value = (value << 4) | digit;\n            }\n            return (char) value;\n        }\n\n        private boolean isAsciiHexDigit(char c) {\n            return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');\n        }\n\n        private String parseBoolean() {","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java#L1044-L1080","documentation":"When parseEscape sees \\u it delegates to parseUnicodeEscape, which requires exactly four more characters (four hex digits) after the \\u prefix. If fewer than four characters remain in the input, the Unicode escape is incomplete and this IllegalArgumentException is thrown at the position of the backslash (pos-2).","triggerScenarios":"A JSON string ending with a truncated Unicode escape, e.g. '\"caf\\u00' or '\\u0' at end of input, typically from truncation or hand-written escapes with too few digits.","commonSituations":"Hand-typed \\u escapes missing digits; payloads truncated by a fixed-size log buffer or network read; copy/paste dropping trailing characters.","solutions":["Ensure every \\u escape has exactly four hex digits: '\\u00e9' not '\\u0' or '\\u00'","Check whether the input was truncated upstream and re-obtain the full payload","Use a JSON serializer to encode non-ASCII characters correctly (it will emit complete escapes or raw UTF-8)","Validate the JSON with a standard parser to pinpoint all malformed escapes before retrying"],"exampleFix":"// before\nString json = \"{\\\"ch\\\":\\\"\\\\u00\\\"}\"; // incomplete escape\n// after\nString json = \"{\\\"ch\\\":\\\"\\\\u00e9\\\"}\"; // 4 hex digits","handlingStrategy":"try-catch","validationCode":"java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"\\\\\\\\\\\\\\\\u(?!\\\\\\\\p{XDigit}{4})\").matcher(json);\nif (m.find()) {\n    throw new IllegalArgumentException(\"Incomplete \\\\u escape at index \" + m.start());\n}","typeGuard":null,"tryCatchPattern":"try {\n    String result = CopilotToolProcessor.jsonToMapOfSource(json);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Incomplete Unicode escape\")) {\n        // input truncated or hand-written escape missing hex digits; refetch/fix\n    }\n}","preventionTips":["Always write four hex digits after \\u","Guard against truncation: check payload ends with the expected terminator (e.g. '}')","Template engines: ensure \\uXXXX placeholders are fully substituted","Prefer serializers that emit valid escapes or raw UTF-8"],"tags":["java","json","parsing","unicode","escaping"],"backgroundTag":"json-parse-error","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}