{"record":{"id":"e412213f2685e55b","repo":"apache/incubator-seata","slug":"targetclass-must-be-not-null","errorCode":null,"errorMessage":"targetClass must be not null","messagePattern":"targetClass must be not null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/org/apache/seata/common/util/ReflectionUtil.java","lineNumber":663,"sourceCode":"    /**\n     * invoke static Method\n     *\n     * @param targetClass      the target class\n     * @param staticMethodName the static method name\n     * @param parameterTypes   the parameter types\n     * @param args             the args\n     * @return the result of the static method\n     * @throws IllegalArgumentException  if {@code targetClass} is {@code null}\n     * @throws NullPointerException      if {@code methodName} is {@code null}\n     * @throws NoSuchMethodException     the no such method exception\n     * @throws InvocationTargetException if the underlying method throws an exception.\n     * @throws SecurityException         the security exception\n     */\n    public static Object invokeStaticMethod(\n            Class<?> targetClass, String staticMethodName, Class<?>[] parameterTypes, Object... args)\n            throws IllegalArgumentException, NoSuchMethodException, InvocationTargetException, SecurityException {\n        if (targetClass == null) {\n            throw new IllegalArgumentException(\"targetClass must be not null\");\n        }\n\n        // get method\n        Method staticMethod = getMethod(targetClass, staticMethodName, parameterTypes);\n        if (!Modifier.isStatic(staticMethod.getModifiers())) {\n            throw new NoSuchMethodException(\n                    \"static method not found: \" + methodToString(targetClass, staticMethodName, parameterTypes));\n        }\n\n        return invokeStaticMethod(staticMethod, args);\n    }\n\n    /**\n     * invoke static Method\n     *\n     * @param targetClass      the target class\n     * @param staticMethodName the static method name\n     * @return the result of the static method","sourceCodeStart":645,"sourceCodeEnd":681,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/common/src/main/java/org/apache/seata/common/util/ReflectionUtil.java#L645-L681","documentation":"ReflectionUtil.invokeStaticMethod invokes a static method by name on a target class. It first asserts targetClass is non-null and throws IllegalArgumentException(\"targetClass must be not null\") otherwise — a programming-error guard so callers fail fast when the Class reference (often from Class.forName or config) is missing rather than NPE-ing later.","triggerScenarios":"Calling ReflectionUtil.invokeStaticMethod(null, \"methodName\", paramTypes, args) — typically because Class.forName(className) failed upstream and returned/propagated null, or a configurable class name was blank so the lookup produced null.","commonSituations":"Config-driven class names (e.g. serializer or compressor factory classes in seata config) that are misspelled or absent, leaving a null Class passed into reflection-based instantiation; refactors that changed a class constant to an optional value.","solutions":["Fix the upstream class lookup so targetClass is never null — check Class.forName inputs and handle ClassNotFoundException separately","Null-check targetClass before the call and raise a descriptive error naming the missing class","Validate configurable class names at startup (exists on classpath) rather than at first use"],"exampleFix":"// before\nObject r = ReflectionUtil.invokeStaticMethod(clazz, \"init\", null); // clazz == null -> throws\n\n// after\nif (clazz == null) throw new IllegalStateException(\"class not loaded: \" + className);\nObject r = ReflectionUtil.invokeStaticMethod(clazz, \"init\", null);","handlingStrategy":"validation","validationCode":"if (targetClass == null) throw new IllegalStateException(\"target class not loaded: \" + className);\nReflectionUtil.invokeStaticMethod(targetClass, \"init\", paramTypes);","typeGuard":null,"tryCatchPattern":"try { ReflectionUtil.invokeStaticMethod(clazz, m, pt); } catch (IllegalArgumentException e) { throw new ConfigurationException(\"class missing for reflective call\", e); }","preventionTips":["Resolve classes once at startup and fail fast if missing","Validate configurable class names against the classpath during boot","Never pass a possibly-null Class into reflection utilities"],"tags":["reflection","null-check","api-misuse"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}