Bug 268522 - Cross reference view fails to show cross references in aspect
Summary: Cross reference view fails to show cross references in aspect
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: UI (show other bugs)
Version: 1.6.4   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 2.0.0   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-13 09:00 EDT by paul freeman CLA
Modified: 2009-05-11 17:50 EDT (History)
3 users (show)

See Also:


Attachments
sample project and before and after pictures of cross reference tab (39.12 KB, application/zip)
2009-03-13 09:00 EDT, paul freeman CLA
no flags Details
simpler project that recreates the problem (1.10 KB, application/octet-stream)
2009-03-14 16:55 EDT, Andrew Eisenberg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description paul freeman CLA 2009-03-13 09:00:48 EDT
Created attachment 128699 [details]
sample project and before and after pictures of cross reference tab

Build ID: M20090211-1700

Steps To Reproduce:
1. Open the attached sample project
2. Open the cross reference tab.
3. Open the ProcessAspect aspect.
4. Select line 10 - "public aspect ProcessAspect"
5. Perform a clean build.
6. Notice that the cross reference tab shows what you would expect... see the attached before jpg.
7. Select line 9.
8. Select line 10 again.
9. Notice that the cross reference tab no longer shows any cross reference information.


More information:
The cause may also be what is causing: bug 263666.  However that issue was described differently.
Comment 1 paul freeman CLA 2009-03-13 09:06:05 EDT
I have another project that I cannot send to you due to the fact that it contains our company's code.  In this project, the cross reference view always shows what is in the attached after picture... it never shows the cross references.  The markers in the editor will show the correct number of advice points though, and the code is being woven correctly.
Comment 2 Andrew Eisenberg CLA 2009-03-14 16:40:01 EDT
This is interesting.  Thanks for the project.  I am using it and I am finding some peculiarities.

It seems like what is happening here is that the crosscutting model is changing after the build completes.  It should only be changing during a build.

So, what seems to be happening is that the build occurs, then markers are created.  After this, the model changes and the outgoing relationships for the advice are removed from the model.  

This is why the advice relationships are not showing up in the xref view.  They do not exist anymore.

This is starting to look like an AspectJ problem, but I will look some more.
Comment 3 Andrew Eisenberg CLA 2009-03-14 16:48:44 EDT
There are two advice declarations that use "thisJoinPoint".  When I remove all references to thisJoinPoint (and replace with null), then the underlying crosscutting model does not change after the build.

The xref view and navigation works as expected.  I am fairly certain this is an AspectJ issue.
Comment 4 Andrew Eisenberg CLA 2009-03-14 16:55:14 EDT
Created attachment 128834 [details]
simpler project that recreates the problem

This project is a simpler version that recreates the above.  It seems that the problem arises when the advice has a runtime check *and* references thisJoinPoint.

To recreate:

1. compile
2. try to navigate from before advice, but no navigation is possible.
3. comment out thisJoinPoint reference.  Navigation works
4. uncomment thisJoinPoint reference and comment out the cflow pointcut.  Navigation works
Comment 5 Andrew Clement CLA 2009-03-16 16:07:05 EDT
not sure I have enough to go on - I don't know what the model is when it is working or what it is when it becomes broken.  I can see the behaviour as described in comment 4 (although I don't need to comment out the cflow).  If I can't see the model changing, I can't do much other than confirm it is correct and see if I can see a difference with and without thisJoinPoint (I imagine the signature of the method pointing to has changed, and includes a joinpoint parameter in the former case).

Can you print the model between at times when you think it is valid/invalid?

The model cannot change after a build, there are no threads - and we only have one AspectJ project so it can't be another interfering.  But it could be altered very late on in the build process which damages something it showed earlier (but then AJDT shouldn't be looking at it until the build is over).

If I do a full build with the thisJoinPoint reference commented out - I have navigation from the gutter.  If i uncomment the line to get an incremental build, I still have the navigation.  To lose it I have to close and reopen the editor for the aspect.

