Bug 148545 - NoSuchMethodError calling generic method of privileged aspect from advice
Summary: NoSuchMethodError calling generic method of privileged aspect from advice
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.2   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-24 18:27 EDT by Matt Whitlock CLA
Modified: 2006-06-26 04:20 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 Matt Whitlock CLA 2006-06-24 18:27:17 EDT
MyEnum.java
===========
public enum MyEnum {
	ONE, TWO, THREE, FOUR, FIVE
}

---

MyAnnotation.java
=================
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
	MyEnum[] value();
}

---

MyClass.java
============
public class MyClass {

	public MyEnum getValue() {
		return MyEnum.ONE;
	}

	@MyAnnotation({ MyEnum.ONE, MyEnum.TWO })
	public void test() {
	}

	public static void main(String[] args) {
		new MyClass().test();
	}
}

---

MyAspect.aj
===========
import java.util.Arrays;

privileged public aspect MyAspect {

	Object around(MyClass o, MyAnnotation a) :
			execution(@MyAnnotation * *(..)) &&
			target(o) &&
			@annotation(a) {
		if (!isOneOf(o.getValue(), a.value()))
			throw new IllegalStateException(
					o.getValue() +
					" is not one of " +
					Arrays.toString(a.value()));
		return proceed(o, a);
	}

	private static final <T> boolean isOneOf(T obj, T[] arr) {
		for (T el : arr) if (obj == el) return true;
		return false;
	}
}

---

Executing the main method of MyClass produces:

Exception in thread "main" java.lang.NoSuchMethodError: MyAspect.isOneOf(LMyEnum;[LMyEnum;)Z
	at MyAspect.ajc$privMethod$MyAspect$MyAspect$isOneOf(MyAspect.aj:1)
	at MyClass.test_aroundBody1$advice(MyClass.java:109)
	at MyClass.test(MyClass.java:1)
	at MyClass.main(MyClass.java:12)

---

What's interesting is that if you remove the "privileged" modifier from the aspect definition, then it works fine.
Comment 1 Andrew Clement CLA 2006-06-26 03:31:33 EDT
fix committed - will be in next dev build.  the privilege accessor generation code wasnt aware of generic methods.
Comment 2 Andrew Clement CLA 2006-06-26 04:20:45 EDT
fix available in latest AJ dev build.