Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #4410

Closed
edysli opened this issue Aug 13, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@edysli
Copy link

edysli commented Aug 13, 2024

What version of OpenRewrite are you using?

I am using

  • OpenRewrite (whichever version the Maven plugin uses, it doesn't say)
  • Maven plugin v.5.38.1
  • rewrite-migrate-java v2.21.0
  • rewrite-spring v5.16.0
  • rewrite-testing-frameworks v2.15.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a multi-module project. The error happens on one module and the parent project, but not on another module.

<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>5.38.1</version>
  <dependencies>
    <dependency>
      <groupId>org.openrewrite.recipe</groupId>
      <artifactId>rewrite-migrate-java</artifactId>
      <version>2.21.0</version>
    </dependency>
    <dependency>
      <groupId>org.openrewrite.recipe</groupId>
      <artifactId>rewrite-spring</artifactId>
      <version>5.16.0</version>
    </dependency>
    <dependency>
      <groupId>org.openrewrite.recipe</groupId>
      <artifactId>rewrite-testing-frameworks</artifactId>
      <version>2.15.0</version>
    </dependency>
    </dependencies>
    <configuration>
      <activeRecipes>
        <recipe>org.openrewrite.java.format.AutoFormat</recipe>
        <recipe>org.openrewrite.java.format.EmptyNewlineAtEndOfFile</recipe>
        <recipe>org.openrewrite.java.format.RemoveTrailingWhitespace</recipe>
        <recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
        <recipe>org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration</recipe>
        <recipe>org.openrewrite.java.spring.boot3.SpringBoot3BestPractices</recipe>
        <recipe>org.openrewrite.java.testing.assertj.Assertj</recipe>
        <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
        <recipe>org.openrewrite.maven.BestPractices</recipe>
      </activeRecipes>
      <activeStyles>
        <style>org.openrewrite.java.GoogleJavaFormat</style>
      </activeStyles>
    </configuration>
</plugin>

What is the smallest, simplest way to reproduce the problem?

The logs don't say when or on which file the error happened, so it don't know of a way to reproduce this.

What is the full stack trace of any errors you encountered?

Running mvn -e -X rewrite:run produces:

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.38.1:run (default-cli) on project XXXX: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.38.1:run failed: Index 0 out of bounds for length 0 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.38.1:run (default-cli) on project user-profiler: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.38.1:run failed: Index 0 out of bounds for length 0
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:903)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:280)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.38.1:run failed: Index 0 out of bounds for length 0
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:133)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:903)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:280)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at jdk.internal.util.Preconditions$1.apply (Preconditions.java:55)
    at jdk.internal.util.Preconditions$1.apply (Preconditions.java:52)
    at jdk.internal.util.Preconditions$4.apply (Preconditions.java:213)
    at jdk.internal.util.Preconditions$4.apply (Preconditions.java:210)
    at jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:98)
    at jdk.internal.util.Preconditions.outOfBoundsCheckIndex (Preconditions.java:106)
    at jdk.internal.util.Preconditions.checkIndex (Preconditions.java:302)
    at java.lang.String.checkIndex (String.java:4832)
    at java.lang.StringLatin1.charAt (StringLatin1.java:46)
    at java.lang.String.charAt (String.java:1555)
    at org.openrewrite.java.marker.JavaSourceSet.isDeclarable (JavaSourceSet.java:333)
    at org.openrewrite.java.marker.JavaSourceSet.typesFromPath (JavaSourceSet.java:281)
    at org.openrewrite.java.marker.JavaSourceSet.build (JavaSourceSet.java:210)
    at org.openrewrite.maven.MavenMojoProjectParser.sourceSet (MavenMojoProjectParser.java:512)
    at org.openrewrite.maven.MavenMojoProjectParser.processMainSources (MavenMojoProjectParser.java:422)
    at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:178)
    at org.openrewrite.maven.MavenMojoProjectParser.lambda$listSourceFiles$0 (MavenMojoProjectParser.java:150)
    at java.util.stream.ReferencePipeline$7$1.accept (ReferencePipeline.java:273)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1708)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:499)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:921)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:682)
    at org.openrewrite.maven.AbstractRewriteBaseRunMojo.sourcesWithAutoDetectedStyles (AbstractRewriteBaseRunMojo.java:251)
    at org.openrewrite.maven.AbstractRewriteBaseRunMojo.loadSourceSet (AbstractRewriteBaseRunMojo.java:213)
    at org.openrewrite.maven.AbstractRewriteBaseRunMojo.listResults (AbstractRewriteBaseRunMojo.java:128)
    at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:63)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:903)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:280)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
@edysli edysli added the bug Something isn't working label Aug 13, 2024
@timtebeek
Copy link
Contributor

Fixed with the releases linked here:
https://github.com/openrewrite/rewrite-recipe-bom/releases/tag/v2.17.0

@edysli
Copy link
Author

edysli commented Aug 13, 2024

Thanks @timtebeek! :) I'll try with the latest version.

I had had a look at the releases notes before filing this issue, however nothing seemed related to this.

@timtebeek
Copy link
Contributor

No worries; there's a lot of changes all coming together in our two weekly releases; the particular issue here was fixed in

@edysli
Copy link
Author

edysli commented Aug 13, 2024

It works with the Maven plugin version 5.39.0. Thanks for the explanation and sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants