diff --git a/jdk/src/share/native/java/util/zip/Deflater.c b/jdk/src/share/native/java/util/zip/Deflater.c index a9f403db172..d7f751d37a9 100644 --- a/jdk/src/share/native/java/util/zip/Deflater.c +++ b/jdk/src/share/native/java/util/zip/Deflater.c @@ -1,5 +1,5 @@ /* - * 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 @@ -49,13 +49,21 @@ 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 @@ -132,14 +140,14 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, 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; } @@ -158,7 +166,7 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr, 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; diff --git a/jdk/src/share/native/java/util/zip/Inflater.c b/jdk/src/share/native/java/util/zip/Inflater.c index 3778ff4e40c..2e21d084b39 100644 --- a/jdk/src/share/native/java/util/zip/Inflater.c +++ b/jdk/src/share/native/java/util/zip/Inflater.c @@ -1,5 +1,5 @@ /* - * 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 @@ -50,10 +50,15 @@ JNIEXPORT void JNICALL Java_java_util_zip_Inflater_initIDs(JNIEnv *env, jclass cls) { needDictID = (*env)->GetFieldID(env, cls, "needDict", "Z"); + CHECK_NULL(needDictID); 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 @@ -127,14 +132,14 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr, in_buf = (*env)->GetPrimitiveArrayCritical(env, this_buf, 0); if (in_buf == NULL) { - 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; } @@ -154,7 +159,7 @@ Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr, 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_NEED_DICT: (*env)->SetBooleanField(env, this, needDictID, JNI_TRUE); /* Might have consumed some input here! */ diff --git a/jdk/src/share/native/java/util/zip/ZipFile.c b/jdk/src/share/native/java/util/zip/ZipFile.c index d66cccb747a..5fd4936a803 100644 --- a/jdk/src/share/native/java/util/zip/ZipFile.c +++ b/jdk/src/share/native/java/util/zip/ZipFile.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -71,11 +71,13 @@ ThrowZipException(JNIEnv *env, const char *msg) if (msg != NULL) { s = JNU_NewStringPlatform(env, msg); } - x = JNU_NewObjectByName(env, + if (s != NULL) { + x = JNU_NewObjectByName(env, "java/util/zip/ZipException", "(Ljava/lang/String;)V", s); - if (x != NULL) { - (*env)->Throw(env, x); + if (x != NULL) { + (*env)->Throw(env, x); + } } } @@ -367,8 +369,10 @@ Java_java_util_jar_JarFile_getMetaInfEntryNames(JNIEnv *env, jobject obj) /* If some names were found then build array of java strings */ if (count > 0) { - jclass cls = (*env)->FindClass(env, "java/lang/String"); + jclass cls = JNU_ClassString(env); + CHECK_NULL_RETURN(cls, NULL); result = (*env)->NewObjectArray(env, count, cls, 0); + CHECK_NULL_RETURN(result, NULL); if (result != 0) { for (i = 0; i < count; i++) { jstring str = (*env)->NewStringUTF(env, zip->metanames[i]);