Bug 295491 - AsmHierarchyBuilder.java:548 - NullPointerException
Summary: AsmHierarchyBuilder.java:548 - NullPointerException
Status: RESOLVED WORKSFORME
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 1.6.9M1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-18 12:13 EST by wdorninger CLA
Modified: 2010-04-16 13:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wdorninger CLA 2009-11-18 12:13:58 EST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Build Identifier: 20090621-0832

java.lang.NullPointerException
at org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder.visit(AsmHierarchyBuilder.java:548)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:214)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1246)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(Compilatio ... oBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Compile error: NullPointerException thrown: null

Reproducible: Always
Comment 1 wdorninger CLA 2009-11-18 12:27:21 EST
This is the aspect I'm trying to add

package com.test.aspects;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public aspect SpringConfigurableMixin {

    public static interface HasEntityManager {
      EntityManager getEntityManager();
    }
    
    declare @type : (@Entity *) : @Configurable(autowire = Autowire.BY_TYPE, preConstruction = true);
    
    declare parents : (@Entity *) implements HasEntityManager;
    
    @PersistenceContext
    transient private EntityManager HasEntityManager.em;
   
    public EntityManager HasEntityManager.getEntityManager() {
       return em;
    }    
}
Comment 2 wdorninger CLA 2009-11-18 12:36:34 EST
The culprit seems to be the "decleare @type" which causes the exception. When its commented out there is no NullPointerException
Comment 3 Andrew Clement CLA 2009-11-18 12:47:02 EST
I fixed a similar bug to this yesterday (although the fix is not in AJDT yet).  In that case is was happening if your declare statements used an annotation type that you hadn't imported.  Before the compile error about the missing import is reported, the code that builds the model crashes because it is missing.  Are both your annotation types imported?
Comment 4 wdorninger CLA 2009-11-18 15:03:02 EST
Thanks for the quick reply. 

You are right 

import javax.persistence.Entity;
import org.springframework.beans.factory.annotation.Configurable;

were not imported however even after importing them I get the same NullPointerException.
Comment 5 Andrew Clement CLA 2009-11-18 15:20:00 EST
susprised you get the NPE even after the import.  Is Autowire imported too?
Comment 6 wdorninger CLA 2009-11-18 15:36:31 EST
Yes all the imports are done - here the full aspect. I also tried to simplify it by omitting the parameters for the annotation however no luck.

package com.j4fe.aspects;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Entity;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Autowired;

public aspect SpringConfigurableMixin {

    public static interface EntityManagerAware {
      EntityManager getEntityManager();
    }
    
   
    // not working 
    // declare @type : (@Entity *) : @Configurable(autowire = Autowire.BY_TYPE, preConstruction = true);
    
    // also not working
    // declare @type : (@Entity *) : @Configurable
    
    declare parents : (@Entity *) implements EntityManagerAware;
    
    @PersistenceContext
    transient private EntityManager EntityManagerAware.entityManager;
   
    public EntityManager EntityManagerAware.getEntityManager() {
       return entityManager;
    }    
}
Comment 7 Andrew Clement CLA 2009-11-18 16:27:44 EST
your import says Autowired but your code says Autowire - is that just a typo in putting the snippet into bugzilla?
Comment 8 wdorninger CLA 2009-11-19 02:49:30 EST
At the end I did not even try with parameters anymore - I only uncommented this line and also got a NullPointerException (both annotations Entity and Configurable are imported)

declare @type : (@Entity *) : @Configurable
Comment 9 Andrew Clement CLA 2010-01-25 17:01:37 EST
I took the sample code, obtained the spring and persistence dependencies, but I can still only make it fail on an old AJDT.  Are you sure when you had everything imported that you also had Autowire imported, because I don't see the import for that in the sample?

Once I upgraded AJDT, everything behaved as expected and the NPE went away.

Can you let me know what version of AJDT you are using so I can persue this further, thanks.
Comment 10 Andrew Clement CLA 2010-03-10 11:55:55 EST
let me know the AJDT version if you are still having this problem.