SqlGeneratorFactory uses Class.equals

Hi everyone,

currently we have a problem using Liquibase and WebSphere 6.1. We get ClassCastExceptions like this:
java.lang.ClassCastException: liquibase.statement.core.CreateIndexStatement incompatible with liquibase.statement.core.DropPrimaryKeyStatement
    at liquibase.sqlgenerator.core.DropPrimaryKeyGenerator.supports(DropPrimaryKeyGenerator.java:12)
    at liquibase.sqlgenerator.SqlGeneratorFactory.checkType(SqlGeneratorFactory.java:120)
    at liquibase.sqlgenerator.SqlGeneratorFactory.getGenerators(SqlGeneratorFactory.java:95)
    at liquibase.sqlgenerator.SqlGeneratorFactory.supports(SqlGeneratorFactory.java:155)
    at liquibase.change.AbstractChange.warn(AbstractChange.java:79)
    at liquibase.changelog.visitor.ValidatingVisitor.visit(ValidatingVisitor.java:77)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
    at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:131)
    at liquibase.Liquibase.listUnrunChangeSets(Liquibase.java:583)

After some debugging I found out that this is caused by this expressionin the checkType method of SqlGeneratorFactory:
if (typeClass.equals(SqlStatement.class)) {

Looks like WebSphere uses multiple classloaders, so there are multiple definitions of SqlStatements loaded. Although typeClass is SqlStatement, sometimes the expression returns false.

Later the ClassCastException occurs.

Is it possible to migrate the code not to use the equals method? I think you don’t want to compare the type (hierachy) of the class and not the instance itself, don’t you?

I have to admit we don’t have this problem on every WebSphere environment, but from time to time it occurs…

Kind regards

I see you made a jira issue http://liquibase.jira.com/browse/CORE-894. Thanks. I’ll take a look and update that issue.


Yes, I’m not sure, if it’s a classloader issue… I anyway, this ClassCastException occurs and multiple classloaders are the only reason I can imagine…