I will get the model for a full build with and without the reference and put it here.
Comment 6 Andrew Clement CLA 2009-03-16 16:10:16 EDT
full build with tjp:

pr268522  [build configuration file] 
  hid is =pr268522
    [package] 
    hid is =pr268522<
    Advises.aj  [java source file] C:\temp\ajcSandbox\ws34\ajcTest15152.tmp\pr268522\src\Advises.aj:1::0
      hid is =pr268522<*Advises.aj
        [import reference] 
        hid is =pr268522<*Advises.aj#
      Advises  [aspect] C:\temp\ajcSandbox\ws34\ajcTest15152.tmp\pr268522\src\Advises.aj:2::15
        hid is =pr268522<*Advises.aj}Advises
        before(): <anonymous pointcut>..  [advice] C:\temp\ajcSandbox\ws34\ajcTest15152.tmp\pr268522\src\Advises.aj:3::26
          hid is =pr268522<*Advises.aj}Advises&before
    IsAdvised.java  [java source file] C:\temp\ajcSandbox\ws34\ajcTest15152.tmp\pr268522\src\IsAdvised.java:1::0
      hid is =pr268522<{IsAdvised.java
        [import reference] 
        hid is =pr268522<{IsAdvised.java#
      IsAdvised  [class] C:\temp\ajcSandbox\ws34\ajcTest15152.tmp\pr268522\src\IsAdvised.java:2::14
        hid is =pr268522<{IsAdvised.java[IsAdvised
        main(java.lang.String[])  [method] C:\temp\ajcSandbox\ws34\ajcTest15152.tmp\pr268522\src\IsAdvised.java:4::47
          hid is =pr268522<{IsAdvised.java[IsAdvised~main~\[QString;
Hid:1:(targets=1) =pr268522<{IsAdvised.java[IsAdvised~main~\[QString; (advised by) =pr268522<*Advises.aj}Advises&before
Hid:2:(targets=1) =pr268522<*Advises.aj}Advises&before (advises) =pr268522<{IsAdvised.java[IsAdvised~main~\[QString;
Comment 7 Andrew Clement CLA 2009-03-16 16:10:55 EDT
full build without tjp:

pr268522  [build configuration file] 
  hid is =pr268522
    [package] 
    hid is =pr268522<
    Advises.aj  [java source file] C:\temp\ajcSandbox\ws34\ajcTest50905.tmp\pr268522\src\Advises.aj:1::0
      hid is =pr268522<*Advises.aj
        [import reference] 
        hid is =pr268522<*Advises.aj#
      Advises  [aspect] C:\temp\ajcSandbox\ws34\ajcTest50905.tmp\pr268522\src\Advises.aj:2::15
        hid is =pr268522<*Advises.aj}Advises
        before(): <anonymous pointcut>..  [advice] C:\temp\ajcSandbox\ws34\ajcTest50905.tmp\pr268522\src\Advises.aj:3::26
          hid is =pr268522<*Advises.aj}Advises&before
    IsAdvised.java  [java source file] C:\temp\ajcSandbox\ws34\ajcTest50905.tmp\pr268522\src\IsAdvised.java:1::0
      hid is =pr268522<{IsAdvised.java
        [import reference] 
        hid is =pr268522<{IsAdvised.java#
      IsAdvised  [class] C:\temp\ajcSandbox\ws34\ajcTest50905.tmp\pr268522\src\IsAdvised.java:2::14
        hid is =pr268522<{IsAdvised.java[IsAdvised
        main(java.lang.String[])  [method] C:\temp\ajcSandbox\ws34\ajcTest50905.tmp\pr268522\src\IsAdvised.java:4::47
          hid is =pr268522<{IsAdvised.java[IsAdvised~main~\[QString;
Hid:1:(targets=1) =pr268522<{IsAdvised.java[IsAdvised~main~\[QString; (advised by) =pr268522<*Advises.aj}Advises&before
Hid:2:(targets=1) =pr268522<*Advises.aj}Advises&before (advises) =pr268522<{IsAdvised.java[IsAdvised~main~\[QString;
Comment 8 Andrew Clement CLA 2009-03-16 16:13:17 EDT
no difference in the model or relationships other than the sandbox directory
Comment 9 Andrew Clement CLA 2009-03-16 16:19:08 EDT
> So, what seems to be happening is that the build occurs, then markers are
> created.  After this, the model changes and the outgoing relationships for the
> advice are removed from the model.  

I guess these are the events for which I need to know the model.  Are the relationships gone or are they simply moved around?
Comment 10 Andrew Eisenberg CLA 2009-03-16 16:52:51 EDT
Here is the hierarchy and relationship map for before and after.  The behavior is slightly different from what I remember yesterday.  It seems that on a full build, the model is correct and then a noop change to the aspect will corrupt it (the outgoing advice relationship is lost).

Below is the hierarchy and relationship map printing that is used by AJDT (see AJProjectModelFacade).

(do full build)

Hierarchy after full build

=Bug268522/src
  =Bug268522/src<
    =Bug268522/src<*Advises.aj
      =Bug268522/src<*Advises.aj#
      =Bug268522/src<*Advises.aj}Advises
        =Bug268522/src<*Advises.aj}Advises&before
    =Bug268522/src<{IsAdvised.java
      =Bug268522/src<{IsAdvised.java#
      =Bug268522/src<{IsAdvised.java[IsAdvised
        =Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString;


Relationship Map after full build

=Bug268522/src<*Advises.aj}Advises&before ::
	=Bug268522/src<*Advises.aj}Advises&before --advises--> [=Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString;]
=Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString; ::
	=Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString; --advised by--> [=Bug268522/src<*Advises.aj}Advises&before]


(whitespace change to aspect and save---force noop incremental build)


Hierarchy after incremental build 

=Bug268522/src
  =Bug268522/src<
    =Bug268522/src<{IsAdvised.java
      =Bug268522/src<{IsAdvised.java#
      =Bug268522/src<{IsAdvised.java[IsAdvised
        =Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString;
    =Bug268522/src<*Advises.aj
      =Bug268522/src<*Advises.aj#
      =Bug268522/src<*Advises.aj}Advises
        =Bug268522/src<*Advises.aj}Advises&before


Relationship map after incremental build. Notice that the first line (for the advice) should have some relationships associated with it, but does not.

=Bug268522/src<*Advises.aj}Advises&before ::
=Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString; ::
	=Bug268522/src<{IsAdvised.java[IsAdvised~main~\[QString; --advised by--> [=Bug268522/src<*Advises.aj}Advises&before]
Comment 11 Andrew Clement CLA 2009-03-16 21:27:34 EDT
I have now recreated a case where a relationship vanishes, but only inside AJDT.  After hours of debugging (adding too many breakpoints makes the problem become less likely, stupid thing) I have found a bit of code deleting things from the model which i don't think should be:

java.util.AbstractList$Itr.remove(AbstractList.java:360)
        at
org.eclipse.ajdt.core.model.AJProjectModelFacade$2.preProcess(AJProjectModelFacade.java:784)
        at org.aspectj.asm.HierarchyWalker.process(HierarchyWalker.java:28)
        at org.aspectj.asm.internal.ProgramElement.walk(ProgramElement.java:420)
        at org.aspectj.asm.HierarchyWalker.process(HierarchyWalker.java:29)

The AspectJ model is not returning an unmodifiable list and that allows other people to damage it if they aren't careful.

I will look into how cheap unmodifiableLists are and perhaps return one of those instead to stop this kind of thing.
Comment 12 Andrew Eisenberg CLA 2009-03-17 00:46:58 EDT
(In reply to comment #11)
> org.eclipse.ajdt.core.model.AJProjectModelFacade$2.preProcess(AJProjectModelFacade.java:784)

I've changed this line to use a copy of the list rather than the original list and the problems goes away.  

Rather than return an unmodifiable list, perhaps you can return a copy.  And internally for the sections that require speed, create a new method that returns the original list.  After a quick grep through the code, it looks like the method is only used 3 times inside aspectj and about 5 times in AJDT.  All of the AJDT uses are bound to the UI, so speed is not much of a factor.
Comment 13 Andrew Clement CLA 2009-03-17 01:13:36 EDT
I don't think my contract on that API should be to return a copy that the user can mess with (and copying it just in case anyone wants to write to it would be wasteful) - your approach to creating a copy of whatever you get back would be more sensible.  But an unmodifiableList would be the cheap way to stop anyone messing with it by accident.

Now we know the problematic code, can you more accurately describe the scenario which would lead to relationships vanishing?  Is it something in AJDT 1.6.4?  Is it something relatively common or uncommon?
Comment 14 paul freeman CLA 2009-03-17 09:16:59 EDT
I'll just throw my 2 cents in since I reported the bug.

> Is it something in AJDT 1.6.4? 
I noticed it after installing eclipse 3.4 (with the latest ajdt) and aspectj 1.6.  I did not notice this issue in eclipse 3.3 and aspectj 1.5.

> Is it something relatively common or uncommon?
For me it is very common.  This behavior (or a variation of it) has occurred with every project I have created using aspectj 1.6 and eclipse 3.3.

Other variations:
- cross references never show up when viewing them from the aspect (as apposed to the advised class)
- markers show up with one build and then disappear with the next
- markers never show up



Comment 15 paul freeman CLA 2009-03-17 09:51:07 EDT
(In reply to comment #14)
> I'll just throw my 2 cents in since I reported the bug.
> 
> > Is it something in AJDT 1.6.4? 
> I noticed it after installing eclipse 3.4 (with the latest ajdt) and aspectj
> 1.6.  I did not notice this issue in eclipse 3.3 and aspectj 1.5.
> 
> > Is it something relatively common or uncommon?
> For me it is very common.  This behavior (or a variation of it) has occurred
> with every project I have created using aspectj 1.6 and eclipse 3.3.
> 
> Other variations:
> - cross references never show up when viewing them from the aspect (as apposed
> to the advised class)
> - markers show up with one build and then disappear with the next
> - markers never show up
> 

sorry... I meant to say "This behavior (or a variation of it) has occurred
with every project I have created using aspectj 1.6 and eclipse 3.4." not 3.3.

I also should have been more specific on the AJDT version I have seen this with: 1.6.4.  I had the latest stable build installed and then tried the latest development build to see if it would fix the issue.  Here are the ajde plugins I have installed:
org.aspectj.ajde_1.6.4.20090106083800
org.aspectj.ajde_1.6.4.20090304172355
and runtimes
org.aspectj.runtime_1.6.4.20090106083800
org.aspectj.runtime_1.6.4.20090304172355
Comment 16 Andrew Eisenberg CLA 2009-03-17 11:34:48 EDT
This will not occur in 1.6.0 or earlier because the refactored project model was not introduced until 1.6.1.

This problem will occur whenever multiple kinds of relationships apply to a single program element.  Eg, when there is an Aspect Declarations and an Annotated by relationship on a type.  I think this is a critical bug that must be added to 1.6.4.
Comment 17 Andrew Clement CLA 2009-03-17 18:05:58 EDT
appears to be AJDT.
Comment 18 Andrew Eisenberg CLA 2009-03-18 12:57:52 EDT
I committed the fix for this.  It is now in the AJDT 1.6.5 dev build (available from the dev update site).
Comment 19 Andrew Eisenberg CLA 2009-03-18 13:20:59 EDT
And both projects now work as expected.