liquibase.command.CommandExecutionException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Description
Environment
Java 8, Maven, Spring Boot, MySQL
Activity

Christian Schwarz December 18, 2019 at 10:10 PMEdited
We are also encountering a similar issue, exclusively on MySQL.
db_changelogs/changelog.xml : liquibase.precondition.core.ViewExistsPrecondition@737bfc7f : String index out of range: -1 at [...]
After analysing the affected systems, we figured out that this relates to MySQLs automatic generation of the SECURITY DEFINER in all createView changeSets. In case the user trying to access the view is not covered by that specific definer, the above issue occurs. This can happen for example, if the database user was changed since a specific view required for the changeSet was created. In our case, the recreation of the views with a matching SECURITY DEFINER solved the issue.

Krystian Buszkowski August 28, 2019 at 12:28 PMEdited
I also found this problem and spend on it many hours looking for solution. My database has multi-tenancy basing on views so Liquibase was completely not working for me. After investigation I found working version which was 3.3.5, then I test all versions from 3.4.0 up to 3.8.0 and all have this bug. Exception is thrown from liquibase-core/liquibase/snapshot/jvm/ViewSnapshotGenerator.class, line 87
code:
int length = definition.length();
if (definition.charAt(length - 1) == 0) <-- Exception thrown here
{
definition = definition.substring(0, length - 1);
}
After deleting all views, program is generating change set normally.
Full exception output:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.8.0:generateChangeLog (default-cli) on project ae.pkcv.fleetmgmt-java-api: Error setting up or running Liquibase: liquibase.command.CommandExecutionException: java.lang.StringIndexOutOfBoundsExce
ption: String index out of range: -1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.8.0:generateChangeLog (default-cli) on project ae.pkcv.fleetmgmt-java-api: Error setting up or running Liquibase: liquibase.command.CommandExecutio
nException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error setting up or running Liquibase: liquibase.command.CommandExecutionException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:375)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:282)
at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:251)
at org.liquibase.maven.plugins.LiquibaseGenerateChangeLogMojo.performLiquibaseTask(LiquibaseGenerateChangeLogMojo.java:112)
at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:371)
... 22 more
Caused by: liquibase.command.CommandExecutionException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:24)
at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:280)
... 25 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.charAt(String.java:658)
at liquibase.snapshot.jvm.ViewSnapshotGenerator.snapshotObject(ViewSnapshotGenerator.java:87)
at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:66)
at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:49)
at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:69)
at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:49)
at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:69)
at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:49)
at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:315)
at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:436)
at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:458)
at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:363)
at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:338)
at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:106)
at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:59)
at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:39)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:217)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:190)
at liquibase.command.core.DiffCommand.createReferenceSnapshot(DiffCommand.java:221)
at liquibase.command.core.DiffCommand.createDiffResult(DiffCommand.java:143)
at liquibase.command.core.GenerateChangeLogCommand.run(GenerateChangeLogCommand.java:46)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:19)
... 26 more
Sergejs Visockis January 13, 2019 at 12:51 PM
This issue was solved. Liquibase cannot create changeset from database with views created. I have deleted this views copying SQL and it was able to generate changelog after that I have executed SQL to create views back. And after that manually added SQL to create views into the xml changeset
I am trying to export database schema into the liquibase changelog xml file using maven plugin running command - mvn liquibase:generateChangeLog but I always get "Error setting up or running Liquibase: liquibase.command.CommandExecutionException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1"
Could you explain what kind of problem does it might be? Or maybe it is a bug?
What are the probable reasons of this String out of bounds in this case?