play-liquibase
play-liquibase copied to clipboard
2.2 fails with a NullPointerException if more than one database is configured
I am not up on scala, but from what I can see including stepping through the debugger, PlayLiquibase.liquibase() throws an NPE if more than one db is configured, because in that case dbCfg is null via singleJdbcDatabaseConfig and dbCfg.flatMap() is subsequently unconditionally invoked. See the two 'NPE' comments below:
protected def liquibase(): Option[Liquibase] = { var missingRequiredParam = false
/** get p parameter from cfg.
* If not found use defValue
*
* @param p parameter get value for
* @param defValue default value
* @param cfg configuration the value shall be taken from
* @return null if not set or trimmed to an empty string
*/
def getRequiredParam(p: Param, defValue: Option[String] = None)
(implicit cfg: Option[Configuration]): String = {
val ret = getParam(p, defValue)(cfg)
if (null == ret) {
missingRequiredParam = true
log.warn(s"Missing required configuration parameter: $p")
}
ret
}
implicit val liquibaseConfOpt: Option[Configuration] = config.getOptional[Configuration]("liquibase")
// NPE: if more than one db is configured, singleJdbcDatabaseConfig returns null:
val dbCfg = singleJdbcDatabaseConfig
// NPE: if more than one db is configured, dbCfg is null and .flatMap() results an NPE:
val url = getRequiredParam(Param.url, dbCfg.flatMap(_.url))
val driver = getRequiredParam(Param.driver, dbCfg.flatMap(_.driver))
...
}