8035327: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp
authorpchelko
Fri, 28 Feb 2014 17:56:53 +0400
changeset 23609 e5d09a0f6bdc
parent 23608 be16345d1cec
child 23610 5eee22a40e7b
8035327: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp Reviewed-by: anthony, serb
jdk/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp
jdk/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
--- a/jdk/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp	Fri Feb 28 17:52:40 2014 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Win32GraphicsConfig.cpp	Fri Feb 28 17:56:53 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -91,6 +91,7 @@
     jobject bounds = NULL;
 
     clazz = env->FindClass("java/awt/Rectangle");
+    CHECK_NULL_RETURN(clazz, NULL);
     mid = env->GetMethodID(clazz, "<init>", "(IIII)V");
     if (mid != 0) {
         RECT rRW = {0, 0, 0, 0};
--- a/jdk/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp	Fri Feb 28 17:52:40 2014 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp	Fri Feb 28 17:56:53 2014 +0400
@@ -328,16 +328,13 @@
         jintArray bitsArray;
 
         clazz1 = env->FindClass("java/awt/color/ColorSpace");
+        CHECK_NULL_RETURN(clazz1, NULL);
         mid = env->GetStaticMethodID(clazz1, "getInstance",
               "(I)Ljava/awt/color/ColorSpace;");
-        if (mid == 0) {
-            return NULL;
-        }
+        CHECK_NULL_RETURN(mid, NULL);
         cspace = env->CallStaticObjectMethod(clazz1, mid,
             java_awt_color_ColorSpace_CS_GRAY);
-        if (cspace == 0) {
-            return NULL;
-        }
+        CHECK_NULL_RETURN(cspace, NULL);
 
         bits[0] = 8;
         bitsArray = env->NewIntArray(1);
@@ -348,13 +345,10 @@
         }
 
         clazz = env->FindClass("java/awt/image/ComponentColorModel");
-
+        CHECK_NULL_RETURN(clazz, NULL);
         mid = env->GetMethodID(clazz,"<init>",
             "(Ljava/awt/color/ColorSpace;[IZZII)V");
