Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] RE: aspectj-users digest, Vol 1 #242 - 4 msgs

Dear Ron,

Thank u for your answer, but I don't think it answers the problem

When I had the method showClassContent() directly in the ExampleMain, it
works !
But when the aspect weaves it in ExampleMain, only the public field's
values are accessible and not the private ones :(

Best regards,
Alain van den Hove

------------Original Message-------------
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Accessing private fields
From: "Ron Bodkin" <rbodkin@xxxxxxxxxxx>
Date: Tue, 12 Aug 2003 09:31:31 -0700
Reply-To: aspectj-users@xxxxxxxxxxx

Alain,

Remember that getDeclaredFields() will only return the fields declared
on the class itself, not on its superclasses. If you want all the fields
for an instance, you need to walk up the inheritance hierarchy using
Class.getSuperclass() and get the declared fields on each.

Ron

Ron Bodkin
Chief Technology Officer
New Aspects of Security
m: (415) 509-2895

> ------------Original Message-------------
> From: "Alain van den Hove" <A_vandenHove@xxxxxxxxxx>
> To: <aspectj-users@xxxxxxxxxxx>
> Date: Tue, Aug-12-2003 1:06 AM
> Subject: [aspectj-users] Accessing private fields
> 
> 
> 
> Hello everybody!
> 
> I'm trying to access private fields by reflection to get a class's 
> contents, it doesn't work unless i had the code directly into the 
> class that i want to inspect
> 
> In this aspect, I had the function showClassContent() to the class 
> ExampleMain that I want to inspect :
> 
> public aspect TraceMyClasses {
> 
> public void ExampleMain.showClassContent() {
> 	Field[] fieldTab = this.getClass().getDeclaredFields();
> 	for(int i=0;i<fieldTab.length-1;i++) {
> 		String fieldName = fieldTab[i].getName();
> 		String fieldValue;
> 		try {
> 			fieldValue=fieldTab[i].get(this).toString();
> 		} catch (IllegalAccessException e) {
> 			fieldValue="Unable to access";
> 		}
> 	}
> 
> void around (ExampleMain myClass, Object arg): execution(void *.*(..))
> 	   && this(myClass) && args(arg) {
> 		try { proceed(myClass,arg); }
> 		catch (Exception e) {
> 			myClass.showClassContent();
> 		}	
> 	}
> }
> 
> But I can't get the value of private fields.. How can I do ?
> 
> Thanks in advance
> Alain


Back to the top