NullPointerException while trying to invoke method on private field using
Reflection
The original issue is described How to run method on private field using
reflection?
The class is
public class SecureResource {
private HttpServletRequest request;
// more things
}
Based on @Jon answer
(Where resource is a reference to the relevant instance of SecureResource.)
I did the following
Class cls = response.getResourceClass();
Object obj = cls.newInstance();
Field f = cls.getDeclaredField("request");
f.setAccessible(true);
HttpServletRequest request = (HttpServletRequest) f.get(obj);
String auth = request.getHeader("X-AUTH");
and I get request as null
and the Field f is not null
private javax.servlet.http.HttpServletRequest
com.sunrunhome.blackbird.service.SecureResource.request
Please let me know where I am making mistakes here?
No comments:
Post a Comment