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

CauseParameterInExceptionCheck: ArrayIndexOutOfBoundsException #589

Closed
rnveach opened this issue May 26, 2017 · 1 comment
Closed

CauseParameterInExceptionCheck: ArrayIndexOutOfBoundsException #589

rnveach opened this issue May 26, 2017 · 1 comment
Labels
Milestone

Comments

@rnveach
Copy link
Contributor

@rnveach rnveach commented May 26, 2017

Identified at #571 (comment) , and was able to reproduce with the latest version of checkstyle in report http://rveach.no-ip.org/checkstyle/regression/reports/61/apache-ant/index.html#A4

Got an exception - java.lang.ArrayIndexOutOfBoundsException: 586
at com.puppycrawl.tools.checkstyle.api.AbstractCheck.log(AbstractCheck.java:253)
at com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter.log(AbstractViolationReporter.java:144)
at com.github.sevntu.checkstyle.checks.design.CauseParameterInExceptionCheck.finishTree(CauseParameterInExceptionCheck.java:174)

Exception is happening because the field exceptionClassesToWarn isn't being cleared when processing multiple files when an exception is thrown on the previous file's run. The problem is only surfacing because of haltOnException being off.
finishTree shouldn't be used to reset instance fields. It is not guaranteed to always be called, like on an exception.

Here is the source of the checkstyle-result.xml:

<file name="/home/ricky/opensource/contribution/checkstyle-tester/reports/saverefs/apache-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java">
<error line="0" severity="error" message="Got an exception - java.lang.NullPointerException&#10;	at com.github.sevntu.checkstyle.checks.coding.NoNullForCollectionReturnCheck.getMethodDef(NoNullForCollectionReturnCheck.java:355)&#10;	at com.github.sevntu.checkstyle.checks.coding.NoNullForCollectionReturnCheck.visitToken(NoNullForCollectionReturnCheck.java:147)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:363)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:500)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:305)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:180)&#10;	at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)&#10;	at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:316)&#10;	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:286)&#10;	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)&#10;	at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:252)&#10;	at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)&#10;	at org.apache.maven.plugin.checkstyle.CheckstyleReport.executeReport(CheckstyleReport.java:154)&#10;	at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)&#10;	at org.apache.maven.plugins.site.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:219)&#10;	at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderModule(DefaultSiteRenderer.java:319)&#10;	at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:135)&#10;	at org.apache.maven.plugins.site.SiteMojo.renderLocale(SiteMojo.java:175)&#10;	at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:138)&#10;	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)&#10;	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)&#10;	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)&#10;	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)&#10;	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)&#10;	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)&#10;	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)&#10;	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)&#10;	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)&#10;	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)&#10;	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)&#10;	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)&#10;	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)&#10;	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)&#10;	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)&#10;	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)&#10;	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&#10;	at java.lang.reflect.Method.invoke(Method.java:498)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)&#10;" source="com.puppycrawl.tools.checkstyle.Checker"/>
</file>
<file name="/home/ricky/opensource/contribution/checkstyle-tester/reports/saverefs/apache-ant/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java">
<error line="0" severity="error" message="Got an exception - java.lang.ArrayIndexOutOfBoundsException: 586&#10;	at com.puppycrawl.tools.checkstyle.api.AbstractCheck.log(AbstractCheck.java:253)&#10;	at com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter.log(AbstractViolationReporter.java:144)&#10;	at com.github.sevntu.checkstyle.checks.design.CauseParameterInExceptionCheck.finishTree(CauseParameterInExceptionCheck.java:174)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.notifyEnd(TreeWalker.java:349)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:307)&#10;	at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:180)&#10;	at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)&#10;	at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:316)&#10;	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:286)&#10;	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)&#10;	at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:252)&#10;	at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)&#10;	at org.apache.maven.plugin.checkstyle.CheckstyleReport.executeReport(CheckstyleReport.java:154)&#10;	at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)&#10;	at org.apache.maven.plugins.site.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:219)&#10;	at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderModule(DefaultSiteRenderer.java:319)&#10;	at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:135)&#10;	at org.apache.maven.plugins.site.SiteMojo.renderLocale(SiteMojo.java:175)&#10;	at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:138)&#10;	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)&#10;	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)&#10;	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)&#10;	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)&#10;	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)&#10;	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)&#10;	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)&#10;	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)&#10;	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)&#10;	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)&#10;	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)&#10;	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)&#10;	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)&#10;	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)&#10;	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)&#10;	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)&#10;	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)&#10;	at java.lang.reflect.Method.invoke(Method.java:498)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)&#10;	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)&#10;" source="com.puppycrawl.tools.checkstyle.Checker"/>
</file>

Reports don't show file's order of execution, only the XML result file does.
Previous file's exception was an NPE in NoNullForCollectionReturnCheck when processing IPlanetEjbc.java.
Once it was fixed, ArrayIndexOutOfBoundsException disappeared from reports.

@romani
Copy link
Member

@romani romani commented May 26, 2017

fix is merged

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

Successfully merging a pull request may close this issue.

None yet
2 participants