Uploaded image for project: 'Maven Checkstyle Plugin'
  1. Maven Checkstyle Plugin
  2. MCHECKSTYLE-354

Plugin throws exception on encountering rule: SeparatorWrapDot of Google checkstyle

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 3.0.0
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Java 8
      Apache Maven 3.3.9

      Description

      Version 3.0.0 of the plugin throws below exception if any voilation of rule 'SeparatorWrapDot' is found in the code. I am using Google checks as the ruleset. 

       

      Execution validate of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check fa
      iled: String index out of range: -1
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
      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:309)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
      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.PluginExecutionException: Execution validate of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check failed: String index out of range: -1
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
      ... 20 more
      Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1967)
      at org.apache.maven.plugins.checkstyle.RuleUtil.getCategory(RuleUtil.java:95)
      at org.apache.maven.plugins.checkstyle.CheckstyleViolationCheckMojo.countViolations(CheckstyleViolationCheckMojo.java:646)
      at org.apache.maven.plugins.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:564)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
      ... 21 more
      
      

       

      Reason:

      Implementation of the function which is failing is below:

      Class: RuleUtil

      public static String getCategory( String eventSrcName )
      {
          if ( eventSrcName == null )
          {
              return null;
          }
      
          int end = eventSrcName.lastIndexOf( '.' );
          eventSrcName = eventSrcName.substring( 0,  end );
      
          if ( CHECKSTYLE_PACKAGE.equals( eventSrcName ) )
          {
              return "misc";
          }
          else if ( !eventSrcName.startsWith( CHECKSTYLE_PACKAGE ) )
          {
              return "extension";
          }
      
          return eventSrcName.substring( eventSrcName.lastIndexOf( '.' ) + 1 );
      }
      

      The code 

      eventSrcName = eventSrcName.substring( 0,  end );
      

      The variable end is calculated using the statement:

      int end = eventSrcName.lastIndexOf( '.' );
      

      And for this rule, variable eventSrcName contains 'SeparatorWrapDot'. It DOES NOT contain eny dot in it. so end is -1 which results in:

      String index out of range: -1

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rfscholte Robert Scholte
                Reporter:
                jawwad.farooq Jawwad Farooq
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: