Bug 70404 - passing null to array arguments confuzes static join point signature.
Summary: passing null to array arguments confuzes static join point signature.
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-20 06:22 EDT by Lasse R. Nielsen CLA
Modified: 2004-10-21 04:31 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 Lasse R. Nielsen CLA 2004-07-20 06:22:52 EDT
(Example classes below)

When calling with a null argument for the array parameter the *first* time it is 
called, the "thisStaticJoinPoint" signature reports "ClassNotFoundException" as 
the type of that parameter, also for the next call where the argument is not 
null.
 
However, if I *switch* the calls, so the first call is with a non-null argument, 
then the static join point correctly reports the array type, also for the next 
call.
 
Tested with both AspectJ 1.1 and 1.2 from command line and AJDT 1.1.11 from 
Eclipse 3.  
 
It seems to be a bug in the runtime classes (no Component for that?)

Example classes:
--- Main.java ---
package dk.infimum.aspectjtest;
public class Main {
 
    public static void main(String[] args) {
      Main obj = new Main();
      // swap following lines to change behavior
      obj.test(null, null);
      obj.test(null, new Main[]{});
    }
 
    void test(Main dummy, Main[] dummy2) {}
 
}
--- end Main.java ---
 
and
 
--- MainAspect.aj ---
import org.aspectj.lang.reflect.MethodSignature;
 
public aspect MainAspect {
 
    pointcut testcall(): execution(* test*(..));
 
    before(): testcall() {
      MethodSignature sig = 
        (MethodSignature) thisJoinPointStaticPart.getSignature();
      System.out.println(sig);
      Class[] params = sig.getParameterTypes();
      for(int i=0;i<params.length;i++) {
        Class cls = params[i];
        System.out.println(" - " + cls.getName());
      }
    }
}
--- end MainAspect.aj ---
 
The output from running Main is:
 
---
void dk.infimum.aspectjtest.Main.test(Main, ClassNotFoundException)
 - dk.infimum.aspectjtest.Main
 - java.lang.ClassNotFoundException
void dk.infimum.aspectjtest.Main.test(Main, ClassNotFoundException)
 - dk.infimum.aspectjtest.Main
 - java.lang.ClassNotFoundException
---
 
However, if I swap the calls to test, the output becomes:
 
---
void dk.infimum.aspectjtest.Main.test(Main, Main[])
 - dk.infimum.aspectjtest.Main
 - [Ldk.infimum.aspectjtest.Main;
void dk.infimum.aspectjtest.Main.test(Main, Main[])
 - dk.infimum.aspectjtest.Main
 - [Ldk.infimum.aspectjtest.Main;
---
Comment 1 Adrian Colyer CLA 2004-08-09 15:28:47 EDT
marked as target 1.2.1
Comment 2 Adrian Colyer CLA 2004-08-27 10:25:37 EDT
Turns out I only *said* I was marking this for 1.2.1 last time, but I didn't actually do it. this time I really 
have so we should get a fix in soon.
Comment 3 Andrew Clement CLA 2004-08-27 10:36:19 EDT
This bug appears to be due to a problem of us using loadClass() rather than
Class.forName() to get hold of the array type.

The raiser says that this fails:

obj.test(null, null);
obj.test(null, new Main[]{});

and this works:

obj.test(null, new Main[]{});
obj.test(null, null);

However, this also works:

Main m[] = new Main[3];
obj.test(null, null);
obj.test(null, null);

Basically using Class.forName() will attempt to bring the type into existence
(i.e. it understands "[Lblahblah;" is an array type that needs dynamically
creating) whereas the loadClass() method that we use right now will just look
around for it - if it doesn't find it then it throws a ClassNotFoundException.

That's why it works if someone else has referred to the array type earlier on -
they will have caused it to be dynamically created for loadClass() to find.

I'm about to stick in a fix for it...
Comment 4 Andrew Clement CLA 2004-08-27 11:24:13 EDT
Fix checked in - waiting for build (sorry about working on a bug assigned to you
Adrian!).
Comment 5 Andrew Clement CLA 2004-08-28 12:33:33 EDT
Fix available:

BUILD COMPLETE -  build.364
Date of build: 08/27/2004 22:17:38
Time to build: 95 minutes 15 seconds
Last changed: 08/27/2004 17:02:18
Latest good AspectJ jar available at:
download.eclipse.org/technology/ajdt/dev/aspectj-DEVELOPMENT.jar
Comment 6 Adrian Colyer CLA 2004-10-21 04:31:40 EDT
Fix released as part of AspectJ 1.2.1