{"record":{"id":"2f9a46a0b5184262","repo":"pagehelper-org/Mybatis-PageHelper","slug":"autodialectclassstr-class-must-provide-a-constru","errorCode":null,"errorMessage":"${autoDialectClassStr}Class must provide a constructor without parameters","messagePattern":"(.+?)Class must provide a constructor without parameters","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/github/pagehelper/page/PageAutoDialect.java","lineNumber":288,"sourceCode":"     *\n     * @param properties\n     */\n    private void initAutoDialectClass(Properties properties) {\n        String autoDialectClassStr = properties.getProperty(\"autoDialectClass\");\n        if (StringUtil.isNotEmpty(autoDialectClassStr)) {\n            try {\n                Class<? extends AutoDialect> autoDialectClass;\n                if (autoDialectMap.containsKey(autoDialectClassStr)) {\n                    autoDialectClass = autoDialectMap.get(autoDialectClassStr);\n                } else {\n                    autoDialectClass = (Class<AutoDialect>) Class.forName(autoDialectClassStr);\n                }\n                this.autoDialectDelegate = ClassUtil.newInstance(autoDialectClass, properties);\n            } catch (ClassNotFoundException e) {\n                throw new IllegalArgumentException(\"Make sure that the AutoDialect implementation class (\"\n                        + autoDialectClassStr + \") for the autoDialectClass configuration exists!\", e);\n            } catch (Exception e) {\n                throw new RuntimeException(autoDialectClassStr + \"Class must provide a constructor without parameters\", e);\n            }\n        } else {\n            this.autoDialectDelegate = new DataSourceNegotiationAutoDialect();\n        }\n    }\n\n    /**\n     * 初始化方言别名\n     *\n     * @param properties\n     */\n    private void initDialectAlias(Properties properties) {\n        String dialectAlias = properties.getProperty(\"dialectAlias\");\n        if (StringUtil.isNotEmpty(dialectAlias)) {\n            String[] alias = dialectAlias.split(\";\");\n            for (int i = 0; i < alias.length; i++) {\n                String[] kv = alias[i].split(\"=\");\n                if (kv.length != 2) {","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/pagehelper-org/Mybatis-PageHelper/blob/c692616c5bc95b41aa779b502f991825c8e5acbc/src/main/java/com/github/pagehelper/page/PageAutoDialect.java#L270-L306","documentation":"After resolving the autoDialectClass, PageAutoDialect instantiates it via ClassUtil.newInstance; any exception other than ClassNotFoundException (missing public no-arg constructor, instantiation failure, constructor throwing) is wrapped in a RuntimeException '<class>Class must provide a constructor without parameters'.","triggerScenarios":"The configured AutoDialect class exists but has no accessible no-argument constructor, is abstract/an interface, or its constructor (or static init) throws when invoked during setProperties.","commonSituations":"Custom AutoDialect written with a constructor taking Properties only; class made abstract; constructor depending on a service that is unavailable at plugin init; nested class not declared static (no implicit no-arg constructor).","solutions":["Add a public no-argument constructor to the AutoDialect implementation (properties are applied later via setProperties).","Make the class concrete, public, and static if nested.","Check the cause of this RuntimeException for the true reflective error.","Initialize external dependencies lazily in setLocalPageSize/setProperties rather than in the constructor."],"exampleFix":"// before\npublic class MyAutoDialect implements AutoDialect {\n    public MyAutoDialect(Properties p) { ... } // no no-arg ctor\n}\n// after\npublic class MyAutoDialect implements AutoDialect {\n    public MyAutoDialect() { }\n    @Override\n    public AbstractHelperDialect extractDialect(...) { ... }\n}","handlingStrategy":"try-catch","validationCode":"Class<?> c = Class.forName(autoDialectClass);\nif (c.isInterface() || java.lang.reflect.Modifier.isAbstract(c.getModifiers())\n        || java.lang.reflect.Constructor.class == null && c.getConstructors().length == 0) {\n    throw new IllegalStateException(autoDialectClass + \" needs a public no-arg constructor\");\n}\nc.getDeclaredConstructor().newInstance();","typeGuard":"static boolean hasNoArgCtor(Class<?> c) {\n    try { c.getDeclaredConstructor(); return java.lang.reflect.Modifier.isPublic(c.getModifiers()); }\n    catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    autoDialectDelegate = ClassUtil.newInstance(autoDialectClass, properties);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().endsWith(\"must provide a constructor without parameters\")) {\n        throw new IllegalStateException(\"Add a public no-arg constructor to \" + autoDialectClass, e.getCause());\n    }\n    throw e;\n}","preventionTips":["Always define an explicit public no-arg constructor in AutoDialect implementations; read properties in setProperties instead.","Declare nested implementation classes static.","Avoid throwing from constructors/initializers — defer to setProperties.","Check the wrapped cause when this RuntimeException appears; it names the reflective failure."],"tags":["auto-dialect","reflection","constructor","java"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"c692616c5bc95b41aa779b502f991825c8e5acbc","analyzedAt":"2026-09-08T03:50:49.192Z","contentChangedAt":"2026-09-08T03:50:49.192Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}