Uploaded image for project: 'Commons Weaver'
  1. Commons Weaver
  2. WEAVER-16

NullPointerException when weaving class with no package

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.0
    • core
    • None

    Description

      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.

      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");
          }
      }
      

      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.

      // 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
      

      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.

      Attachments

        Activity

          People

            mbenson Matthew Jason Benson
            kinow Bruno P. Kinoshita
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: