{"record":{"id":"487b153282af9eee","repo":"baomidou/mybatis-plus","slug":"unable-to-find-a-usable-constructor-for-s","errorCode":null,"errorMessage":"Unable to find a usable constructor for %s","messagePattern":"Unable to find a usable constructor for (.+?)","errorType":"exception","errorClass":"TypeException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/CompositeEnumTypeHandler.java","lineNumber":96,"sourceCode":"    }\n\n    @SuppressWarnings(\"unchecked\")\n    public <T> TypeHandler<T> getInstance(Class<?> javaTypeClass, Class<?> typeHandlerClass) {\n        if (javaTypeClass != null) {\n            try {\n                Constructor<?> c = typeHandlerClass.getConstructor(Class.class);\n                return (TypeHandler<T>) c.newInstance(javaTypeClass);\n            } catch (NoSuchMethodException ignored) {\n                // ignored\n            } catch (Exception e) {\n                throw new TypeException(\"Failed invoking constructor for handler \" + typeHandlerClass, e);\n            }\n        }\n        try {\n            Constructor<?> c = typeHandlerClass.getConstructor();\n            return (TypeHandler<T>) c.newInstance();\n        } catch (Exception e) {\n            throw new TypeException(\"Unable to find a usable constructor for \" + typeHandlerClass, e);\n        }\n    }\n}\n","sourceCodeStart":78,"sourceCodeEnd":100,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/CompositeEnumTypeHandler.java#L78-L100","documentation":"The configured default enum TypeHandler class exposes neither a constructor taking a Class nor a no-arg constructor, so CompositeEnumTypeHandler.getInstance cannot instantiate it. Both fallback paths (getConstructor(Class.class) and getConstructor()) failed.","triggerScenarios":"defaultEnumTypeHandler points to a class whose only constructors require other parameter types, or the class is non-public/in a non-exported package making getConstructor fail with an access exception.","commonSituations":"Custom handler with only a (String) or (Properties) constructor; handler class not public; Java module access restrictions blocking reflective constructor access.","solutions":["Add a public no-arg constructor and/or a public constructor accepting a single Class argument to the custom handler","Ensure the handler class is public and accessible","If the handler needs configuration, initialize it from the no-arg constructor via a static registry"],"exampleFix":"// before\npublic class MyEnumHandler extends BaseTypeHandler<Enum<?>> {\n    public MyEnumHandler(String config) { ... }\n}\n// after\npublic class MyEnumHandler extends BaseTypeHandler<Enum<?>> {\n    public MyEnumHandler() { this(defaultConfig()); }\n    public MyEnumHandler(Class<?> type) { ... }\n}","handlingStrategy":"validation","validationCode":"// Startup check for a custom default enum handler\nConstructor<?>[] ctors = MyHandler.class.getConstructors();\nboolean ok = Arrays.stream(ctors).anyMatch(c -> c.getParameterCount() == 0\n        || (c.getParameterCount() == 1 && c.getParameterTypes()[0] == Class.class));\nif (!ok) throw new IllegalStateException(\"Handler needs a public no-arg or (Class) constructor\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give custom TypeHandlers a public no-arg constructor by convention","Add an architecture test (ArchUnit/reflective check) enforcing constructor shape on handler classes","Document required constructor shapes when introducing custom handler SPIs"],"tags":["mybatis","type-handler","enum","reflection"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}