8068338: Better message about incompatible zlib in Deflater.init
authorigerasim
Tue, 30 Dec 2014 00:11:00 +0300
changeset 28258 381e960842b6
parent 28257 070ef0dc9f5c
child 28259 ec8d2eb85cc0
8068338: Better message about incompatible zlib in Deflater.init Reviewed-by: alanb, sherman
jdk/src/java.base/share/native/libzip/Deflater.c
--- a/jdk/src/java.base/share/native/libzip/Deflater.c	Mon Dec 29 09:10:15 2014 -0800
+++ b/jdk/src/java.base/share/native/libzip/Deflater.c	Tue Dec 30 00:11:00 2014 +0300
@@ -76,10 +76,11 @@
         JNU_ThrowOutOfMemoryError(env, 0);
         return jlong_zero;
     } else {
-        char *msg;
-        switch (deflateInit2(strm, level, Z_DEFLATED,
-                             nowrap ? -MAX_WBITS : MAX_WBITS,
-                             DEF_MEM_LEVEL, strategy)) {
+        const char *msg;
+        int ret = deflateInit2(strm, level, Z_DEFLATED,
+                               nowrap ? -MAX_WBITS : MAX_WBITS,
+                               DEF_MEM_LEVEL, strategy);
+        switch (ret) {
           case Z_OK:
             return ptr_to_jlong(strm);
           case Z_MEM_ERROR:
@@ -91,7 +92,11 @@
             JNU_ThrowIllegalArgumentException(env, 0);
             return jlong_zero;
           default:
-            msg = strm->msg;
+            msg = ((strm->msg != NULL) ? strm->msg :
+                   (ret == Z_VERSION_ERROR) ?
+                   "zlib returned Z_VERSION_ERROR: "
+                   "compile time and runtime zlib implementations differ" :
+                   "unknown error initializing zlib library");
             free(strm);
             JNU_ThrowInternalError(env, msg);
             return jlong_zero;