Bug 37069 - [grammar] compiler allows package name containing "aspect" keyword
Summary: [grammar] compiler allows package name containing "aspect" keyword
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 2000
: P5 minor (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 41785 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-04-29 15:40 EDT by Julie Waterhouse CLA
Modified: 2009-04-01 06:43 EDT (History)
3 users (show)

See Also:


Attachments
Trivial aspect in a package that has the keyword "aspect" in its name. (135 bytes, text/plain)
2003-04-29 15:42 EDT, Julie Waterhouse CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Julie Waterhouse CLA 2003-04-29 15:40:11 EDT
This bug was originally found by Charles Zhang and reported as an AJDT problem 
on our newsgroup.  I think it's an AspectJ compiler problem, and so am 
reporducing it here.

I am using AspectJ 1.1rc1 on Win2K.

The problem first manifested using the Eclipse AJDT plugin.  If you create a 
package called "aspect.test" and then create an aspect MyAspect in that 
package, you get an error 'Error Syntax error on token "aspect", "Identifier" 
expected' (the error is flagged on the bad package name).  I assume this is 
because "aspect" is a keyword in AspectJ, so this is expected behaviour 
(ideally we could catch it when the package is created, but we'd have to write 
a specialised AspectJ New Package Wizard for that.  Right now, Java keywords 
are caught by that wizard, so you can't create a new package 
called "class.foo", e.g.)

The unusual behaviour is that this program, with aspect "MyAspect" in 
package "aspect.test", does compile using ajc from the command line, and runs.  
On the other hand, a class in a package called "class.foo" will not build with 
ajc (you get the error "identifier expected" on the "class.foo" name).  This 
seems inconsistent (both between the behaviour of Java keywords versus AspectJ 
keywords, as well as between the ide versus the commandline).  I would expect a 
similar "identifier expected" error when I try to use "apsect.foo" as an 
identifier.
Comment 1 Julie Waterhouse CLA 2003-04-29 15:42:29 EDT
Created attachment 4756 [details]
Trivial aspect in a package that has the keyword "aspect" in its name.
Comment 2 Jim Hugunin CLA 2003-04-30 21:31:19 EDT
This bug merits some more work to understand the details after the 1.1 release.

In order to be compatible with existing Java code bases, we've tried to not 
add any new keywords to the AspectJ grammar.  Instead, words like 'aspect' are 
treated as pseudo-keywords that are also allowed to be used in most identifier 
positions.  This means that code which has a field called 'aspect' is legal, 
whereas code with a field called 'class' is not.

We should probably look at the grammar more closely to understand any places 
where this liberalness breaks down and at least document that behavior.  
Ceratinly, having a top-level package named aspect is the kind of thing that 
might lead to trouble.  However, we definitely want to support package names 
like 'com.parc.mycode.aspect' which are easier to imagine in large-scale 
existing code bases.
Comment 3 Jim Hugunin CLA 2003-08-25 13:28:23 EDT
*** Bug 41785 has been marked as a duplicate of this bug. ***
Comment 4 Neale Upstone CLA 2009-04-01 06:43:42 EDT
Version: 1.6.5.200903301249
AspectJ version: 1.6.4.20090329215800

This is more curious than it seems...

I just tried this.

-- src/aspect/Aspect.aj
package aspect; // after build, error marker here, and aspect is bold as keyword

public aspect Aspect
{
}

However, if I look in my bin directory I get:

/bin
- /aspect
- /Aspect.class

When I should see

/bin
- /aspect
- /aspect/Aspect.class

The package folder is created, but the generated class is not in it.