{"record":{"id":"41751d62bc985639","repo":"apache/dolphinscheduler","slug":"type-reference-cannot-be-null","errorCode":null,"errorMessage":"Type reference cannot be null","messagePattern":"Type reference cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java","lineNumber":286,"sourceCode":"            return \"\";\n        }\n    }\n\n    /**\n     * json to object\n     *\n     * @param json json string\n     * @param type type reference\n     * @param <T>\n     * @return return parse object\n     */\n    public static <T> T parseObject(String json, TypeReference<T> type) {\n        if (Strings.isNullOrEmpty(json)) {\n            return null;\n        }\n\n        if (type == null) {\n            throw new IllegalArgumentException(\"Type reference cannot be null\");\n        }\n\n        try {\n            return objectMapper.readValue(json, type);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(\"Parse json: \" + json + \" to type: \" + type.getType() + \" failed\", e);\n        }\n    }\n\n    /**\n     * object to json string\n     *\n     * @param object object\n     * @return json string\n     */\n    public static String toJsonString(Object object) {\n        try {\n            return objectMapper.writeValueAsString(object);","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java#L268-L304","documentation":"JSONUtils.parseObject(String, TypeReference<T>) deserializes JSON into a generic type expressed via a Jackson TypeReference. It throws this IllegalArgumentException when the TypeReference argument is null — the type is required to drive deserialization. Note the argument-order guard: an empty/null json returns null before this check, but a present json with a null type throws.","triggerScenarios":"Calling parseObject(json, null) or passing a TypeReference<T> variable built conditionally (null when the type is unknown), e.g. parseObject(payload, refs.get(typeName)) where refs has no entry for typeName.","commonSituations":"Generic helper methods forwarding a TypeReference that wasn't initialized; a switch/registry of TypeReferences for polymorphic payloads missing a case; refactoring from the Class overload where the TypeReference was forgotten.","solutions":["Always pass an anonymous TypeReference literal: parseObject(json, new TypeReference<Map<String, Object>>() {}).","Null-check/fail-fast the resolved TypeReference before calling, with a message naming the unresolved type.","Fix the registry/switch that produces the TypeReference so all expected payload kinds are covered.","Catch IllegalArgumentException around dynamic-type deserialization and return a typed failure."],"exampleFix":"// before\nTypeReference<List<Task>> ref = REF_CACHE.get(kind); // may be null\nList<Task> tasks = JSONUtils.parseObject(json, ref);\n// after\nTypeReference<List<Task>> ref = REF_CACHE.get(kind);\nif (ref == null) {\n    ref = new TypeReference<List<Task>>() {}; // or throw new IllegalStateException(\"Unknown kind: \" + kind);\n}\nList<Task> tasks = JSONUtils.parseObject(json, ref);","handlingStrategy":"type-guard","validationCode":"Objects.requireNonNull(typeRef, \"TypeReference for JSONUtils.parseObject must not be null\");","typeGuard":"if (typeRef != null) {\n    T value = JSONUtils.parseObject(json, typeRef);\n}","tryCatchPattern":"try {\n    return JSONUtils.parseObject(json, typeRef);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"TypeReference unresolved for payload\", e);\n}","preventionTips":["Create TypeReferences as anonymous literals at the call site: new TypeReference<...>() {}.","Null-check TypeReference variables fetched from caches/switches before use.","Document which payload kinds map to which TypeReference and test all branches."],"tags":["json","null-argument","type-reference"],"backgroundTag":"null-argument","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}