Bruno P. Kinoshita created WEAVER-16:
----------------------------------------

             Summary: 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)

Reply via email to