The Artima Developer Community
Sponsored Link

Java Answers Forum
Urgent help regarding Reflection

4 replies on 1 page. Most recent reply: Apr 12, 2002 12:59 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Mohit Gupta

Posts: 15
Nickname: mohit
Registered: Mar, 2002

Urgent help regarding Reflection Posted: Apr 12, 2002 4:46 AM
Reply to this message Reply
Advertisement
is there any way to access package accissible field of any class through reflection, and then can we change value assingned to it??


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Urgent help regarding Reflection Posted: Apr 12, 2002 10:14 AM
Reply to this message Reply
I haven't tried this, but I think you need to set up the security policy with java.lang.reflect.ReflectPermission.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Urgent help regarding Reflection Posted: Apr 12, 2002 10:17 AM
Reply to this message Reply
More specifically, try a policy file with this content:
grant {
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};

Mohit Gupta

Posts: 15
Nickname: mohit
Registered: Mar, 2002

Re: Urgent help regarding Reflection Posted: Apr 12, 2002 11:01 AM
Reply to this message Reply
Thanx for ur quick reply Mr. Matt, i haven't tried ur suggestion till now but will try it, but besides it i have resolved my problem by using code :

got the reqdField by getDeclaredFields(), and then make its accessibility status true by :

reqdField.setAccessible(true);

and change its value to desired one..and it turned into desired result.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Urgent help regarding Reflection Posted: Apr 12, 2002 12:59 PM
Reply to this message Reply
Sounds like your security policy was already loose enough, because this is what the documentation says:

If there is a security manager, this method first calls the security manager's checkMemberAccess method with this and Member.DECLARED as its arguments. If the class is in a package, then this method also calls the security manager's checkPackageAccess method with the package name as its argument. Either of these calls could result in a SecurityException.

If you are working outside the package in question and you didn't get a SecurityException, then your policy is already permissive enough. Maybe you were already using policy.all:
grant {
    permission java.security.AllPermission "", "";
};

Flat View: This topic has 4 replies on 1 page
Topic: Amazing Job Openings Previous Topic   Next Topic Topic: Export XLS and CSV Files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use