Bug 254207 - NPE when generic type substitution invalid
Summary: NPE when generic type substitution invalid
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 1.6.3   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-05 19:11 EST by Michael Huffman CLA
Modified: 2008-11-10 11:31 EST (History)
2 users (show)

See Also:


Attachments
Code causing compiler error (6.93 KB, application/x-zip-compressed)
2008-11-06 10:49 EST, Michael Huffman CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Huffman CLA 2008-11-05 19:11:00 EST
Build ID: M20080911-1700

Steps To Reproduce:
Create an abstract aspect with a bounded generic type. Use that generic type as the return type of an abstract method. Create a concrete aspect which extends the abstract aspect with a type not valid within the bounds defined by the abstract aspect's generic type. 

This should cause a compiler error. Instead, a null pointer exception is thrown (see below). Code below was used to reproduce:

public abstract aspect Abstract<T extends Integer> {
   public abstract T getT();
}

// Number is not valid substitute for T
public aspect Concrete extends Abstract<Number> { 
   public Number getT() {
      return 5;
   }
}

This appears to occur only within Eclipse/AJDT as I cannot reproduce it in our Ant builds.

AJDT Version: 1.6.2.20081105005554
AspectJ Version: 1.6.3.20081028135200
Incremental Compiler Optimizations: On
Non-standard compiler options: -Xset:pipelineCompilation=false

The NPE exceptions tracktrace is:

java.lang.NullPointerException
at org.aspectj.weaver.CrosscuttingMembers.setPerClause(CrosscuttingMembers.java:475)
at org.aspectj.weaver.ResolvedType.collectCrosscuttingMembers(ResolvedType.java:560)
at org.aspectj.weaver.CrosscuttingMembersSet.addOrReplaceAspect(CrosscuttingMembersSet.java:77)
at org.aspectj.weaver.CrosscuttingMembersSet.addOrReplaceDescendantsOf(CrosscuttingMembersSet.java:113)
at org.aspectj.weaver.CrosscuttingMembe ... oBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Compile error: NullPointerException thrown: null
Comment 1 Andrew Eisenberg CLA 2008-11-05 19:27:17 EST
This looks like an AspectJ error even though it is only reproducible in AJDT land.  Willing to look at it more if otherwise. 
Comment 2 Andrew Clement CLA 2008-11-06 08:51:50 EST
definetly aj
Comment 3 Michael Huffman CLA 2008-11-06 10:05:47 EST
I thought it was in aj but as I couldn't reproduce outside of AJDT, I just took a shot. Thanks.
Comment 4 Michael Huffman CLA 2008-11-06 10:49:55 EST
Created attachment 117210 [details]
Code causing compiler error
Comment 5 Michael Huffman CLA 2008-11-06 10:50:42 EST
After more investigation this morning, it doesn't look related to the return type at all. If its any help, an even simpler case is provided below. Looks like NPE occurs any time there would be a compilation error related to generic bounds/substitution:

public interface Interface { }

public class Class { }

// class does not implement Interface
public aspect Concrete extends Abstract<Class> { } 

public abstract aspect Abstract<T extends Interface> { }

I've also noticed a similar bug related to generics and type substitution. This may be a duplicate, so I haven't yet reported a bug for it. In that scenario, I've setup some type inheritance which goes across projects (no aspect/inpaths, just Java dependencies). In doing so, it looks like there might be an issue with type erasure, as a valid generic type substitution doesn't compile. Oddly enough, I can only reproduce that compile failure when there are two projects. When placing all the code in a single project, the NPE reported for this bug gets thrown. This leads me to believe they're the same bug. I've attached code to reproduce the second scenario.
Comment 6 Andrew Clement CLA 2008-11-10 09:42:28 EST
Can I ask why you are running with pipeline compilation switched off?  Given that we don't test that mode at all it is effectively unsupported.

However, I have recreated the scenario described in the first comment so will debug it now - but it only happens if I turn off pipeline compilation.
Comment 7 Michael Huffman CLA 2008-11-10 11:11:38 EST
We've had this option set in our build since a bug was reported several months ago. We have attempted to remove this flag on a couple of occasions, but if memory serves we have run into other issues. When I get more time, I can tell you what issues, if any, we still see without the flag. I'll get back to you on that one.
Comment 8 Andrew Clement CLA 2008-11-10 11:31:08 EST
Here is the command to get it to fail on command line:

ajc -1.5 -proceedOnError -Xset:pipelineCompilation=false Abstract.java
Concrete.java

The problem is due to heading into the weaving process even though the aspect
is broken (which is what -proceedOnError does, and that is default in AJDT)

I've committed a change to cope with a broken aspect (and so the real error
comes out).

I've put in two testcases - one for your first scenario and one for the
scenario in comment 5.


If you can let me know why you still need pipeline compilation, that would be
great - I don't like to see it used other than for debugging or a temporary
workaround.  There are a couple of known issues that are very hard to solve for
pipelining.  It might be one of those and so far they haven't made it into a
release plan.  If it is then you will probably need to continue using it - but
it is worth checking if it is something I don't know about.

cheers