Skip to content

Commit

Permalink
fix: 1.14 1.15 classloader (DataLinkDC#2667)
Browse files Browse the repository at this point in the history
* fix: 1.14 1.15 classloader

Signed-off-by: licho <[email protected]>

* Spotless Apply

* refactor: 14 15 set currentThread classloader

Signed-off-by: licho <[email protected]>

* Spotless Apply

* refactor: remove other current thread set classloader

Signed-off-by: licho <[email protected]>

---------

Signed-off-by: licho <[email protected]>
Co-authored-by: leechor <[email protected]>
  • Loading branch information
leechor and leechor authored Dec 17, 2023
1 parent 6366ecd commit 98891a5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.dinky.aop;

import org.dinky.data.exception.DinkyException;
import org.dinky.job.JobResult;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void allPointcut() {}
@Around("allPointcut()")
public Object round(ProceedingJoinPoint proceedingJoinPoint) {
Object proceed = null;

ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
proceed = proceedingJoinPoint.proceed();
} catch (Throwable e) {
Expand All @@ -61,7 +60,9 @@ public Object round(ProceedingJoinPoint proceedingJoinPoint) {
e.printStackTrace();
throw (DinkyException) e;
} finally {
if (proceed instanceof JobResult) {}
if (contextClassLoader != Thread.currentThread().getContextClassLoader()) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
return proceed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public AlertResult send(String title, String content) {
return alertResult;
}

Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

try {
String sendResult = MailUtil.send(
getMailAccount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public CustomTableEnvironmentImpl(
executor,
isStreamingMode,
userClassLoader));
Thread.currentThread().setContextClassLoader(userClassLoader);
this.executor = executor;
injectParser(new CustomParserImpl(getPlanner().getParser()));
injectExtendedExecutor(new CustomExtendedOperationExecutorImpl(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public CustomTableEnvironmentImpl(
executor,
isStreamingMode,
userClassLoader));
Thread.currentThread().setContextClassLoader(userClassLoader);
injectParser(new CustomParserImpl(getPlanner().getParser()));
injectExtendedExecutor(new CustomExtendedOperationExecutorImpl(this));
}
Expand Down
4 changes: 0 additions & 4 deletions dinky-core/src/main/java/org/dinky/executor/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import com.fasterxml.jackson.databind.node.ObjectNode;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.URLUtil;

/**
Expand Down Expand Up @@ -152,9 +151,6 @@ protected void init(DinkyClassLoader classLoader) {
if (executorConfig.isValidVariables()) {
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);
Expand Down

0 comments on commit 98891a5

Please sign in to comment.