[ 
https://jira.codehaus.org/browse/MCHECKSTYLE-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=364578#comment-364578
 ] 

Peter Palaga commented on MCHECKSTYLE-250:
------------------------------------------

For this bug to occur it is enough that the dependency of non-jar type ({{pom}} 
in our case) in plugin dependencies is a transitive dependency. In our case the 
checkstyle configuration is packaged as a {{jar}} - see 
[here|https://github.com/hawkular/hawkular-build-tools/blob/956f04cbdfcd563982ef29aef19c93e9cb46a14b/build-tools/pom.xml#L21]
 but its parent is of type {{pom}} - see 
[here|https://github.com/hawkular/hawkular-build-tools/blob/956f04cbdfcd563982ef29aef19c93e9cb46a14b/pom.xml#L27].
 We have to break the parent-child link between the two as a workaround.

> NPE on tying to load LICENSE.txt resource from non-jar plugin dependencies
> --------------------------------------------------------------------------
>
>                 Key: MCHECKSTYLE-250
>                 URL: https://jira.codehaus.org/browse/MCHECKSTYLE-250
>             Project: Maven Checkstyle Plugin
>          Issue Type: Bug
>    Affects Versions: 2.13
>            Reporter: Konstantin Pokrovsky
>
> *Steps to reproduce:*
> * Add non jar (XML for example) artifact dependency to plugin dependencies 
> section:
> {code:xml}
>             <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>
> {code}
> * Run _checkstyle:check_
> Result:
> {noformat}
> [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
> {noformat}
> *Investigation:*
> * _CheckstyleViolationCheckMojo_ forms _CheckstyleExecutorRequest_ for the 
> executor by initializing _licenseArtifacts_ property with all plugin's 
> dependencies.
> {code:java|title=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 );
> {code}
>  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:
> {code:java|title=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
>                 }
>             }
>         }
> {code}
> * Later Plexus _JarResourceLoader_ fails to load the resource from those non 
> jar dependencies:
> {code:java:title=JarHolder.java:62}
>     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 )
>         {
>         }
>     }
> {code}
> _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.



--
This message was sent by Atlassian JIRA
(v6.1.6#6162)

Reply via email to