Bug 36114 - advice on main method is not picked up
Summary: advice on main method is not picked up
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-06 13:58 EDT by Tony CLA
Modified: 2003-04-08 16:34 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tony CLA 2003-04-06 13:58:56 EDT
sample code from 
http://www.eli.sdsu.edu/courses/spring03/cs683/notes/aspectJSyntax/aspectJSyntax
.html#Heading2

public class Hello
   {
   public static void main(String[] args )
      {
      System.out.println("Hello");
      }
   }

public aspect HelloAspect
   {
   before() : call(void main(String[]))
      {
      System.out.println( "Advice");
      }
   }

Instead of output as 
Advice
Hello

The output is 
Hello

If the aspect is changed to
public aspect HelloAspect
   {
   before() : call(void *(*)) && !within(HelloAspect)
	  {
	  System.out.println( "Advice");
	  }
   }

then the correct output is produced
Advice
Hello

I tried to put advice on other static methods and the advice was picked up.
Is the advice supposed to work in this way?
I am using the latest 1.1.1 AJDT plugin for Eclipse.
Comment 1 Jim Hugunin CLA 2003-04-08 16:34:12 EDT
This is the correct behavior.  call(void main(..)) matches every call to the 
main method, but in this case the call to main is happening from the JVM and 
is not visible to the compiler.  If you put advice on execution(void main(..)) 
that will run whenever the main method starts executing regardless of where it 
is called from.