Bug 156904 - Incorrect warning when advising a private method of a private inner class
Summary: Incorrect warning when advising a private method of a private inner class
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: IDE (show other bugs)
Version: 1.5.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.3   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-11 13:39 EDT by Wim Deblauwe CLA
Modified: 2012-04-03 15:48 EDT (History)
0 users

See Also:


Attachments
failing testcases (6.34 KB, patch)
2006-10-03 09:04 EDT, Helen Beeken CLA
aclement: iplog+
Details | Diff
proposed fix (2.12 KB, patch)
2006-10-03 09:06 EDT, Helen Beeken CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wim Deblauwe CLA 2006-09-11 13:39:27 EDT
The Eclipse AJDT give an incorrect warning when you want to advise a private method of a private inner class.


When I want to advise a private method in a private inner class, like this

public class Outer
{
   private class Inner
   {
      private void myMethod()
   }
}

Using the following poincut:

poincut innerpointcut():execution( * Outer.Inner.myMethod() );

and advice:

before():innerpointcut()
{
   System.out.println( "executing!" );
}

I get a warning "invalidAbsoluteTypeName" next to my pointcut, but next to the advice, there is a marker that points to the private method.
Comment 1 Andrew Clement CLA 2006-09-25 09:17:35 EDT
take a look for 1.5.3
Comment 2 Helen Beeken CLA 2006-09-27 09:58:16 EDT
This problem is occurring because Outer is in a package. Changing the pointcut expression to include the package ie. pkg.Outer.Inner.myMethod() or moving Outer to the default package does not produce the invalidAbsoluteTypeName warning. 

Also, note that the test programs for bug 67591 and bug 65925 which have previously been fixed also produce the invalidAbsoluteTypeName warning if the classes are in packages.

The reason we're producing the warning is that at this time we're looking at Outer.Inner which we can't find, whereas when we come to match this has become pkg.Outer.Inner which we can find (and is why the marker is there indicating its been advised).
Comment 3 Helen Beeken CLA 2006-10-02 09:34:12 EDT
The reason we're getting the invalidAbsoluteTypeName is the same as we were getting the warning in bug 67591. That is, due to the visibility checking in org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.canBeSeenBy(). We find Outer.Inner, however, since this is a private class we check for the privileged modififier on the aspect. This isn't there so we return a ProblemReferenceBinding which ultimately results in the warning being reported. 

The fix for bug 67591 was to check if the type can be found in the world if there's a problem finding it from the current scope. This currently doesn't work in the case of this bug because, as previously mentioned, the class is in a package. When we come to see if the type Outer$Inner is in the world we ask the world's typemap for LOuter$Inner. However, the typemap contains Lpkg/Outer$Inner which doesn't match so we return that we can't find it in the world. A MissingResolvedTypeWithKnownSignature is created and the invalidAbsoluteTypeName warning is the result.
Comment 4 Helen Beeken CLA 2006-10-02 09:37:49 EDT
The problem is though that when we're resolving the pointcut, the pointcut expression contains "Outer.Inner.myMethod()" which makes no reference to the package...
Comment 5 Helen Beeken CLA 2006-10-03 08:57:44 EDT
The reason we know about the package when we come to match is that after reporting the warning we record scope.getImportedPrefixes(). In the case of the supplied testcase this includes pkg$A, pkg., java.lang.Object$ and java.lang. The fix is to update lookupTypeInWorld to include a search for the typename prepended with these prefixes.
Comment 6 Helen Beeken CLA 2006-10-03 09:04:39 EDT
Created attachment 51328 [details]
failing testcases

Apply this patch to the tests project.

This patch contains four scenarios:

1. There is one file containing public aspect and a class. The class contains a private inner class which contains a private method. There should be no warning from the pointcut about not being able to find the type corresponding to the inner class.

2. The class and aspect are in different packages. The class has default visibility and contains a private method. The aspect imports the package containing the class. There should be no warning from the pointcut about not being able to find the class type.

2. The class and aspect are in different packages. The class has default visibility and contains a private method. The aspect does not import the package containing the class. There should be a warning from the pointcut about not being able to find the class type.

4. The class and aspect are are in the same package but different files. The class has default visibility and contains a private method. There should be no warnings saying cant find the class type.
Comment 7 Helen Beeken CLA 2006-10-03 09:06:04 EDT
Created attachment 51329 [details]
proposed fix

Apply this patch to the weaver project.

This patch contains the proposed fix as described in comment #5.
Comment 8 Andrew Clement CLA 2006-10-03 10:56:46 EDT
patches in

iplog
Comment 9 Andrew Clement CLA 2006-10-04 03:05:17 EDT
fixed in latest aj dev builds.