NullPointerException when running generateChangeLog using MySQL and Liquibase 3.2.2

I am trying to generate a changeLog using an already existing database so I can begin using Liquibase from this point forward. When running the command 

  1. liquibase --changeLogFile=changelog.xml generateChangeLog

with the following liquibase.properties file

  1. driver: com.mysql.jdbc.Driver
  2. classpath: C:\\Program Files (x86)\\MySQL\\Connector J 5.1.30\\mysql-connector-java-5.1.30-bin.jar
  3. url: jdbc:mysql://localhost/adtest
  4. username: root
  5. password: ***********
  6. logFile: liquibase.txt
  7. logLevel:debug
I get "Unexpected error running Liquibase: java.lang.NullPointerException

The following is an excerpt from the log file

  1. INFO 8/25/14 1:40 PM: liquibase: changelog.xml does not exist, creating
  2. DEBUG 8/25/14 1:40 PM: liquibase: MissingObjectChangeGenerator type order:     liquibase.structure.core.Catalog    liquibase.structure.core.Schema    liquibase.structure.core.Sequence    liquibase.structure.core.StoredProcedure    liquibase.structure.core.Table    liquibase.structure.core.Column    liquibase.structure.core.PrimaryKey    liquibase.structure.core.UniqueConstraint    liquibase.structure.core.ForeignKey    liquibase.structure.core.Index    liquibase.structure.core.View
  3. SEVERE 8/25/14 1:40 PM: liquibase: java.lang.NullPointerException
  4. liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.lang.NullPointerException
  5. at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:139)
  6. at liquibase.integration.commandline.Main.doMigration(Main.java:904)
  7. at liquibase.integration.commandline.Main.run(Main.java:170)
  8. at liquibase.integration.commandline.Main.main(Main.java:89)
  9. Caused by: liquibase.command.CommandExecutionException: java.lang.NullPointerException
  10. at liquibase.command.AbstractCommand.execute(AbstractCommand.java:13)
  11. at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:137)
  12. ... 3 more
  13. Caused by: java.lang.NullPointerException
  14. at liquibase.diff.output.changelog.core.MissingForeignKeyChangeGenerator.fixMissing(MissingForeignKeyChangeGenerator.java:43)
  15. at liquibase.diff.output.changelog.ChangeGeneratorChain.fixMissing(ChangeGeneratorChain.java:44)
  16. at liquibase.diff.output.changelog.ChangeGeneratorFactory.fixMissing(ChangeGeneratorFactory.java:99)
  17. at liquibase.diff.output.changelog.DiffToChangeLog.generateChangeSets(DiffToChangeLog.java:147)
  18. at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:127)
  19. at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:73)
  20. at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:61)
  21. at liquibase.command.GenerateChangeLogCommand.run(GenerateChangeLogCommand.java:54)
  22. at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
  23. ... 4 more
Any help would be greatly appreciated

Thanks for the input Steve. I completely agree with what you said, but I’m using the root account, so permissions shouldn’t be an issue, and I just checked every restraint found in information_schema.table_constraints for the current schema and it refers to table that does exist (checked using SHOW TABLES)

I’m setting up the liquibase code in Eclipse now so I can step through the code to see exactly which fk object has the null pointer. I’m having a little trouble getting it running, but I’ll be sure to report back here with what I find.

-Eddie

Ok, so I was able to track it down. It was a missing table. When I was checking I must have been matching to the wrong column, I thought I was checking the tables the foreign keys were referencing, but it turns out I was just checking the tables the foreign keys were on. 

Thanks again for your help Steve, I really appreciated it.

Looking at the source code mentioned in the stack trace, I see this at liquibase.diff.output.changelog.core.MissingForeignKeyChangeGenerator.fixMissing(MissingForeignKeyChangeGenerator.java:43)

       change.setReferencedTableName(fk.getPrimaryKeyTable().getName());

The ‘change’ object is created in that method, so it cannot be null. The ‘fk’ object mentioned in that line is used in the line before, so it is also not null. That leaves just fk.getPrimaryKeyTable() as the possible null pointer. 

If I had to guess, I would say that somewhere in the database you are trying to generate a changelog for there is a foreign key that refers to a table that is not in the current schema or that the user connecting to the database does not have permissions for. But that is just a guess. 

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Glad I was able to help. 

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/