java.lang.NullPointerException

JIRA | tozanni | 8 years ago
  1. 0

    Transferred from Sourceforge: artifact_id: 2052055 submitted_by: tozanni assigned_to: nobody priority: 4 resolution: None open_date: 1218747123 aftifact_type: Bugs category: None artifact_group_id: None category: None status: Open history: priority51231313032nvoxland messages: priority51231313032nvoxland In release 1.7, if you do a diff command for two MySQL databases and you have an unexpected column of type ENUM in the base table, migration would fail by "unknown reason", however the cause is a null pointer exception: java.lang.NullPointerException at liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue(MySqlDatabaseSnapshot.java:95) at liquibase.database.structure.SqlDatabaseSnapshot.readColumns(SqlDatabaseSnapshot.java:263) at liquibase.database.structure.SqlDatabaseSnapshot.<init>(SqlDatabaseSnapshot.java:82) at liquibase.database.structure.MySqlDatabaseSnapshot.<init>(MySqlDatabaseSnapshot.java:55) at liquibase.database.MySQLDatabase.createDatabaseSnapshot(MySQLDatabase.java:155) at liquibase.diff.Diff.compare(Diff.java:68) The call is: columnInfo.setTypeName(tableSchema.get(columnName).get(0)); The problem seems to be that previously the tableSchema is retrieved from schemaCache, but will fail because the column won't be on the cached schema (it'll only appear on the target database which haven't been cached) I solved it provisionally by disabling the schemaCache and always using the last parsed schema to process ENUM and SET columns, but you better do it the right way. Base schema: CREATE TABLE `user_items` ( `id_domain` varchar(64) NOT NULL default '', `id_item` int(11) NOT NULL default '0', `id_user` varchar(64) NOT NULL default '', `visible` enum('true','false') NOT NULL default 'true', PRIMARY KEY (`id_domain`,`id_item`), KEY `id_user` (`id_user`), KEY `visible` (`visible`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Target schema: CREATE TABLE `user_items` ( `id_domain` varchar(64) NOT NULL default '', `id_item` int(11) NOT NULL default '0', `id_user` varchar(64) NOT NULL default '', PRIMARY KEY (`id_domain`,`id_item`,`id_user`), KEY `id_item` (`id_item`), KEY `id_user` (`id_user`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    JIRA | 8 years ago | tozanni
    java.lang.NullPointerException
  2. 0

    Transferred from Sourceforge: artifact_id: 2052055 submitted_by: tozanni assigned_to: nobody priority: 4 resolution: None open_date: 1218747123 aftifact_type: Bugs category: None artifact_group_id: None category: None status: Open history: priority51231313032nvoxland messages: priority51231313032nvoxland In release 1.7, if you do a diff command for two MySQL databases and you have an unexpected column of type ENUM in the base table, migration would fail by "unknown reason", however the cause is a null pointer exception: java.lang.NullPointerException at liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue(MySqlDatabaseSnapshot.java:95) at liquibase.database.structure.SqlDatabaseSnapshot.readColumns(SqlDatabaseSnapshot.java:263) at liquibase.database.structure.SqlDatabaseSnapshot.<init>(SqlDatabaseSnapshot.java:82) at liquibase.database.structure.MySqlDatabaseSnapshot.<init>(MySqlDatabaseSnapshot.java:55) at liquibase.database.MySQLDatabase.createDatabaseSnapshot(MySQLDatabase.java:155) at liquibase.diff.Diff.compare(Diff.java:68) The call is: columnInfo.setTypeName(tableSchema.get(columnName).get(0)); The problem seems to be that previously the tableSchema is retrieved from schemaCache, but will fail because the column won't be on the cached schema (it'll only appear on the target database which haven't been cached) I solved it provisionally by disabling the schemaCache and always using the last parsed schema to process ENUM and SET columns, but you better do it the right way. Base schema: CREATE TABLE `user_items` ( `id_domain` varchar(64) NOT NULL default '', `id_item` int(11) NOT NULL default '0', `id_user` varchar(64) NOT NULL default '', `visible` enum('true','false') NOT NULL default 'true', PRIMARY KEY (`id_domain`,`id_item`), KEY `id_user` (`id_user`), KEY `visible` (`visible`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Target schema: CREATE TABLE `user_items` ( `id_domain` varchar(64) NOT NULL default '', `id_item` int(11) NOT NULL default '0', `id_user` varchar(64) NOT NULL default '', PRIMARY KEY (`id_domain`,`id_item`,`id_user`), KEY `id_item` (`id_item`), KEY `id_user` (`id_user`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    JIRA | 8 years ago | tozanni
    java.lang.NullPointerException
  3. 0

    Transferred from Sourceforge: artifact_id: 2420388 submitted_by: refragtor assigned_to: nvoxland priority: 5 resolution: Fixed open_date: 1229081787 aftifact_type: Bugs category: None artifact_group_id: None category: None status: Closed history: close_date01230924465nvoxland assigned_to1001230924465nvoxland resolution_id1001230924465nvoxland status_id11230924465nvoxland messages: close_date01230924465nvoxland assigned_to1001230924465nvoxland resolution_id1001230924465nvoxland status_id11230924465nvoxland If you creating a table with following field: CREATE TABLE TEST ( TIME_STARTED TIMESTAMP NULL DEFAULT NULL ); you get an NullPointerException on every action: $ liquibase --driver=com.mysql.jdbc.Driver --classpath=mysql-connector-java-5.1.7-bin.jar --logLevel=finest --url="jdbc:mysql://localhost:3306/liquibase" --username=liquibase --password=liquibase generateChangeLog Reading tables for liquibase @ jdbc:mysql://localhost:3306/liquibase ... Reading foreign keys for liquibase @ jdbc:mysql://localhost:3306/liquibase ... Reading primary keys for liquibase @ jdbc:mysql://localhost:3306/liquibase ... Reading columns for liquibase @ jdbc:mysql://localhost:3306/liquibase ... Migration Failed: Unknown Reason. For more information, use the --logLevel flag) 12.12.2008 12:20:48 liquibase.commandline.Main main SCHWERWIEGEND: Unknown Reason java.lang.NullPointerException at liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue(MySqlDatabaseSnapshot.java:112) at liquibase.database.structure.SqlDatabaseSnapshot.readColumns(SqlDatabaseSnapshot.java:275) at liquibase.database.structure.SqlDatabaseSnapshot.<init>(SqlDatabaseSnapshot.java:85) at liquibase.database.structure.MySqlDatabaseSnapshot.<init>(MySqlDatabaseSnapshot.java:55) at liquibase.database.MySQLDatabase.createDatabaseSnapshot(MySQLDatabase.java:163) at liquibase.diff.Diff.compare(Diff.java:61) at liquibase.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:128) at liquibase.commandline.Main.doMigration(Main.java:578) at liquibase.commandline.Main.main(Main.java:90) But if I using this table, liquibase works fine: CREATE TABLE TEST ( TIME_STARTED TIMESTAMP ); and build this changelog: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.8 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.8.xsd"> <changeSet author="Name (generated)" id="1229080930837-1"> <createTable tableName="test"> <column defaultValueDate="CURRENT_TIMESTAMP" name="TIME_STARTED" type="TIMESTAMP"> <constraints nullable="false"/> </column> </createTable> </changeSet> </databaseChangeLog>

    JIRA | 8 years ago | refragtor
    java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    MySqlDatabaseSnapshot throws NPE when "enum" or "timestamp" column was removed from table. It happens because the class uses a static schemaCache and the key is a table name. Durind diff operation ("base" database processing) the cache contains schema for destination database and therefore can't get column data in lines 93 and 112: 93: ... tableSchema.get(columnName).get(0) 112: ... tableSchema.get(columnName).get(1) tableSchema.get(columnName) returns null and we are getting nasty NPE. Steps to reproduce: create database with tables: create database foo1; use foo1; CREATE TABLE `barenum` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '', `flag` enum('Y','N') DEFAULT 'N' ); CREATE TABLE `barts` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '', `createts` timestamp ); create database foo2; use foo1; CREATE TABLE `barenum` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '' ); CREATE TABLE `barts` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '' ); Run diff operation: liqubase.sh --driver=com.mysql.jdbc.Driver \ --url=jdbc:mysql://localhost/foo2 \ --username=root \ --password=XXXXXXX \ diff \ --baseUrl=jdbc:mysql://localhost/foo1 \ --baseUsername=root \ --basePassword=XXXXXXX The result: Reading primary keys for root @ jdbc:mysql://localhost/foo2 ... Reading columns for root @ jdbc:mysql://localhost/foo2 ... Reading unique constraints for root @ jdbc:mysql://localhost/foo2 ... Reading indexes for root @ jdbc:mysql://localhost/foo2 ... Reading sequences for root @ jdbc:mysql://localhost/foo2 ... Reading tables for root @ jdbc:mysql://localhost/foo1 ... Reading foreign keys for root @ jdbc:mysql://localhost/foo1 ... Reading primary keys for root @ jdbc:mysql://localhost/foo1 ... Reading columns for root @ jdbc:mysql://localhost/foo1 ... Migration Failed: Unknown Reason. For more information, use the --logLevel flag) Jul 21, 2009 5:16:24 PM liquibase.commandline.Main main SEVERE: Unknown Reason java.lang.NullPointerException at liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue(MySqlDatabaseSnapshot.java:93) at liquibase.database.structure.SqlDatabaseSnapshot.readColumns(SqlDatabaseSnapshot.java:287) at liquibase.database.structure.SqlDatabaseSnapshot.<init>(SqlDatabaseSnapshot.java:91) at liquibase.database.structure.MySqlDatabaseSnapshot.<init>(MySqlDatabaseSnapshot.java:55) at liquibase.database.MySQLDatabase.createDatabaseSnapshot(MySQLDatabase.java:163) at liquibase.diff.Diff.compare(Diff.java:69) at liquibase.commandline.CommandLineUtils.doDiff(CommandLineUtils.java:108) at liquibase.commandline.Main.doMigration(Main.java:581) at liquibase.commandline.Main.main(Main.java:95) Quick and simple fix: Concatenate database name and table name an use it as schema cache key. ... String cacheKey = database + tableName; if (!schemaCache.containsKey(cacheKey)) { Statement selectStatement = database.getConnection().createStatement(); ResultSet rsColumnType = selectStatement.executeQuery("DESC "+database.escapeTableName(schemaName, tableName)); while(rsColumnType.next()) { List<String> colSchema = new ArrayList<String>(); colSchema.add(rsColumnType.getString("Type")); colSchema.add(rsColumnType.getString("Default")); tableSchema.put(rsColumnType.getString("Field"), colSchema); } rsColumnType.close(); schemaCache.put(cacheKey, tableSchema); } tableSchema = schemaCache.get(cacheKey); ...

    JIRA | 7 years ago | Vladimir Aleksandrov
    java.lang.NullPointerException
  6. 0

    MySqlDatabaseSnapshot throws NPE when "enum" or "timestamp" column was removed from table. It happens because the class uses a static schemaCache and the key is a table name. Durind diff operation ("base" database processing) the cache contains schema for destination database and therefore can't get column data in lines 93 and 112: 93: ... tableSchema.get(columnName).get(0) 112: ... tableSchema.get(columnName).get(1) tableSchema.get(columnName) returns null and we are getting nasty NPE. Steps to reproduce: create database with tables: create database foo1; use foo1; CREATE TABLE `barenum` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '', `flag` enum('Y','N') DEFAULT 'N' ); CREATE TABLE `barts` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '', `createts` timestamp ); create database foo2; use foo1; CREATE TABLE `barenum` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '' ); CREATE TABLE `barts` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(32) NOT NULL DEFAULT '' ); Run diff operation: liqubase.sh --driver=com.mysql.jdbc.Driver \ --url=jdbc:mysql://localhost/foo2 \ --username=root \ --password=XXXXXXX \ diff \ --baseUrl=jdbc:mysql://localhost/foo1 \ --baseUsername=root \ --basePassword=XXXXXXX The result: Reading primary keys for root @ jdbc:mysql://localhost/foo2 ... Reading columns for root @ jdbc:mysql://localhost/foo2 ... Reading unique constraints for root @ jdbc:mysql://localhost/foo2 ... Reading indexes for root @ jdbc:mysql://localhost/foo2 ... Reading sequences for root @ jdbc:mysql://localhost/foo2 ... Reading tables for root @ jdbc:mysql://localhost/foo1 ... Reading foreign keys for root @ jdbc:mysql://localhost/foo1 ... Reading primary keys for root @ jdbc:mysql://localhost/foo1 ... Reading columns for root @ jdbc:mysql://localhost/foo1 ... Migration Failed: Unknown Reason. For more information, use the --logLevel flag) Jul 21, 2009 5:16:24 PM liquibase.commandline.Main main SEVERE: Unknown Reason java.lang.NullPointerException at liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue(MySqlDatabaseSnapshot.java:93) at liquibase.database.structure.SqlDatabaseSnapshot.readColumns(SqlDatabaseSnapshot.java:287) at liquibase.database.structure.SqlDatabaseSnapshot.<init>(SqlDatabaseSnapshot.java:91) at liquibase.database.structure.MySqlDatabaseSnapshot.<init>(MySqlDatabaseSnapshot.java:55) at liquibase.database.MySQLDatabase.createDatabaseSnapshot(MySQLDatabase.java:163) at liquibase.diff.Diff.compare(Diff.java:69) at liquibase.commandline.CommandLineUtils.doDiff(CommandLineUtils.java:108) at liquibase.commandline.Main.doMigration(Main.java:581) at liquibase.commandline.Main.main(Main.java:95) Quick and simple fix: Concatenate database name and table name an use it as schema cache key. ... String cacheKey = database + tableName; if (!schemaCache.containsKey(cacheKey)) { Statement selectStatement = database.getConnection().createStatement(); ResultSet rsColumnType = selectStatement.executeQuery("DESC "+database.escapeTableName(schemaName, tableName)); while(rsColumnType.next()) { List<String> colSchema = new ArrayList<String>(); colSchema.add(rsColumnType.getString("Type")); colSchema.add(rsColumnType.getString("Default")); tableSchema.put(rsColumnType.getString("Field"), colSchema); } rsColumnType.close(); schemaCache.put(cacheKey, tableSchema); } tableSchema = schemaCache.get(cacheKey); ...

    JIRA | 7 years ago | Vladimir Aleksandrov
    java.lang.NullPointerException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue()
    2. liquibase.database.structure
      MySqlDatabaseSnapshot.<init>
      1. liquibase.database.structure.MySqlDatabaseSnapshot.getColumnTypeAndDefValue(MySqlDatabaseSnapshot.java:95)
      2. liquibase.database.structure.SqlDatabaseSnapshot.readColumns(SqlDatabaseSnapshot.java:263)
      3. liquibase.database.structure.SqlDatabaseSnapshot.<init>(SqlDatabaseSnapshot.java:82)
      4. liquibase.database.structure.MySqlDatabaseSnapshot.<init>(MySqlDatabaseSnapshot.java:55)
      4 frames
    3. Liquibase Core
      Diff.compare
      1. liquibase.database.MySQLDatabase.createDatabaseSnapshot(MySQLDatabase.java:155)
      2. liquibase.diff.Diff.compare(Diff.java:68)
      2 frames