Skip to content

Commit

Permalink
Enhance exception
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Aug 7, 2024
1 parent 1a2e2f2 commit 131e712
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/test/java/io/airlift/compress/v2/HadoopNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.CompressionCodecFactory;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.io.compress.zlib.ZlibCompressor;
import org.apache.hadoop.io.compress.zlib.ZlibDecompressor;
import org.apache.hadoop.io.compress.zlib.ZlibFactory;
import org.apache.hadoop.util.NativeCodeLoader;
Expand All @@ -25,6 +26,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -66,7 +68,16 @@ private static void requireNativeZlib()
{
Configuration conf = new Configuration();
if (!ZlibFactory.isNativeZlibLoaded(conf)) {
throw new RuntimeException("native zlib is not loaded");
Throwable cause = null;
try {
Method initIDs = ZlibCompressor.class.getDeclaredMethod("initIDs");
initIDs.setAccessible(true);
initIDs.invoke(null);
}
catch (ReflectiveOperationException e) {
cause = e;
}
throw new RuntimeException("native zlib is not loaded", cause);
}

CompressionCodecFactory factory = new CompressionCodecFactory(conf);
Expand Down

0 comments on commit 131e712

Please sign in to comment.