mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
copy context for image renderer to avoid changing class loader in common context
This commit is contained in:
@@ -39,7 +39,7 @@ public class ClassLoadingUtils {
|
||||
|
||||
public static ClassLoaderReference getClassLoader(EvaluationContext context, DebugProcess process) throws EvaluateException {
|
||||
try {
|
||||
// TODO: cache?
|
||||
// TODO [egor]: cache?
|
||||
ClassType loaderClass = (ClassType)process.findClass(context, "java.net.URLClassLoader", context.getClassLoader());
|
||||
Method ctorMethod = loaderClass.concreteMethodByName("<init>", "([Ljava/net/URL;Ljava/lang/ClassLoader;)V");
|
||||
ClassLoaderReference reference = (ClassLoaderReference)process.newInstance(context, loaderClass, ctorMethod, Arrays
|
||||
@@ -74,8 +74,13 @@ public class ClassLoadingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and if necessary defines helper class
|
||||
* May modify class loader in evaluationContext
|
||||
*/
|
||||
@Nullable
|
||||
public static ClassType getHelperClass(String name, EvaluationContext evaluationContext, DebugProcess process) throws EvaluateException {
|
||||
// TODO [egor]: cache and load in boostrap class loader
|
||||
try {
|
||||
ClassLoaderReference classLoader = evaluationContext.getClassLoader();
|
||||
return (ClassType)process.findClass(evaluationContext, name, classLoader);
|
||||
|
||||
@@ -91,12 +91,13 @@ class ImageObjectRenderer extends ToStringBasedRenderer implements FullValueEval
|
||||
private static Value getImageBytes(EvaluationContext evaluationContext, Value obj, String methodName)
|
||||
throws EvaluateException {
|
||||
DebugProcess process = evaluationContext.getDebugProcess();
|
||||
ClassType helperClass = ClassLoadingUtils.getHelperClass(ImageSerializer.class.getName(), evaluationContext, process);
|
||||
EvaluationContext copyContext = evaluationContext.createEvaluationContext(obj);
|
||||
ClassType helperClass = ClassLoadingUtils.getHelperClass(ImageSerializer.class.getName(), copyContext, process);
|
||||
|
||||
if (helperClass != null) {
|
||||
List<Method> methods = helperClass.methodsByName(methodName);
|
||||
if (!methods.isEmpty()) {
|
||||
return process.invokeMethod(evaluationContext, helperClass, methods.get(0), Collections.singletonList(obj));
|
||||
return process.invokeMethod(copyContext, helperClass, methods.get(0), Collections.singletonList(obj));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user