{"record":{"id":"5545b68d8993b5bd","repo":"OpenAPITools/openapi-generator","slug":"word-name-could-not-be-escaped","errorCode":null,"errorMessage":"Word '${name}' could not be escaped.","messagePattern":"Word '(.+?)' could not be escaped\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/StringUtils.java","lineNumber":278,"sourceCode":"     * throws Runtime exception as word is not escaped properly.\n     */\n    public static String escape(final String name, final Map<String, String> replacementMap,\n                                final List<String> charactersToAllow, final String appendToReplacement) {\n        EscapedNameOptions ns = new EscapedNameOptions(name, replacementMap.keySet(), charactersToAllow, appendToReplacement);\n        return escapedWordsCache.get(ns, wordToEscape -> {\n            String result = name.chars().mapToObj(c -> {\n                String character = String.valueOf((char) c);\n                if (charactersToAllow != null && charactersToAllow.contains(character)) {\n                    return character;\n                } else if (replacementMap.containsKey(character)) {\n                    return replacementMap.get(character) + (appendToReplacement != null ? appendToReplacement : \"\");\n                } else {\n                    return character;\n                }\n            }).reduce((c1, c2) -> c1 + c2).orElse(null);\n\n            if (result != null) return result;\n            throw new RuntimeException(\"Word '\" + name + \"' could not be escaped.\");\n        });\n    }\n\n    /**\n     * Return a unique string based on a set of processed strings.\n     *\n     * @param processedStrings a set of strings that have been processed\n     * @param input            input to be checked for uniqueness\n     * @return a unique string\n     */\n    public static String getUniqueString(Set<String> processedStrings, String input) {\n        if (input == null) {\n            return null;\n        }\n\n        String uniqueName = input;\n        // check for input uniqueness\n        int counter = 0;","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/StringUtils.java#L260-L296","documentation":"StringUtils.escape (line 262) maps each character of a name through a replacement map and joins the results. The reduce(...).orElse(null) yields null only when the input's chars() stream is empty — i.e. the name is an empty string — at which point the RuntimeException 'Word ... could not be escaped.' is thrown. So despite the generic wording, this error means escape(\"\") was called: some generator passed an empty identifier (model/property/operation name) into escaping.","triggerScenarios":"A generator or plugin calling StringUtils.escape with an empty string, e.g. a schema with an empty-name property, an empty tag or operationId-derived value, or code that builds names by string concatenation and produces \"\" before escaping. The message renders as: Word '' could not be escaped.","commonSituations":"Specs with anonymous/empty property names (\"\": {type: string}) that some tools tolerate; custom template code or third-party generator subclasses constructing names from optional vendor extensions that are absent; edge cases after name sanitization strips everything.","solutions":["Find what is empty: the exception shows Word '' — inspect the stack trace for the calling generator method and check the corresponding spec element (property name, tag, operationId) near the failing model.","Give every schema property, definition and operation a non-empty, alphanumeric-starting name in the spec.","In custom code calling escape, guard empty inputs and fall back to a sensible default name instead of escaping \"\"."],"exampleFix":"// before (custom code)\nString className = StringUtils.escape(schemaName, replacements, allowed, \"_\");\n// schemaName may be \"\" for anonymous schemas\n\n// after\nString className = StringUtils.escape(\n    schemaName == null || schemaName.isEmpty() ? \"GeneratedModel\" : schemaName,\n    replacements, allowed, \"_\");","handlingStrategy":"validation","validationCode":"// Node: reject empty names anywhere in the spec before generating\nconst check = (o, path) => { for (const [k, v] of Object.entries(o ?? {})) {\n  if (/^(properties|schemas|operationId|tag)$/.test(k) || path === 'properties') {\n    if ((k === '' || k === 'operationId') && String(v).length === 0)\n      throw new Error('empty identifier in spec');\n  }\n  if (v && typeof v === 'object') check(v, k);\n}};\ncheck(require('./openapi.json'), '');","typeGuard":"// Java: guard before calling StringUtils.escape\nString safeEscape(String name) {\n    return StringUtils.escape(\n        (name == null || name.isEmpty()) ? \"Generated\" : name,\n        replacements, allowed, \"_\");\n}","tryCatchPattern":null,"preventionTips":["Never leave anonymous (empty-key) properties or empty identifiers in specs.","In custom generator code, short-circuit empty names to a default before escaping."],"tags":["java","codegen","string-escaping","naming","edge-case"],"backgroundTag":"empty-identifier-name","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}