{"record":{"id":"7196d36fc1266f86","repo":"baomidou/mybatis-plus","slug":"failed-invoking-constructor-for-handler-s","errorCode":null,"errorMessage":"Failed invoking constructor for handler %s","messagePattern":"Failed invoking constructor for handler (.+?)","errorType":"exception","errorClass":"TypeException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/CompositeEnumTypeHandler.java","lineNumber":89,"sourceCode":"    public E getResult(ResultSet rs, int columnIndex) throws SQLException {\n        return delegate.getResult(rs, columnIndex);\n    }\n\n    @Override\n    public E getResult(CallableStatement cs, int columnIndex) throws SQLException {\n        return delegate.getResult(cs, columnIndex);\n    }\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":71,"sourceCodeEnd":100,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/CompositeEnumTypeHandler.java#L71-L100","documentation":"CompositeEnumTypeHandler fell back to the configured default enum TypeHandler (a class taking a Class constructor), and invoking that constructor threw an exception (found via getConstructor(Class.class), but newInstance failed). The handler class exists but its constructor rejected the enum type.","triggerScenarios":"GlobalConfig/defaultEnumTypeHandler is set to a custom TypeHandler whose (Class) constructor throws — e.g. it only supports certain enum shapes (requires IEnum or @EnumValue annotations) and throws for plain enums.","commonSituations":"A custom defaultEnumTypeHandler that assumes annotated enums (MybatisEnumTypeHandler-like behavior) but is registered for all enums including plain ones; handler constructor performing lookups that fail for some enum types.","solutions":["Inspect the nested cause to see why the handler constructor threw for the specific enum type","Make the custom handler tolerate plain enums (fall back internally to default behavior) instead of throwing","Annotate the enum correctly (e.g. add @EnumValue field or implement IEnum) if the handler requires it","Restrict the custom handler to the enum types it actually supports"],"exampleFix":"// before\npublic class StatusTypeHandler extends BaseTypeHandler<Enum<?>> {\n    public StatusTypeHandler(Class<?> type) {\n        if (!type.isAnnotationPresent(Supported.class)) throw new IllegalArgumentException();\n    }\n}\n// after\npublic class StatusTypeHandler extends BaseTypeHandler<Enum<?>> {\n    public StatusTypeHandler(Class<?> type) { /* tolerant: handle unsupported types gracefully */ }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { CompositeEnumTypeHandler.setDefaultEnumTypeHandler(MyHandler.class); } catch (TypeException e) { log.error(\"Default enum handler unusable: {}\", e.getCause()); throw e; } // fail fast at config time, not per query","preventionTips":["Unit-test your custom enum handler against a plain enum (no annotations) before registering it as default","Design handler constructors to never throw for unsupported types — degrade to default behavior","Keep annotated (IEnum/@EnumValue) and plain enums on separate handler paths"],"tags":["mybatis","type-handler","enum","configuration"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}