{"record":{"id":"925ccbdee5214258","repo":"apache/flink","slug":"missing-value-for-the-key","errorCode":null,"errorMessage":"Missing value for the key '{}'","messagePattern":"Missing value for the key '(.+?)'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/LinkedOptionalMap.java","lineNumber":188,"sourceCode":"\n    /**\n     * Assuming all the entries of this map are present (keys and values) this method would return a\n     * map with these key and values, stripped from their Optional wrappers. NOTE: please note that\n     * if any of the key or values are absent this method would throw an {@link\n     * IllegalStateException}.\n     */\n    public LinkedHashMap<K, V> unwrapOptionals() {\n        final LinkedHashMap<K, V> unwrapped =\n                CollectionUtil.newLinkedHashMapWithExpectedSize(underlyingMap.size());\n\n        for (Entry<String, KeyValue<K, V>> entry : underlyingMap.entrySet()) {\n            String namedKey = entry.getKey();\n            KeyValue<K, V> kv = entry.getValue();\n            if (kv.key == null) {\n                throw new IllegalStateException(\"Missing key '\" + namedKey + \"'\");\n            }\n            if (kv.value == null) {\n                throw new IllegalStateException(\"Missing value for the key '\" + namedKey + \"'\");\n            }\n            unwrapped.put(kv.key, kv.value);\n        }\n        return unwrapped;\n    }\n\n    /** Returns the key names added to this map. */\n    public Set<String> keyNames() {\n        return underlyingMap.keySet();\n    }\n\n    // --------------------------------------------------------------------------------------------------------\n    // Static Utility Methods\n    // --------------------------------------------------------------------------------------------------------\n\n    private static <K, V> boolean keyOrValueIsAbsent(Entry<String, KeyValue<K, V>> entry) {\n        KeyValue<K, V> kv = entry.getValue();\n        return kv.key == null || kv.value == null;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/LinkedOptionalMap.java#L170-L206","documentation":"The counterpart of the missing-key check in LinkedOptionalMap.unwrapOptionals(): an entry has a key but its value is null (KeyValue.value == null), so the map cannot produce a fully-populated LinkedHashMap and throws IllegalStateException naming the entry.","triggerScenarios":"Calling unwrapOptionals() after adding an entry whose key object exists but whose value was never supplied (optional value left absent), e.g. registering a component by name+key without a concrete instance.","commonSituations":"Optional component registration (table modules, formats, catalogs) where a factory failed or was skipped but the entry stayed in the map; partially-built configuration flows that add names first and values later, with unwrap called before population completes.","solutions":["Locate the entry named in the message and ensure its value is set before unwrapOptionals() runs.","Complete or remove half-populated entries prior to unwrapping (iterate keyNames() and check each value).","If a value cannot be resolved (factory unavailable), fail early with a clearer error at registration time instead of leaving a null value.","Write a validation step asserting all entries have both key and value before the unwrap call."],"exampleFix":"// before\nmap.put(\"module-a\", moduleKey, null); // value never resolved\nmap.unwrapOptionals(); // IllegalStateException: Missing value for the key 'module-a'\n\n// after\nModule module = moduleFactory.create();\nif (module != null) {\n    map.put(\"module-a\", moduleKey, module);\n}\nmap.unwrapOptionals();","handlingStrategy":"validation","validationCode":"for (String name : map.keyNames()) {\n    if (map.getOption(name) == null /* value absent */) {\n        throw new IllegalStateException(\"Entry '\" + name + \"' has no value; resolve it before unwrap\");\n    }\n}\nLinkedHashMap<K, V> m = map.unwrapOptionals();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve all values before registering entries","Fail at registration time when a factory cannot produce a value","Test the unwrap path with fully and partially populated maps"],"tags":["map","optional","configuration","table"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}