This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 497fe0af fix(java): fix classloader get npe (#1792)
497fe0af is described below

commit 497fe0af970c4a40d5b20e4323e9f9736171fdb4
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Aug 5 20:13:47 2024 +0800

    fix(java): fix classloader get npe (#1792)
    
    ## What does this PR do?
    
     fix classloader get npe
    
    ## Related issues
    
    Closes #1763
    
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fury/issues/new/choose) describing the
    need to do so and update the document if necessary.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    -->
---
 .../src/main/java/org/apache/fury/config/FuryBuilder.java      |  3 +++
 .../java/org/apache/fury/pool/FuryPooledObjectFactory.java     | 10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git 
a/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java 
b/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java
index 4d5c9686..ebd9fb8b 100644
--- a/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java
+++ b/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java
@@ -321,6 +321,9 @@ public final class FuryBuilder {
   private void finish() {
     if (classLoader == null) {
       classLoader = Thread.currentThread().getContextClassLoader();
+      if (classLoader == null) {
+        classLoader = Fury.class.getClassLoader();
+      }
     }
     if (language != Language.JAVA) {
       stringRefIgnored = false;
diff --git 
a/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
 
b/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
index 56033bf5..17e56a63 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
@@ -50,7 +50,14 @@ public class FuryPooledObjectFactory {
 
   /** ThreadLocal: ClassLoader. */
   private final ThreadLocal<ClassLoader> classLoaderLocal =
-      ThreadLocal.withInitial(() -> 
Thread.currentThread().getContextClassLoader());
+      ThreadLocal.withInitial(
+          () -> {
+            ClassLoader loader = 
Thread.currentThread().getContextClassLoader();
+            if (loader == null) {
+              loader = Fury.class.getClassLoader();
+            }
+            return loader;
+          });
 
   /**
    * Dynamic capacity expansion and contraction The user sets the minimum 
number of object pools.
@@ -84,6 +91,7 @@ public class FuryPooledObjectFactory {
   public ClassLoaderFuryPooled getPooledCache() {
     try {
       ClassLoader classLoader = classLoaderLocal.get();
+      assert classLoader != null;
       ClassLoaderFuryPooled classLoaderFuryPooled =
           classLoaderFuryPooledCache.getIfPresent(classLoader);
       if (classLoaderFuryPooled == null) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to