ClassCastException when executing a custom task change (AntClassLoader problem)

Description

After upgrading from 3.1.1 to 3.2.2 we encounter a ClassCastException when Liquibase tries to parse the changelog files.

BUILD FAILED
xxx\build.xml:2172: liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: liquibase.exception.SetupException: liquibase.exception.SetupException: liquibase.exception.UnexpectedLiquibaseException: java.lang.ClassCastException: x.y.z.liquibase.wrapper.TaskWrapper cannot be cast to liquibase.change.custom.CustomChange

Our x.y.z.liquibase.wrapper.TaskWrapper implements CustomTaskChange which extends CustomChange, so this should be no problem.

After a quick look into the Liquibase code I saw that apparently Liquibase uses a different ClassLoader to load our TaskWrapper class. And because CustomChange was loaded using another ClassLoader, the ClassCastException occurs.

In line 320 in class liquibase.change.custom.CustomChangeWrapper it takes place:
customChange = (CustomChange) Class.forName(className, false, resourceAccessor.toClassLoader()).newInstance();
The ClassLoader returned by resourceAccessor.toClassLoader() seems to be a different one than the one which loaded CustomChange.

By the way, we run Liquibase using the Ant task. I'm not sure if this is related to the problem.

Environment

OS: Win 7 x64
JDK: 1.7.0_65
Databases: H2 1.4, PostgreSQL 9.3, Oracle 11, SQL Server 2012 and 2014

Status

Assignee

Unassigned

Reporter

Marco Perazzo

Labels

None

Components

Fix versions

Affects versions

3.2.2
3.3.0

Priority

Blocker