{"record":{"id":"cb475af31bbba74d","repo":"apache/incubator-seata","slug":"static-method-not-found","errorCode":null,"errorMessage":"static method not found: {}","messagePattern":"static method not found: (.+?)","errorType":"exception","errorClass":"NoSuchMethodException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/org/apache/seata/common/util/ReflectionUtil.java","lineNumber":669,"sourceCode":"     * @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\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     */","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/common/src/main/java/org/apache/seata/common/util/ReflectionUtil.java#L651-L687","documentation":"ReflectionUtil.invokeStaticMethod resolves the named method via getMethod and then requires it to be static. If the method exists but is an instance method (or resolution matched a non-static overload), it throws NoSuchMethodException(\"static method not found: \" + methodToString(...)) — the message embeds the full class.method(parameters) signature. Note: a truly missing name throws NoSuchMethodException from getMethod itself instead.","triggerScenarios":"Calling invokeStaticMethod(targetClass, \"someMethod\", parameterTypes, ...) where someMethod is declared without 'static' in the target class — e.g. invoking a factory method after someone removed the static modifier, or passing an interface/instance utility class whose methods are all instance-level.","commonSituations":"Upgrading a dependency whose API changed a static factory to an instance method (or vice versa); copy-pasted method names; refactors that made a helper non-static without updating reflective callers such as seata serializer/compressor factories.","solutions":["Add 'static' to the target method declaration, or invoke it on an instance via the instance-method variant of ReflectionUtil","Verify the exact method name, parameter types, and staticness with javap or IDE inspection before the reflective call","Pin/align dependency versions so reflective targets match the compiled signatures"],"exampleFix":"// before\nclass SerializerHolder { Object create(Class<?> c) { ... } } // instance method\nReflectionUtil.invokeStaticMethod(SerializerHolder.class, \"create\", new Class[]{Class.class}); // throws\n\n// after\nclass SerializerHolder { static Object create(Class<?> c) { ... } }\nReflectionUtil.invokeStaticMethod(SerializerHolder.class, \"create\", new Class[]{Class.class});","handlingStrategy":"validation","validationCode":"Method m = targetClass.getMethod(\"create\", paramTypes);\nif (!Modifier.isStatic(m.getModifiers())) throw new IllegalStateException(\"create is not static on \" + targetClass);\nReflectionUtil.invokeStaticMethod(targetClass, \"create\", paramTypes);","typeGuard":"static boolean isStaticMethod(Class<?> c, String name, Class<?>[] pt) throws NoSuchMethodException { return Modifier.isStatic(c.getMethod(name, pt).getModifiers()); }","tryCatchPattern":"try { ReflectionUtil.invokeStaticMethod(c, \"create\", pt); } catch (NoSuchMethodException e) { throw new ConfigurationException(\"expected static factory missing: \" + e.getMessage(), e); }","preventionTips":["Verify staticness with reflection (Modifier.isStatic) before invoking","Pin dependency versions whose reflective targets you rely on","Write a startup self-test for each reflectively invoked factory method"],"tags":["reflection","api-misuse","version-change"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}