snuyanzin commented on code in PR #29356:
URL: https://github.com/apache/flink/pull/29356#discussion_r4164557046
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/generated/CompileUtils.java:
##########
@@ -95,8 +107,32 @@ public static <T> Class<T> compile(ClassLoader cl, String
name, String code) {
}
}
+ @SuppressWarnings("unchecked")
private static <T> Class<T> doCompile(ClassLoader cl, String name, String
code) {
checkNotNull(cl, "Classloader must not be null.");
+ // Generated code only references types that resolve the same way
under every classloader,
+ // so the bytecode is cooked once per code and defined into cl.
+ final Map<String, byte[]> byteCodes = sharedByteCode(cl, name, code);
+ try {
+ return (Class<T>) new ByteArrayClassLoader(cl,
byteCodes).loadClass(name);
+ } catch (ClassNotFoundException e) {
+ throw new FlinkRuntimeException("Can not load class " + name, e);
+ }
+ }
+
+ private static Map<String, byte[]> sharedByteCode(ClassLoader cl, String
name, String code) {
+ try {
+ return BYTECODE_CACHE.get(code, () -> cook(cl, name, code));
Review Comment:
it looks like claude is trying to apply general java problem to Flink's code
gen.
And this is invalid approach
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]