[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] How does an ITD access a field in the target instance via reflection?

Hi all,

Newbie question.  I have defined an inter-type declaration, and I want to be
able to access via Field.get(this) a protected or public field's value in an
instance whose class is receiving an introduced method.  For example, if
there is a field in the target object called "name", I get a runtime error
of java.lang.IllegalAccessException when the code in an introduced method
attempts to access the value of the field via Field.get(this):

public aspect NameableItd {
	declare parents:  (@HasName *) implements Nameable;
	declare soft: IllegalAccessException : execution(* *(..)) &&

	public String Nameable.getName() {
		Field field = this.getClass().getField("name"); // could be public,
protected, package or private
		if (field == null) {
			return "";
		return field.getString(this); // throws IllegalAccessException

Any reason why?  Can an ITD not access field values in an instance of the
target type via reflection inside an introduced method?

I am not running with a security manager, to my knowledge.


View this message in context: http://www.nabble.com/How-does-an-ITD-access-a-field-in-the-target-instance-via-reflection--tp24803137p24803137.html
Sent from the AspectJ - users mailing list archive at Nabble.com.