-
-        if (mid == 0) {
-            return NULL;
-        }
+        CHECK_NULL_RETURN(mid, NULL);
 
         awt_colormodel = env->NewObject(clazz, mid,
                                         cspace,
@@ -370,12 +364,11 @@
         jbyte vbits[256/8];
         jobject validBits = NULL;
 
+        CHECK_NULL_RETURN(hRGB, NULL);
         /* Create the LUT from the color map */
         try {
             rgb = (unsigned int *) env->GetPrimitiveArrayCritical(hRGB, 0);
-            if (rgb == NULL) {
-                return NULL;
-            }
+            CHECK_NULL_RETURN(rgb, NULL);
             rgbP = rgb;
             if (!palette) {
                 palette = new AwtPalette(this);
@@ -439,10 +432,12 @@
         // Construct a new color model
         if (!allvalid) {
             jbyteArray bArray = env->NewByteArray(sizeof(vbits));
+            CHECK_NULL_RETURN(bArray, NULL);
             env->SetByteArrayRegion(bArray, 0, sizeof(vbits), vbits);
             validBits = JNU_NewObjectByName(env,
                                             "java/math/BigInteger",
                                             "([B)V", bArray);
+            JNU_CHECK_EXCEPTION_RETURN(env, NULL);
         }
         awt_colormodel =
             JNU_NewObjectByName(env,
@@ -500,19 +495,22 @@
         jintArray cacheArray = (jintArray)env->GetObjectField(colorModel,
             AwtWin32GraphicsDevice::indexCMcacheID);
         if (!rgbArray || !cacheArray) {
-            JNU_ThrowInternalError(env,
-                "rgb or lookupcache array of IndexColorModel null");
+            JNU_ThrowInternalError(env, "rgb or lookupcache array of IndexColorModel null");
             return;
         }
         int rgbLength = env->GetArrayLength(rgbArray);
         int cacheLength = env->GetArrayLength(cacheArray);
-        jint *cmEntries = (jint *)env->GetPrimitiveArrayCritical(rgbArray,
-            &isCopy);
-        jint *cache = (jint *)env->GetPrimitiveArrayCritical(cacheArray,
-            &isCopy);
-        if (!cmEntries || !cache) {
-            JNU_ThrowInternalError(env,
-                "Problem retrieving rgb or cache critical array");
+        jint *cmEntries = (jint *)env->GetPrimitiveArrayCritical(rgbArray, &isCopy);
+        if (!cmEntries) {
+            env->ExceptionClear();
+            JNU_ThrowInternalError(env, "Problem retrieving rgb critical array");
+            return;
+        }
+        jint *cache = (jint *)env->GetPrimitiveArrayCritical(cacheArray, &isCopy);
+        if (!cache) {
+            env->ExceptionClear();
+            env->ReleasePrimitiveArrayCritical(rgbArray, cmEntries, JNI_ABORT);
+            JNU_ThrowInternalError(env, "Problem retrieving cache critical array");
             return;
         }
         // Set the new rgb values
@@ -839,31 +837,36 @@
     /* class ids */
     AwtWin32GraphicsDevice::indexCMClass =
         (jclass)env->NewGlobalRef(env->FindClass("java/awt/image/IndexColorModel"));
+    DASSERT(AwtWin32GraphicsDevice::indexCMClass);
+    CHECK_NULL(AwtWin32GraphicsDevice::indexCMClass);
+
     AwtWin32GraphicsDevice::wToolkitClass =
         (jclass)env->NewGlobalRef(env->FindClass("sun/awt/windows/WToolkit"));
-
-    DASSERT(AwtWin32GraphicsDevice::indexCMClass);
     DASSERT(AwtWin32GraphicsDevice::wToolkitClass);
+    CHECK_NULL(AwtWin32GraphicsDevice::wToolkitClass);
 
     /* field ids */
     AwtWin32GraphicsDevice::dynamicColorModelID = env->GetFieldID(cls,
         "dynamicColorModel", "Ljava/awt/image/ColorModel;");
+    DASSERT(AwtWin32GraphicsDevice::dynamicColorModelID);
+    CHECK_NULL(AwtWin32GraphicsDevice::dynamicColorModelID);
+
     AwtWin32GraphicsDevice::indexCMrgbID =
         env->GetFieldID(AwtWin32GraphicsDevice::indexCMClass, "rgb", "[I");
+    DASSERT(AwtWin32GraphicsDevice::indexCMrgbID);
+    CHECK_NULL(AwtWin32GraphicsDevice::indexCMrgbID);
+
     AwtWin32GraphicsDevice::indexCMcacheID =
         env->GetFieldID(AwtWin32GraphicsDevice::indexCMClass,
         "lookupcache", "[I");
+    DASSERT(AwtWin32GraphicsDevice::indexCMcacheID);
+    CHECK_NULL(AwtWin32GraphicsDevice::indexCMcacheID);
 
     /* method ids */
     AwtWin32GraphicsDevice::paletteChangedMID = env->GetStaticMethodID(
         AwtWin32GraphicsDevice::wToolkitClass, "paletteChanged", "()V");
-
-
-    DASSERT(AwtWin32GraphicsDevice::dynamicColorModelID);
-    DASSERT(AwtWin32GraphicsDevice::indexCMrgbID);
-    DASSERT(AwtWin32GraphicsDevice::indexCMcacheID);
-
     DASSERT(AwtWin32GraphicsDevice::paletteChangedMID);
+    CHECK_NULL(AwtWin32GraphicsDevice::paletteChangedMID);
 
     // Only want to call this once per session
     make_uns_ordered_dither_array(img_oda_alpha, 256);
@@ -1069,16 +1072,15 @@
 
     jclass displayModeClass = env->FindClass("java/awt/DisplayMode");
     if (JNU_IsNull(env, displayModeClass)) {
-        JNU_ThrowInternalError(env,
-            "Could not get display mode class");
+        env->ExceptionClear();
+        JNU_ThrowInternalError(env, "Could not get display mode class");
         return NULL;
     }
 
-    jmethodID cid = env->GetMethodID(displayModeClass, "<init>",
-        "(IIII)V");
+    jmethodID cid = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
     if (cid == NULL) {
-        JNU_ThrowInternalError(env,
-            "Could not get display mode constructor");
+        env->ExceptionClear();
+        JNU_ThrowInternalError(env, "Could not get display mode constructor");
         return NULL;
     }
 
@@ -1224,6 +1226,7 @@
         jmethodID mid = env->GetMethodID(arrayListClass, "add",
         "(Ljava/lang/Object;)Z");
         if (mid == NULL) {
+            env->ExceptionClear();
             JNU_ThrowInternalError(env,
                 "Could not get method java.util.ArrayList.add()");
             return;
@@ -1264,6 +1267,7 @@
         if (dm.dmBitsPerPel >= 8) {
             addDisplayMode(env, arrayList, dm.dmPelsWidth, dm.dmPelsHeight,
                            dm.dmBitsPerPel, dm.dmDisplayFrequency);
+            JNU_CHECK_EXCEPTION(env);
         }
     }