klaudworks opened a new pull request, #514:
URL: https://github.com/apache/flink-agents/pull/514

   ## Summary
   
   This PR fixes `ClassNotFoundException` when loading user-defined resource 
classes (e.g., custom `ChatModel` implementations like 
`AzureOpenAIChatModelSetup`) from user JARs uploaded via the REST API.
   
   ## Problem
   
   When `flink-agents-dist.jar` is deployed in `/opt/flink/lib`, it is loaded 
by the **System ClassLoader**. User JARs uploaded at runtime are loaded by 
Flink's **User ClassLoader** (a child of the System ClassLoader).
   
   The existing code uses `Class.forName(className)` which uses the caller's 
classloader (System ClassLoader). Due to Java's parent-first delegation model, 
the System ClassLoader cannot see classes in its child classloaders, resulting 
in `ClassNotFoundException`.
   
   ## Solution
   
   Use the **Thread Context ClassLoader (TCCL)** instead:
   
   ```java
   Class.forName(className, true, 
Thread.currentThread().getContextClassLoader())
   ```
   
   Flink sets the TCCL to the User ClassLoader before executing user code, 
making user-defined classes accessible to framework code.
   
   ## Files Changed
   
   - `JavaResourceProvider.java` - Main resource instantiation
   - `JavaSerializableResourceProvider.java` - Serializable resource 
deserialization  
   - `AgentPlan.java` - PythonResourceWrapper class checks
   - `ActionJsonDeserializer.java` - Parameter type and config deserialization
   - `FunctionToolJsonDeserializer.java` - Parameter type deserialization
   - `EventLogRecordJsonDeserializer.java` - Event class deserialization
   
   ## Testing
   
   Validated in a Flink 1.20 cluster with flink-agents, successfully loading 
custom `AzureOpenAIChatModelSetup` classes from user JARs uploaded via the REST 
API.


-- 
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]

Reply via email to