Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] generics problem: generated method not adviced (bug?)

Dear all,
I have a problem with the following aspect which can advice methods, depending on how it's compiled...

public class A implements java.util.Comparator <String> {
 public int compare(String a, String b) {
   return 0;
 }
}

javac generated a compare(Object, Object) method corresponding to

public int compare(Object a, Object b) {
  return compare((String)a, (String)b);
}

When weaving A.java with the following aspect, only the compare(String, String) method is adviced...

public aspect Foo {
 before() : execution(* *(..)) && !within(Foo) {}
}

javac A.java
jar cvf a.jar A.class
ajc -showWeaveInfo  -inpath a.jar -outjar woven.jar Foo.aj
Join point 'method-execution(int A.compare(java.lang.String, java.lang.String))' in Type 'A' (A.java:3) advised by before advice from 'Foo' (Foo.aj:2)
	
Now, if I add the compare(Object, Object) manually, the Foo aspect advice both compare(String, String) and compare(Object, Object) methods!!!!

public class A implements java.util.Comparator /*<String> */ {
 public int compare(String a, String b) {
   return 0;
 }
 public int compare(Object a, Object b) {
   return compare((String)a, (String)b);
 }
}

javac A.java
jar cvf a.jar A.class
ajc -showWeaveInfo  -inpath a.jar -outjar woven.jar Foo.aj
Join point 'method-execution(int A.compare(java.lang.String, java.lang.String))' in Type 'A' (A.java:3) advised by before advice from 'Foo' (Foo.aj:2)
	
Join point 'method-execution(int A.compare(java.lang.Object, java.lang.Object))' in Type 'A' (A.java:6) advised by before advice from 'Foo' (Foo.aj:2)
	
Curiously, the bytecode for compare(Object, Object) is strictly the same.. in both cases..

public int compare(java.lang.Object, java.lang.Object);
 Signature: (Ljava/lang/Object;Ljava/lang/Object;)I
 Code:
  Stack=3, Locals=3, Args_size=3
  0:   aload_0
  1:   aload_1
  2:   checkcast       #2; //class java/lang/String
  5:   aload_2
  6:   checkcast       #2; //class java/lang/String
9: invokevirtual #3; //Method compare:(Ljava/lang/String;Ljava/ lang/String;)I
  12:  ireturn
 LineNumberTable:
  line 1: 0

Is this a bug of ajc? I tested it with 1.6.1 and 1.6.2 (development version)

Thanks a lot,

Alex





Back to the top