Java Reflection Resolution Error

I am trying to load a class via URLClassLoader (well, it does not work with a regular class loader) and does not want them to have any rights.

Therefore, I created my own security manager, which generates a key at startup, which can be requested only once (in the main thread). The security manager has 2 lists, applicationThread, which will be granted any right and a temporary list that will be granted one right only once (this is a reflection).

How very difficult to describe, I decided to download all of this: see the link below

Ok, back: I created a WatchDog thread that checks to see if the thread is too busy.

When I now start an instance of two classes from URLClassLoader, I call exactly 30 methods without any errors, but with the 31st call, he tries to check the permissions for the next, but this only happens after the 30th call.

java.lang.RuntimePermission accessClassInPackage.sun.reflect),

Does anyone know what is going on there?

edit: I managed to remove an example. http://myxcode.at/securitymanager.zip I found out that the SecurityManager is not set synchronously. Just run this small piece of code and look at the red lines.

If the red lines are on the first line, just run the program again, you will find that it is a little uncontrollable.

, . , (?) http://pastebin.com/E9yLRLif

edit2: , ? , ?

+5
1

, i=15:

checkPermission ((java.lang.RuntimePermission accessClassInPackage.sun.reflect)) [main, 5, main]

inflationThreshold ReflectionFactory, invoke NativeMethodAccessorImpl.java:

public Object invoke(Object obj, Object[] args)
        throws IllegalArgumentException, InvocationTargetException {
    if (++numInvocations > ReflectionFactory.inflationThreshold()) {
        MethodAccessorImpl acc = (MethodAccessorImpl) new MethodAccessorGenerator()
                .generateMethod(method.getDeclaringClass(), method
                        .getName(), method.getParameterTypes(),
                        method.getReturnType(), method
                                .getExceptionTypes(), method
                                .getModifiers());
        parent.setDelegate(acc);
    }

    return invoke0(method, obj, args);
}

, API Reflection:)

Field hack = Class.forName("sun.reflect.ReflectionFactory").getDeclaredField("inflationThreshold");
hack.setAccessible(true);
hack.set(null, 0);
+4

All Articles