You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bruno P. Kinoshita (JIRA)" <ji...@apache.org> on 2016/11/19 06:10:58 UTC

[jira] [Commented] (WEAVER-16) NullPointerException when weaving class with no package

    [ https://issues.apache.org/jira/browse/WEAVER-16?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15678693#comment-15678693 ] 

Bruno P. Kinoshita commented on WEAVER-16:
------------------------------------------

Exception:

{noformat}
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.340 s
[INFO] Finished at: 2016-11-19T18:56:43+13:00
[INFO] Final Memory: 16M/205M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.commons:commons-weaver-maven-plugin:1.4-SNAPSHOT:weave (default) on project weaver-example: weaving failed due to null: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.commons:commons-weaver-maven-plugin:1.4-SNAPSHOT:weave (default) on project weaver-example: weaving failed due to null
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	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:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	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.MojoExecutionException: weaving failed due to null
	at org.apache.commons.weaver.maven.AbstractWeaveMojo.doExecute(AbstractWeaveMojo.java:40)
	at org.apache.commons.weaver.maven.AbstractCWMojo.execute(AbstractCWMojo.java:115)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.NullPointerException
	at org.apache.commons.weaver.model.ScanResult.getWeavable(ScanResult.java:184)
	at org.apache.commons.weaver.model.ScanResult.getWeavable(ScanResult.java:200)
	at org.apache.commons.weaver.model.ScanResult.getWeavable(ScanResult.java:218)
	at org.apache.commons.weaver.Finder.scan(Finder.java:706)
	at org.apache.commons.weaver.privilizer.PrivilizerWeaver.process(PrivilizerWeaver.java:55)
	at org.apache.commons.weaver.WeaveProcessor.weave(WeaveProcessor.java:70)
	at org.apache.commons.weaver.maven.AbstractWeaveMojo.doExecute(AbstractWeaveMojo.java:38)
	... 23 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
{noformat}

> NullPointerException when weaving class with no package
> -------------------------------------------------------
>
>                 Key: WEAVER-16
>                 URL: https://issues.apache.org/jira/browse/WEAVER-16
>             Project: Commons Weaver
>          Issue Type: Bug
>          Components: core
>            Reporter: Bruno P. Kinoshita
>            Priority: Minor
>
> This issue happened while quickly writing an example with weaver to test another issue.
> I created a sample project to call the maven-plugin with privilizer, as in the project home page example.
> {code}
> import org.apache.commons.weaver.privilizer.Privileged;
> public class SimpleClass {
>     public void sayA() {
>         System.out.println("Aaa");
>     }
>     
>     @Privileged
>     public void sayNothing() {
>         System.out.println("Nothing");
>     }
> }
> {code}
> As I was in a hurry, I didn't bother creating a package, adding comments, etc. When I asked Eclipse to build the project, it threw a NPE. Then I tried via command line, same behavior.
> My pom.xml was using version 1.3, but since I have the project sources in my workspace, I re-synced the local repo, `mvn install`'d, and then updated the pom to use 1.4-SNAPSHOT.
> Same issue. I believe the issue is in the ScanResult#getWeavable method that returns a WeavablePackage.
> {code}
> // snip
>     /**
>      * Public for use by {@link WeaveProcessor}.
>      * @param pkg to wrap
>      * @return {@link WeavablePackage}
>      */
>     public WeavablePackage getWeavable(final Package pkg) {
>         final String key = pkg.getName();
>         if (packages.containsKey(key)) {
>             return packages.get(key);
>         }
>         final WeavablePackage result = new WeavablePackage(pkg);
>         final WeavablePackage faster = packages.putIfAbsent(key, result);
>         return faster == null ? result : faster;
>     }
> // snip
> {code}
> I believe when you create a class with no package, trying to get its package (i.e. obj.getClass().getPackage()) will return null. So I'm no sure how this issue could be fixed. Simply passing a null to WeavablePackage's contructor seems like will create other issues...
> For the time being, will update my example to use packages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)