java.lang.ClassCastException: java.lang.String cannot be cast to liquibase.structure.core.Column
Description
Environment
Windows / oracle 11g
Attachments
discovered while testing
Activity

Pramod kumar March 23, 2017 at 12:44 PM
Hi Team
I am hitting below liquibase error, which is unable to parse the json file.
liquibase.exception.LiquibaseParseException: liquibase.parser.core.ParsedNodeExc
eption: liquibase.exception.UnexpectedLiquibaseException: java.lang.reflect.Invo
cationTargetException
at liquibase.parser.core.yaml.YamlSnapshotParser.parse(YamlSnapshotParse
r.java:58)
at liquibase.database.OfflineConnection.<init>(OfflineConnection.java:88
)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.jav
a:172)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:
151)
at com.vmware.cpd.dbcc.CommandLineUtils.createDatabaseObject(CommandLine
Utils.java:92)
at com.vmware.cpd.dbcc.Main.DBSchemaDiff(Main.java:3791)
at com.vmware.core.dbcc.apis.DBCCAPI.findSchemaDiff(DBCCAPI.java:70)
at com.vmware.skyscraper.dbcc.DBCCExt.menuOption(DBCCExt.java:354)
at com.vmware.skyscraper.dbcc.DBCCExt.main(DBCCExt.java:158)
Caused by: liquibase.parser.core.ParsedNodeException: liquibase.exception.Unexpe
ctedLiquibaseException: java.lang.reflect.InvocationTargetException
at liquibase.snapshot.DatabaseSnapshot.load(DatabaseSnapshot.java:444)
at liquibase.parser.core.yaml.YamlSnapshotParser.parse(
r.java:51)
... 8 more
Caused by: liquibase.exception.UnexpectedLiquibaseException: java.lang.reflect.I
nvocationTargetException
at liquibase.util.ObjectUtil.setProperty(ObjectUtil.java:105)
at liquibase.snapshot.DatabaseSnapshot.load(DatabaseSnapshot.java:424)
... 9 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at liquibase.util.ObjectUtil.setProperty(ObjectUtil.java:99)
... 10 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to liqu
ibase.structure.core.Table
at liquibase.structure.core.ForeignKey.getPrimaryKeyTable(ForeignKey.jav
a:65)
at liquibase.structure.core.ForeignKey.setPrimaryKeyColumns(ForeignKey.j
ava:87)
... 15 more
liquibase.exception.DatabaseException: liquibase.exception.UnexpectedLiquibaseEx
ception: Cannot parse snapshot offline:mssql?snapshot=C:\Users\ADMINI~1\AppData\
Local\Temp\2\dbcc5331524904812021565\vc_6.5_sqlserver_CUSTOM.json
at com.vmware.cpd.dbcc.CommandLineUtils.createDatabaseObject(CommandLine
Utils.java:166)
at com.vmware.cpd.dbcc.Main.DBSchemaDiff(Main.java:3791)
at com.vmware.core.dbcc.apis.DBCCAPI.findSchemaDiff(DBCCAPI.java:70)
at com.vmware.skyscraper.dbcc.DBCCExt.menuOption(DBCCExt.java:354)
at com.vmware.skyscraper.dbcc.DBCCExt.main(DBCCExt.java:158)
Caused by: liquibase.exception.UnexpectedLiquibaseException: Cannot parse snapsh
ot offline:mssql?snapshot=C:\Users\ADMINI~1\AppData\Local\Temp\2\dbcc53315249048
12021565\vc_6.5_sqlserver_CUSTOM.json
at liquibase.database.OfflineConnection.<init>(OfflineConnection.java:99
)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.jav
a:172)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:
151)
at com.vmware.cpd.dbcc.CommandLineUtils.createDatabaseObject(CommandLine
Utils.java:92)
... 4 more
Caused by: liquibase.exception.LiquibaseParseException: liquibase.parser.core.Pa
rsedNodeException: liquibase.exception.UnexpectedLiquibaseException: java.lang.r
eflect.InvocationTargetException
at liquibase.parser.core.yaml.YamlSnapshotParser.parse(YamlSnapshotParse
r.java:58)
at liquibase.database.OfflineConnection.<init>(OfflineConnection.java:88
)
... 7 more
Caused by: liquibase.parser.core.ParsedNodeException: liquibase.exception.Unexpe
ctedLiquibaseException: java.lang.reflect.InvocationTargetException
at liquibase.snapshot.DatabaseSnapshot.load(DatabaseSnapshot.java:444)
at liquibase.parser.core.yaml.YamlSnapshotParser.parse(YamlSnapshotParse
r.java:51)
... 8 more
Caused by: liquibase.exception.UnexpectedLiquibaseException: java.lang.reflect.I
nvocationTargetException
at liquibase.util.ObjectUtil.setProperty(ObjectUtil.java:105)
at liquibase.snapshot.DatabaseSnapshot.load(DatabaseSnapshot.java:424)
... 9 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at liquibase.util.ObjectUtil.setProperty(ObjectUtil.java:99)
... 10 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to liqu
ibase.structure.core.Table
at liquibase.structure.core.ForeignKey.getPrimaryKeyTable(ForeignKey.jav
a:65)
at liquibase.structure.core.ForeignKey.setPrimaryKeyColumns(ForeignKey.j
ava:87)
... 15 more

Dennis Cheung October 11, 2016 at 6:01 AM
BUG_ON when it trying to hack, not fix the feature, to backward compatible of abusing API.
Even with the hack, snapshot may still fail.
Suggest to create a snapshot structure like this.
Column.getName should return only the name part, hacking setName() to parse extra ASC / DESC into Column.descending
And remove workaround in dcd70fe13a384907402b2be40368a06f4fbda08a / 1305a10c0be1e47eeed40998c84a87afb99c1a5b

Dennis Cheung October 11, 2016 at 5:45 AM
I am still having the same issue on 3.5.1 with mysql, when the index name suffix with "DESC"
Nathan Voxland November 23, 2015 at 8:38 PM
Duplicate of

Michel Luiz Milezzi October 29, 2015 at 10:32 AMEdited
It seems this is a bug in the following lines:
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/snapshot/jvm/IndexSnapshotGenerator.java#L308
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/snapshot/jvm/IndexSnapshotGenerator.java#L310
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/snapshot/jvm/ForeignKeySnapshotGenerator.java#L129
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/snapshot/jvm/PrimaryKeySnapshotGenerator.java#L60
The problem is that a new instance of column don't have snapshotId populated:
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/serializer/core/yaml/YamlSnapshotSerializer.java#L53
Result: "liquibase.structure.core.Column#null"
Maybe instead of using a new instance of column it's better to reuse the instance of column in the table definition, that already have snapshotId.
Another way to solve this is a simple generate of a new snapshotId (SnapshotIdService.getInstance().generateId()), but I'm not sure about possible side effects.
hi.
i got an "java.lang.ClassCastException: java.lang.String cannot be cast to liquibase.structure.core.Column" when I do a snapshot and, just after, a diff between this snapshot and the same db :
Regards