{"record":{"id":"375b08938744f139","repo":"apache/dolphinscheduler","slug":"class-type-cannot-be-null","errorCode":null,"errorMessage":"Class type cannot be null","messagePattern":"Class type 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":139,"sourceCode":"    }\n\n    /**\n     * This method deserializes the specified Json into an object of the specified class. It is not\n     * suitable to use if the specified class is a generic type since it will not have the generic\n     * type information because of the Type Erasure feature of Java. Therefore, this method should not\n     * be used if the desired type is a generic type. Note that this method works fine if the any of\n     * the fields of the specified object are generics, just the object itself should not be a\n     * generic type.\n     *\n     * @param json  the string from which the object is to be deserialized\n     * @param clazz the class of T\n     * @param <T>   T\n     * @return an object of type T from the string\n     * classOfT\n     */\n    public static @Nullable <T> T parseObject(String json, Class<T> clazz) {\n        if (clazz == null) {\n            throw new IllegalArgumentException(\"Class type cannot be null\");\n        }\n\n        if (Strings.isNullOrEmpty(json)) {\n            return null;\n        }\n\n        try {\n            return objectMapper.readValue(json, clazz);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(\"Parse json: \" + json + \" to class: \" + clazz.getName() + \" failed\", e);\n        }\n    }\n\n    /**\n     * deserialize\n     *\n     * @param src   byte array\n     * @param clazz class","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java#L121-L157","documentation":"JSONUtils.parseObject(String, Class<T>) deserializes a JSON string into an instance of the given class. It throws this IllegalArgumentException when the clazz argument is null — the target type is required to select the deserializer, so a null type is an immediate programming error, independent of the JSON content (an empty/null JSON string would otherwise just return null).","triggerScenarios":"Calling JSONUtils.parseObject(json, null) or passing a Class<T> variable that was resolved dynamically (reflection, generics erasure, map lookup) and came back null, e.g. parseObject(payload, CLASS_MAP.get(typeName)) with an unknown typeName.","commonSituations":"Generic deserialization helpers parameterized by a class fetched from a registry/enum that no longer contains the key; refactoring where a Class parameter was accidentally dropped or not propagated; building calls via reflection where getDeclaredClass returned null.","solutions":["Pass a concrete class literal: parseObject(json, MyDto.class) instead of a variable that can be null.","If the class is looked up dynamically, check it before calling: if (clazz == null) throw new IllegalStateException(\"Unknown type: \" + typeName);","Fix the registry/enum lookup so every expected key maps to a class, or handle the miss before deserializing.","Catch IllegalArgumentException at boundaries where dynamic types are expected to be occasionally unknown, and return a typed error result."],"exampleFix":"// before\nClass<?> clazz = TYPE_REGISTRY.get(typeName); // may be null\nMyDto dto = JSONUtils.parseObject(json, clazz);\n// after\nClass<?> clazz = TYPE_REGISTRY.get(typeName);\nif (clazz == null) {\n    throw new IllegalStateException(\"Unknown typeName: \" + typeName);\n}\nMyDto dto = JSONUtils.parseObject(json, clazz.asSubclass(MyDto.class));","handlingStrategy":"type-guard","validationCode":"Objects.requireNonNull(clazz, \"Target class for JSONUtils.parseObject must not be null\");","typeGuard":"if (clazz != null) {\n    T value = JSONUtils.parseObject(json, clazz);\n}","tryCatchPattern":"try {\n    return JSONUtils.parseObject(json, clazz);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"No target class resolved for deserialization\", e);\n}","preventionTips":["Pass class literals (Foo.class) instead of nullable Class variables whenever possible.","Null-check results of dynamic class lookups (maps, reflection) immediately after the lookup.","Keep type registries exhaustive: fail at registration/init time if a key has no class."],"tags":["json","null-argument","illegal-argument"],"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"}