Fixes #2913 - ClassNotFoundException: sun.reflect.Reflection with JDK 11
Replaced usage of sun.reflect.Reflection with a SecurityManager subclass, so that it works in all JDKs. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
9fae0c2fa0
commit
3384ff90ea
|
@ -21,7 +21,6 @@ package org.eclipse.jetty.server.handler;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
@ -2585,19 +2584,18 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
|
||||
// no security manager just return the classloader
|
||||
if (!_usingSecurityManager)
|
||||
{
|
||||
return _classLoader;
|
||||
}
|
||||
else
|
||||
{
|
||||
// check to see if the classloader of the caller is the same as the context
|
||||
// classloader, or a parent of it
|
||||
// classloader, or a parent of it, as required by the javadoc specification.
|
||||
try
|
||||
{
|
||||
Class<?> reflect = Loader.loadClass("sun.reflect.Reflection");
|
||||
Method getCallerClass = reflect.getMethod("getCallerClass",Integer.TYPE);
|
||||
Class<?> caller = (Class<?>)getCallerClass.invoke(null,2);
|
||||
|
||||
Class<?> caller = new Caller().getCallerClass(2);
|
||||
boolean ok = false;
|
||||
ClassLoader callerLoader = caller.getClassLoader();
|
||||
ClassLoader callerLoader = caller == null ? null : caller.getClassLoader();
|
||||
while (!ok && callerLoader != null)
|
||||
{
|
||||
if (callerLoader == _classLoader)
|
||||
|
@ -3083,4 +3081,17 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
*/
|
||||
void exitScope(Context context, Request request);
|
||||
}
|
||||
|
||||
private static class Caller extends SecurityManager
|
||||
{
|
||||
public Class<?> getCallerClass(int depth)
|
||||
{
|
||||
if (depth < 0)
|
||||
return null;
|
||||
Class<?>[] classContext = getClassContext();
|
||||
if (classContext.length <= depth)
|
||||
return null;
|
||||
return classContext[depth];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue