{"record":{"id":"25a50151f5d65d79","repo":"YunaiV/yudao-cloud","slug":"cannot-convert-type-to-a-boolean-value","errorCode":null,"errorMessage":"Cannot convert type {} to a boolean value","messagePattern":"Cannot convert type (.+?) to a boolean value","errorType":"exception","errorClass":"UnexpectedLiquibaseException","httpStatus":null,"severity":"error","filePath":"sql/dm/flowable-patch/src/main/java/liquibase/datatype/core/BooleanType.java","lineNumber":108,"sourceCode":"            } else {\n                returnValue = this.getFalseBooleanValue(database);\n            }\n        } else if (value instanceof Number) {\n            if (value.equals(1) || \"1\".equals(value.toString()) || \"1.0\".equals(value.toString())) {\n                returnValue = this.getTrueBooleanValue(database);\n            } else {\n                returnValue = this.getFalseBooleanValue(database);\n            }\n        } else if (value instanceof DatabaseFunction) {\n            return value.toString();\n        } else if (value instanceof Boolean) {\n            if (((Boolean) value)) {\n                returnValue = this.getTrueBooleanValue(database);\n            } else {\n                returnValue = this.getFalseBooleanValue(database);\n            }\n        } else {\n            throw new UnexpectedLiquibaseException(\"Cannot convert type \" + value.getClass() + \" to a boolean value\");\n        }\n\n        return returnValue;\n    }\n\n    protected boolean isNumericBoolean(Database database) {\n        if (database instanceof Firebird3Database) {\n            return false;\n        }\n        if (database instanceof DerbyDatabase) {\n            return !((DerbyDatabase) database).supportsBooleanDataType();\n        } else if (database instanceof DB2Database) {\n            return !((DB2Database) database).supportsBooleanDataType();\n        }\n        return (database instanceof Db2zDatabase)\n            || (database instanceof FirebirdDatabase)\n            || (database instanceof MSSQLDatabase)\n            || (database instanceof MySQLDatabase)","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/YunaiV/yudao-cloud/blob/477be9dd49ab7223a972a6abdff0684d6423dec3/sql/dm/flowable-patch/src/main/java/liquibase/datatype/core/BooleanType.java#L90-L126","documentation":"BooleanType.objectToSqlValue only converts String, Long, Number, DatabaseFunction and Boolean instances. Any other Java type (Date, char[], custom object, null-with-unexpected-type) falls to the final else and throws, reporting the offending class name in the message.","triggerScenarios":"Programmatic API use where a Changeset/column value is set with an unsupported object, e.g. Column.setDefaultValue(Character 'Y'), a java.util.Date, or a char primitive boxed as Character. Character values are the classic case: '1' as char is not the String \"1\".","commonSituations":"Code that builds Liquibase Change objects dynamically and passes raw types from an ORM or CSV import; upgrading Liquibase versions where previously-silently-coerced types now fail; using setDefaultValue(new Character('0')).","solutions":["Convert the value to String/Boolean/Number before setting it: String.valueOf(value) for '1'/'0'/'true'/'false'.","Use Boolean.TRUE/FALSE or Integer 1/0 for numeric-boolean databases.","Wrap computed SQL in new DatabaseFunction(\"...\") instead of raw objects.","Inspect the class name printed in the message to find the exact caller passing the bad type."],"exampleFix":"// before\ncolumn.setDefaultValue(Character.valueOf('1'));\n\n// after\ncolumn.setDefaultValue(\"1\");","handlingStrategy":"type-guard","validationCode":"Object v = column.getDefaultValue();\nif (!(v == null || v instanceof String || v instanceof Boolean || v instanceof Number || v instanceof DatabaseFunction)) {\n    v = String.valueOf(v); // coerce before Liquibase sees it\n    column.setDefaultValue(v);\n}","typeGuard":"static boolean convertibleToLiquibaseBoolean(Object v) {\n    return v == null || v instanceof String || v instanceof Boolean\n        || v instanceof Number || v instanceof DatabaseFunction;\n}","tryCatchPattern":"try { sqlValue = boolType.objectToSqlValue(v, db); }\ncatch (UnexpectedLiquibaseException e) {\n    if (e.getMessage().startsWith(\"Cannot convert type\")) {\n        sqlValue = v == null ? null : String.valueOf(v); // explicit fallback\n    } else throw e;\n}","preventionTips":["Map external values to String/Boolean/Number at the boundary of any Liquibase programmatic API","Beware Character values from CSV/ORM layers — box to String explicitly"],"tags":["liquibase","boolean","datatype","classcast","type-conversion"],"backgroundTag":null,"analyzedSha":"477be9dd49ab7223a972a6abdff0684d6423dec3","analyzedAt":"2026-08-14T13:35:31.121Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}