Bug 288049 - Declare @method fails on subclasses with "method does not exist" error
Summary: Declare @method fails on subclasses with "method does not exist" error
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 1.6.6   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-30 08:14 EDT by Simone Gianni CLA
Modified: 2009-09-08 16:55 EDT (History)
1 user (show)

See Also:


Attachments
Failing project for declare annotations (1.16 KB, application/zip)
2009-08-30 08:16 EDT, Simone Gianni CLA
no flags Details
Failing (this time really) project (1.91 KB, application/octet-stream)
2009-09-05 17:39 EDT, Simone Gianni CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simone Gianni CLA 2009-08-30 08:14:43 EDT
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2009010218 Gentoo Firefox/3.0.5
Build Identifier: 20090619-0625

BcelClassWeaver has a method checkUnusedDeclareAtTypes that should check if a declare @xxx goes unused. This method reports error in some situations where the declare is perfectly legal and applied. For example :

declare @method: public String MyClass+.a*(..) : @Deprecated;

Will give error if there is a method named "aSomething" in a subclass of MyClass.

Looking at the code, it seems like it avoids performing this check unless the declare has an exact pattern. In fact it checks :
- If the declaration uses an ExactTypePattern
AND
- If the delcaration is NOT any
- OR if the declaration is on a constructor

 MyClass+.a*(..), that should not be tested, is in fact tested because :
- It is not an exact type (the typePattern is null) which is right
- It is not an ANY ("a*" is not any, "*" would be any)
- It is not a constructor

I think a "isWithWildcard" is missing, as an alternative to isAny, that should return true if starCount > 0, and should be used in this check.

Changing the type pattern in a way that eludes the check makes the problem go away, for example :

public String org.tests.M*Class.a*(..) // declA.getSignaturePattern().getDeclaringType() instanceof ExactTypePattern becomes false

public String MyClass.*(..) // declA.getSignaturePattern().getName().isAny() becomes true

Reproducible: Always

Steps to Reproduce:
1. Unzip the given test project
2. ajc or ltw
3. Look at the error "The method org.tests.MyClass+a*(..) does not exist".



Since annotation introduction is gaining quite an important role for AspectJ, I feel like this is a major bug.
Comment 1 Simone Gianni CLA 2009-08-30 08:16:25 EDT
Created attachment 146006 [details]
Failing project for declare annotations
Comment 2 Andrew Clement CLA 2009-09-04 13:51:10 EDT
> Reproducible: Always

I just unzipped it and compiled it and got no error...
Comment 3 Simone Gianni CLA 2009-09-05 06:59:36 EDT
Hi Andy,
I'm getting this error consistently on another project. The small project I zipped WAS giving me that error consistently ... but unzipping it NOW is not giving me the error anymore.

I'll try to scope it better and make it reproducible. 

While in Eclipse I was able to see the error, and in that case it could depend on incremental compile. 

While running it in my main program, it was using LTW.

I'll try to reproduce it and let you know.
Comment 4 Simone Gianni CLA 2009-09-05 17:37:25 EDT
Got it, and made an even simpler failing project.

This is what (i think) happens :
- It finds a specific class pattern (even if there is "+")
- It finds that the method pattern is not "any" (it is "do*", so not exact and not any)
- It checks if in the given class such a method exists
- It does not exist (but it exists in subclasses)
- It raises the error (while in reality that is exactly what i asked for, do* methods in subclasses)
Comment 5 Simone Gianni CLA 2009-09-05 17:39:13 EDT
Created attachment 146563 [details]
Failing (this time really) project
Comment 6 Andrew Clement CLA 2009-09-08 16:55:54 EDT
fixed