Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.13
-
None
-
None
Description
Steps to reproduce:
- Add non jar (XML for example) artifact dependency to plugin dependencies section:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.13</version> <dependencies> <dependency> <groupId>anygroup</groupId> <artifactId>anyfile</artifactId> <type>xml</type> </dependency> </dependencies> </plugin>
- Run checkstyle:check
Result:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check (default-cli) on project rt: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check failed. NullPointerException -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check (default-cli) on project rt: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check failed. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224) 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:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214) at org.apache.maven.cli.MavenCli.main(MavenCli.java:158) 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: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check failed. at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 19 common frames omitted Caused by: java.lang.NullPointerException: null at org.codehaus.plexus.resource.loader.JarHolder.getEntries(JarHolder.java:126) at org.codehaus.plexus.resource.loader.JarResourceLoader.loadJar(JarResourceLoader.java:100) at org.codehaus.plexus.resource.loader.JarResourceLoader.initialize(JarResourceLoader.java:63) at org.codehaus.plexus.resource.loader.JarResourceLoader.getResource(JarResourceLoader.java:141) at org.apache.maven.plugin.checkstyle.resource.LicenseResourceManager.getResource(LicenseResourceManager.java:75) at org.codehaus.plexus.resource.DefaultResourceManager.getResourceAsFile(DefaultResourceManager.java:91) at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.getOverridingProperties(DefaultCheckstyleExecutor.java:520) at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.getConfiguration(DefaultCheckstyleExecutor.java:347) at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:220) at org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.execute(CheckstyleViolationCheckMojo.java:532) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106) ... 20 common frames omitted
Investigation:
- CheckstyleViolationCheckMojo forms CheckstyleExecutorRequest for the executor by initializing licenseArtifacts property with all plugin's dependencies.
CheckstyleViolationCheckMojo.java:516
request.setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput ) .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes ) .setResourceIncludes( resourceIncludes ) .setResourceExcludes( resourceExcludes ) .setIncludeResources( includeResources ) .setIncludeTestResources( includeTestResources ) .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() ) .setLog( getLog() ).setProject( project ).setSourceDirectories( getSourceDirectories() ) .setResources( resources ) .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation ) .setTestSourceDirectories( getTestSourceDirectories() ).setConfigLocation( configLocation ) .setConfigurationArtifacts( collectArtifacts( "config" ) ) .setPropertyExpansion( propertyExpansion ) .setHeaderLocation( headerLocation ).setLicenseArtifacts( collectArtifacts( "license" ) ) .setCacheFile( cacheFile ).setSuppressionsFileExpression( suppressionsFileExpression ) .setEncoding( encoding ).setPropertiesLocation( propertiesLocation ); checkstyleExecutor.executeCheckstyle( request );
There is a licence hint parameter passed to dependency initializer, but it is actually not used. Leaving all dependencies being uses as the license one.
- DefaultCheckstyleExecutor adds the dependencies to jar search path without checking the dependency type. I think dependencies should be checked for the jar type:
DefaultCheckstyleExecutor.java:836
// MCHECKSTYLE-225: load licenses from additional artifacts, not from classpath if ( additionalArtifacts != null ) { for ( Artifact licenseArtifact : additionalArtifacts ) { try { resourceManager.addSearchPath( "jar", "jar:" + licenseArtifact.getFile().toURI().toURL() ); } catch ( MalformedURLException e ) { // noop } } }
- Later Plexus JarResourceLoader fails to load the resource from those non jar dependencies:
public void init() { try { URL url = new URL( urlpath ); conn = (JarURLConnection) url.openConnection(); conn.setAllowUserInteraction( false ); conn.setDoInput( true ); conn.setDoOutput( false ); conn.connect(); theJar = conn.getJarFile(); } catch ( IOException ioe ) { } }
init() silently suppresses IOException thrown on connect() leaving theJar as null which causes NPE later referencing theJar's methods. Definitely another bug, but seems won't be fixed at all since plexus-resources is abandoned.
Attachments
Issue Links
- is related to
-
MCHECKSTYLE-225 headerLocation no longer sets checkstyle.header.file
- Closed
-
MCHECKSTYLE-288 NullPointerException during building a multi-module project
- Closed