Unverified Commit 98891a54 authored by Licho's avatar Licho Committed by GitHub

fix: 1.14 1.15 classloader (#2667)

* fix: 1.14 1.15 classloader Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> * Spotless Apply * refactor: 14 15 set currentThread classloader Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> * Spotless Apply * refactor: remove other current thread set classloader Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> --------- Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 6366ecd8
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package org.dinky.aop; package org.dinky.aop;
import org.dinky.data.exception.DinkyException; import org.dinky.data.exception.DinkyException;
import org.dinky.job.JobResult;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
...@@ -51,7 +50,7 @@ public class UdfClassLoaderAspect { ...@@ -51,7 +50,7 @@ public class UdfClassLoaderAspect {
@Around("allPointcut()") @Around("allPointcut()")
public Object round(ProceedingJoinPoint proceedingJoinPoint) { public Object round(ProceedingJoinPoint proceedingJoinPoint) {
Object proceed = null; Object proceed = null;
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try { try {
proceed = proceedingJoinPoint.proceed(); proceed = proceedingJoinPoint.proceed();
} catch (Throwable e) { } catch (Throwable e) {
...@@ -61,7 +60,9 @@ public class UdfClassLoaderAspect { ...@@ -61,7 +60,9 @@ public class UdfClassLoaderAspect {
e.printStackTrace(); e.printStackTrace();
throw (DinkyException) e; throw (DinkyException) e;
} finally { } finally {
if (proceed instanceof JobResult) {} if (contextClassLoader != Thread.currentThread().getContextClassLoader()) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
} }
return proceed; return proceed;
} }
......
...@@ -78,8 +78,6 @@ public final class EmailSender { ...@@ -78,8 +78,6 @@ public final class EmailSender {
return alertResult; return alertResult;
} }
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try { try {
String sendResult = MailUtil.send( String sendResult = MailUtil.send(
getMailAccount(), getMailAccount(),
......
...@@ -119,6 +119,7 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment { ...@@ -119,6 +119,7 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
executor, executor,
isStreamingMode, isStreamingMode,
userClassLoader)); userClassLoader));
Thread.currentThread().setContextClassLoader(userClassLoader);
this.executor = executor; this.executor = executor;
injectParser(new CustomParserImpl(getPlanner().getParser())); injectParser(new CustomParserImpl(getPlanner().getParser()));
injectExtendedExecutor(new CustomExtendedOperationExecutorImpl(this)); injectExtendedExecutor(new CustomExtendedOperationExecutorImpl(this));
......
...@@ -108,6 +108,7 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment { ...@@ -108,6 +108,7 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
executor, executor,
isStreamingMode, isStreamingMode,
userClassLoader)); userClassLoader));
Thread.currentThread().setContextClassLoader(userClassLoader);
injectParser(new CustomParserImpl(getPlanner().getParser())); injectParser(new CustomParserImpl(getPlanner().getParser()));
injectExtendedExecutor(new CustomExtendedOperationExecutorImpl(this)); injectExtendedExecutor(new CustomExtendedOperationExecutorImpl(this));
} }
......
...@@ -60,7 +60,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -60,7 +60,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
/** /**
...@@ -152,9 +151,6 @@ public abstract class Executor { ...@@ -152,9 +151,6 @@ public abstract class Executor {
if (executorConfig.isValidVariables()) { if (executorConfig.isValidVariables()) {
variableManager.registerVariable(executorConfig.getVariables()); variableManager.registerVariable(executorConfig.getVariables());
} }
// Fix the Classloader in the env above Flink1.16 to appClassLoader, causing ckp to fail to compile
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
ReflectUtil.setFieldValue(environment, "userClassloader", contextClassLoader);
} }
abstract CustomTableEnvironment createCustomTableEnvironment(ClassLoader classLoader); abstract CustomTableEnvironment createCustomTableEnvironment(ClassLoader classLoader);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment