src/share/native/java/util/zip/Deflater.c

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -47,17 +47,25 @@
 
 JNIEXPORT void JNICALL
 Java_java_util_zip_Deflater_initIDs(JNIEnv *env, jclass cls)
 {
     levelID = (*env)->GetFieldID(env, cls, "level", "I");
+    CHECK_NULL(levelID);
     strategyID = (*env)->GetFieldID(env, cls, "strategy", "I");
+    CHECK_NULL(strategyID);
     setParamsID = (*env)->GetFieldID(env, cls, "setParams", "Z");
+    CHECK_NULL(setParamsID);
     finishID = (*env)->GetFieldID(env, cls, "finish", "Z");
+    CHECK_NULL(finishID);
     finishedID = (*env)->GetFieldID(env, cls, "finished", "Z");
+    CHECK_NULL(finishedID);
     bufID = (*env)->GetFieldID(env, cls, "buf", "[B");
+    CHECK_NULL(bufID);
     offID = (*env)->GetFieldID(env, cls, "off", "I");
+    CHECK_NULL(offID);
     lenID = (*env)->GetFieldID(env, cls, "len", "I");
+    CHECK_NULL(lenID);
 }
 
 JNIEXPORT jlong JNICALL
 Java_java_util_zip_Deflater_init(JNIEnv *env, jclass cls, jint level,
                                  jint strategy, jboolean nowrap)

@@ -130,18 +138,18 @@
         int level = (*env)->GetIntField(env, this, levelID);
         int strategy = (*env)->GetIntField(env, this, strategyID);
         in_buf = (*env)->GetPrimitiveArrayCritical(env, this_buf, 0);
         if (in_buf == NULL) {
             // Throw OOME only when length is not zero
-            if (this_len != 0)
+            if (this_len != 0 && (*env)->ExceptionOccurred(env) == NULL)
                 JNU_ThrowOutOfMemoryError(env, 0);
             return 0;
         }
         out_buf = (*env)->GetPrimitiveArrayCritical(env, b, 0);
         if (out_buf == NULL) {
             (*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0);
-            if (len != 0)
+            if (len != 0 && (*env)->ExceptionOccurred(env) == NULL)
                 JNU_ThrowOutOfMemoryError(env, 0);
             return 0;
         }
 
         strm->next_in = (Bytef *) (in_buf + this_off);

@@ -156,11 +164,11 @@
         case Z_OK:
             (*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
             this_off += this_len - strm->avail_in;
             (*env)->SetIntField(env, this, offID, this_off);
             (*env)->SetIntField(env, this, lenID, strm->avail_in);
-            return len - strm->avail_out;
+            return (jint) (len - strm->avail_out);
         case Z_BUF_ERROR:
             (*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
             return 0;
         default:
             JNU_ThrowInternalError(env, strm->msg);