2

I used some code from another question to access the private field "classes" in the Java ClassLoader. This works fine, however when I move it to an applet it gets messed up with this exception: access denied (java.lang.RuntimePermission accessDeclaredMembers). I've done some searching and tried using PrivlegedExceptionAction to skip that, but it isn't working. So my question is this: is is possible to bypass this, and if not what is another way to get a list of classes?

Reflection Code:

final ClassLoader cLoader = getClass().getClassLoader();
            final Field f = ClassLoader.class.getDeclaredField("classes");
            AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws Exception {
                        f.setAccessible(true);
                        return null;}});
            Vector<Class> classes = (Vector<Class>)f.get(cLoader);
            cList.addAll(classes);
5
  • Also, I'd like to avoid using a policy file. Commented Sep 6, 2012 at 14:21
  • 1
    I used some code from another question which question ? Commented Sep 6, 2012 at 14:30
  • @jérôme This question (stackoverflow.com/questions/2681459/…) Commented Sep 6, 2012 at 15:04
  • What are you trying to achieve using this and Greenfoot? You can't do this on an applet if you expect it to go on greenfoot.org, but depending on your task there may be another way. Commented Oct 8, 2012 at 14:13
  • This is for a request someone made, I'm trying to get it to work. Commented Oct 8, 2012 at 22:29

1 Answer 1

2

Digitally sign the applet code (then get the user to accept it when prompted) to gain full privileges.

Sign up to request clarification or add additional context in comments.

5 Comments

Sorry I forgot to mention this but I am using greenfoot to do this (it has to be done in this program) and I cannot make a digital signature unless I could do it programmatically.
(shrugs) Whether it is 'greenfoot' or paper, glue & sparkles used to make the applet does not matter. The answer to your question remains the same.
I can't make a digital signature because I am not in control of the upload.
I'm having the exact same problem with an app that is digitally signed, what do you recommend in that case?
@BrianKnoblauch I recommend you ask your own question, link to this one, and explain the differences. Name the exact JRE version this occurs in. Security has been tightened in recent times/JREs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.