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

excludedPath generated-sources leads to StringIndexOutOfBoundsException: String index out of range: -1 #49

Closed
1 of 3 tasks
Treehopper opened this issue Jun 2, 2022 · 1 comment

Comments

@Treehopper
Copy link

Treehopper commented Jun 2, 2022

Summary

There are two classes inside target/generated-sources/api/src/main/java matching my ArchUnitRul that I'd like to filter.
In my multi-module project, I used this in the parent-pom as well as the sub-module pom.xml:

            <excludedPaths>
              <excludedPath>generated-sources</excludedPath>
            </excludedPaths>

But I get below error. Unfortunately, I cannot tell which of my classes causes the exception.

Type of Issue

It is a :

  • bug
  • request
  • question regarding the documentation

Motivation

Current Behavior

classes()
          .that().areAnnotatedWith(RestController.class)
          .should().bePackagePrivate()
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.tngtech.archunit</groupId>
        <artifactId>archunit</artifactId>
        <version>0.23.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>com.societegenerale.commons</groupId>
          <artifactId>arch-unit-maven-plugin</artifactId>
          <version>2.9.2</version>
          <configuration>
            <excludedPaths>
              <excludedPath>generated-sources</excludedPath>
            </excludedPaths>

            <rules>
              <configurableRules>
                <configurableRule>

                  <rule>foo.bar.ArchUnitRules</rule>
                  <applyOn>
                    <packageName>foo.bar</packageName>
                    <scope>main</scope>
                  </applyOn>

                  <checks>
                    <check>FOO</check>
                  </checks>
                </configurableRule>
                <configurableRule>
                  <rule>foo.bar.ArchUnitRules</rule>
                  <applyOn>
                    <packageName>foo.bar</packageName>
                    <scope>test</scope>
                  </applyOn>

                  <checks>
                    <check>BAR</check>
                  </checks>
                </configurableRule>
              </configurableRules>
            </rules>
          </configuration>

          <executions>
            <execution>
              <id>arch-test</id>
              <goals>
                <goal>arch-test</goal>
              </goals>
              <phase>test</phase>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
mvn -e test
[ERROR] Failed to execute goal com.societegenerale.commons:arch-unit-maven-plugin:2.9.2:arch-test (arch-test) on project foo: String index out of range: -1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.societegenerale.commons:arch-unit-maven-plugin:2.9.2:arch-test (arch-test) on project foo: String index out of range: -1
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:274)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:196)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:160)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.mvndaemon.mvnd.builder.SmartBuilderImpl.buildProject(SmartBuilderImpl.java:178)
        at org.mvndaemon.mvnd.builder.SmartBuilderImpl$ProjectBuildTask.run(SmartBuilderImpl.java:198)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.apache.maven.plugin.MojoFailureException: String index out of range: -1
        at com.societegenerale.commons.plugin.maven.ArchUnitMojo.execute(ArchUnitMojo.java:98)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:271)
        ... 11 common frames omitted
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.base/java.lang.String.substring(String.java:1837)
        at com.societegenerale.commons.plugin.service.JavaFileParser.extractClassName(JavaFileParser.java:124)
        at com.societegenerale.commons.plugin.service.JavaFileParser.parse(JavaFileParser.java:44)
        at com.societegenerale.commons.plugin.service.ExcludedPathsPreProcessor.determineClassNames(ExcludedPathsPreProcessor.java:194)
        at com.societegenerale.commons.plugin.service.ExcludedPathsPreProcessor.processExcludedPaths(ExcludedPathsPreProcessor.java:65)
        at com.societegenerale.commons.plugin.service.RuleInvokerService.<init>(RuleInvokerService.java:49)
        at com.societegenerale.commons.plugin.maven.ArchUnitMojo.execute(ArchUnitMojo.java:94)
        ... 13 common frames omitted

Expected Behavior

See: #44

No exception, and generated code filtered.

Steps to Reproduce (for bugs)

See above

Your Environment

  • arch-unit-maven-plugin: 2.9.2
  • archunit: 0.23.1
  • Maven 3.8.3
  • JDK 11
@vincent-fuchs
Copy link
Contributor

this should be fixed with v2.9.3 - please give it a try and close the issue if it works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants