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

ClassNotFoundException when using inherited exception #1192

Closed
rmueller83 opened this issue Jun 8, 2015 · 8 comments
Closed

ClassNotFoundException when using inherited exception #1192

rmueller83 opened this issue Jun 8, 2015 · 8 comments
Assignees
Milestone

Comments

@rmueller83
Copy link

JavadocMethodCheck is used.

I have a custom exception class which extends NestableRuntimeException from commons-lang 2.6:

public class ApplicationException extends NestableRuntimeException { ... }

The custom exception and the code calling it are in my own jar file, while the NestableRuntimeException is in a Maven dependency. When I run checkstyle via maven-checkstyle-plugin, this always results in a stacktrace:

[INFO] Generating "Checkstyle" report           --- maven-checkstyle-plugin:2.15:checkstyle-aggregate
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at com.puppycrawl.tools.checkstyle.checks.ClassResolver.safeLoad(ClassResolver.java:153)
    at com.puppycrawl.tools.checkstyle.checks.ClassResolver.isLoadable(ClassResolver.java:132)
    at com.puppycrawl.tools.checkstyle.checks.ClassResolver.resolveQualifiedName(ClassResolver.java:164)
    at com.puppycrawl.tools.checkstyle.checks.ClassResolver.resolve(ClassResolver.java:83)
    at com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck.resolveClass(AbstractTypeAwareCheck.java:247)
    at com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck.tryLoadClass(AbstractTypeAwareCheck.java:262)
    at com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck$RegularClass.getClazz(AbstractTypeAwareCheck.java:486)
    at com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.checkThrowsTags(JavadocMethodCheck.java:844)
    at com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.checkComment(JavadocMethodCheck.java:439)
    at com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.processAST(JavadocMethodCheck.java:325)
    at com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck.visitToken(AbstractTypeAwareCheck.java:149)
    at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:448)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:541)
    at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:373)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:211)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:73)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:263)
    at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:253)
    at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)
    at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)
    at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:224)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderModule(DefaultSiteRenderer.java:311)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:129)
    at org.apache.maven.plugins.site.render.SiteMojo.renderLocale(SiteMojo.java:182)
    at org.apache.maven.plugins.site.render.SiteMojo.execute(SiteMojo.java:141)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    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:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    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: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 59 more
[INFO] There are 896 errors reported by Checkstyle 6.1.1 with config/sun_checks.xml ruleset.

The same happens with checkstyle 6.7.
A similar issue was posted here: https://groups.google.com/forum/#!topic/checkstyle/9Yae7DL1kdo

@romani
Copy link
Member

romani commented Jun 10, 2015

all functionality base on loading class from classpath is deprecated now (due to a lot of bugs and no reliable way to do that for now) please try to use option suppressLoadErrors with false , http://checkstyle.sourceforge.net/config_javadoc.html#JavadocMethod .

Let me know if that does not help.

@romani romani assigned ivanov-alex and unassigned ivanov-alex Jun 11, 2015
@rmueller83
Copy link
Author

I think you mean to set suppressLoadErrorsto true, since false is the default value. Anyway, this did not help as this setting only seems to suppress the logging call in https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/AbstractTypeAwareCheck.java#L253 but this line is not yet reached as the exception already occurs 2 lines earlier at https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/AbstractTypeAwareCheck.java#L251

@romani
Copy link
Member

romani commented Jun 11, 2015

thanks, if you already see how to fix that please be welcome with PR.

@rmueller83
Copy link
Author

I think it should be sufficient to catch the NoClassDefFoundError in either the isLoadable method of ClassResolver or the resolveClass method of AbstractTypeAwareCheck.
The whole issue confuses me as the error only occurs when I configure checkstyle as a reporting plugin in the root pom.xml, making it run as part of the maven-site-plugin. If I directly run mvn checkstyle:checkstyle, there is no error.

@romani
Copy link
Member

romani commented Jun 11, 2015

That is classpath managmend that checkstyle-maven-plugin provide. Please report additional issue to that project.

@romani
Copy link
Member

romani commented Jun 13, 2015

@Vladlis , please help us with that issue.

Vladlis added a commit to Vladlis/checkstyle that referenced this issue Jun 19, 2015
Vladlis added a commit to Vladlis/checkstyle that referenced this issue Jun 19, 2015
Vladlis added a commit to Vladlis/checkstyle that referenced this issue Jun 21, 2015
@romani
Copy link
Member

romani commented Jun 24, 2015

very strange issue as due to javadoc - only ClassNotFoundException is expected as we use "Class.forName".
https://docs.oracle.com/javase/7/docs/api/java/lang/ClassNotFoundException.html
http://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html

We can not create a test for that as we receive only ClassNotFoundException, so we will do blind extending of code to catch NoClassDefFoundError.

@romani romani added this to the 6.8 milestone Jun 24, 2015
@romani
Copy link
Member

romani commented Jun 24, 2015

merged.

@romani romani closed this as completed Jun 24, 2015
dgtombs added a commit to VHAINNOVATIONS/ASRCM that referenced this issue Aug 24, 2015
I also added some unchecked exceptions to a couple methods' throws declarations
to work around Checkstyle bug 1192[1].

[1] checkstyle/checkstyle#1192
romani added a commit that referenced this issue Mar 5, 2016
romani added a commit that referenced this issue Mar 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants