Skip to content

Commit

Permalink
[Java] print exception for fury creation (#885)
Browse files Browse the repository at this point in the history
print exception for fury creation
  • Loading branch information
chaokunyang authored Aug 30, 2023
1 parent 463816e commit 9517c6a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions java/fury-core/src/main/java/io/fury/Fury.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.fury.type.Generics;
import io.fury.type.Type;
import io.fury.util.LoggerFactory;
import io.fury.util.Platform;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -1489,7 +1490,7 @@ public Fury build() {
// clear classLoader to avoid `LoaderBinding#furyFactory` lambda capture classLoader by
// capturing `FuryBuilder`, which make `classLoader` not able to be gc.
this.classLoader = null;
return new Fury(this, loader);
return newFury(this, loader);
}

/** Build thread safe fury. */
Expand All @@ -1505,7 +1506,7 @@ public ThreadLocalFury buildThreadLocalFury() {
// capturing `FuryBuilder`, which make `classLoader` not able to be gc.
this.classLoader = null;
ThreadLocalFury threadSafeFury =
new ThreadLocalFury(classLoader -> new Fury(FuryBuilder.this, classLoader));
new ThreadLocalFury(classLoader -> newFury(FuryBuilder.this, classLoader));
threadSafeFury.setClassLoader(loader);
return threadSafeFury;
}
Expand Down Expand Up @@ -1543,7 +1544,7 @@ public ThreadSafeFury buildThreadSafeFuryPool(
this.classLoader = null;
ThreadSafeFury threadSafeFury =
new ThreadPoolFury(
classLoader -> new Fury(FuryBuilder.this, classLoader),
classLoader -> newFury(FuryBuilder.this, classLoader),
minPoolSize,
maxPoolSize,
expireTime,
Expand All @@ -1552,4 +1553,20 @@ public ThreadSafeFury buildThreadSafeFuryPool(
return threadSafeFury;
}
}

/**
* Create Fury and print exception when failed. Many application will create fury as a static
* variable, Fury creation exception will be swallowed by {@link NoClassDefFoundError}. We print
* exception explicitly for better debugging.
*/
private static Fury newFury(FuryBuilder builder, ClassLoader classLoader) {
try {
return new Fury(builder, classLoader);
} catch (Throwable t) {
t.printStackTrace();
LOG.error("Fury creation failed with classloader {}", classLoader);
Platform.throwException(t);
throw new RuntimeException(t);
}
}
}

0 comments on commit 9517c6a

Please sign in to comment.