8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
authorpchelko
Tue, 25 Mar 2014 16:31:02 +0400
changeset 24130 db72fc72f87b
parent 23699 fa664c1f28c1
child 24131 740d55cc7975
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings Reviewed-by: serb, anthony
jdk/src/solaris/native/sun/awt/CUPSfuncs.c
jdk/src/solaris/native/sun/awt/X11Color.c
jdk/src/solaris/native/sun/awt/awt.h
jdk/src/solaris/native/sun/awt/awt_AWTEvent.c
jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c
jdk/src/solaris/native/sun/awt/awt_Font.c
jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
jdk/src/solaris/native/sun/awt/awt_InputMethod.c
jdk/src/solaris/native/sun/awt/awt_Insets.c
jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
jdk/src/solaris/native/sun/awt/awt_Robot.c
jdk/src/solaris/native/sun/awt/awt_UNIXToolkit.c
jdk/src/solaris/native/sun/awt/awt_util.c
jdk/src/solaris/native/sun/awt/fontpath.c
jdk/src/solaris/native/sun/awt/initIDs.c
jdk/src/solaris/native/sun/awt/multi_font.c
jdk/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c
--- a/jdk/src/solaris/native/sun/awt/CUPSfuncs.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/CUPSfuncs.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -213,6 +213,8 @@
 
     name = (*env)->GetStringUTFChars(env, printer, NULL);
     if (name == NULL) {
+        (*env)->ExceptionClear(env);
+        JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
         return NULL;
     }
 
@@ -220,12 +222,10 @@
     // unlink() must be caled to remove the file when finished using it.
     filename = j2d_cupsGetPPD(name);
     (*env)->ReleaseStringUTFChars(env, printer, name);
+    CHECK_NULL_RETURN(filename, NULL);
 
     cls = (*env)->FindClass(env, "java/lang/String");
-
-    if (filename == NULL) {
-        return NULL;
-    }
+    CHECK_NULL_RETURN(cls, NULL);
 
     if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
         unlink(filename);
@@ -249,6 +249,7 @@
             unlink(filename);
             j2d_ppdClose(ppd);
             DPRINTF("CUPSfuncs::bad alloc new array\n", "")
+            (*env)->ExceptionClear(env);
             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
             return NULL;
         }
@@ -323,6 +324,11 @@
     ppd_size_t *size;
 
     const char *name = (*env)->GetStringUTFChars(env, printer, NULL);
+    if (name == NULL) {
+        (*env)->ExceptionClear(env);
+        JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
+        return NULL;
+    }
     const char *filename;
     int i;
     jobjectArray sizeArray = NULL;
@@ -332,9 +338,7 @@
     // unlink() must be called to remove the file after using it.
     filename = j2d_cupsGetPPD(name);
     (*env)->ReleaseStringUTFChars(env, printer, name);
-    if (filename == NULL) {
-        return NULL;
-    }
+    CHECK_NULL_RETURN(filename, NULL);
     if ((ppd = j2d_ppdOpenFile(filename)) == NULL) {
         unlink(filename);
         DPRINTF("unable to open PPD  %s\n", filename)
@@ -350,11 +354,19 @@
             unlink(filename);
             j2d_ppdClose(ppd);
             DPRINTF("CUPSfuncs::bad alloc new float array\n", "")
+            (*env)->ExceptionClear(env);
             JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
             return NULL;
         }
 
         dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL);
+        if (dims == NULL) {
+            unlink(filename);
+            j2d_ppdClose(ppd);
+            (*env)->ExceptionClear(env);
+            JNU_ThrowOutOfMemoryError(env, "Could not create printer name");
+            return NULL;
+        }
         for (i = 0; i<option->num_choices; i++) {
             choice = (option->choices)+i;
             size = j2d_ppdPageSize(ppd, choice->choice);
--- a/jdk/src/solaris/native/sun/awt/X11Color.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/X11Color.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -892,11 +892,10 @@
     jmethodID mid;
 
     clazz = (*env)->FindClass(env,"java/awt/color/ColorSpace");
+    CHECK_NULL_RETURN(clazz, NULL);
     mid = (*env)->GetStaticMethodID(env, clazz, "getInstance",
                                     "(I)Ljava/awt/color/ColorSpace;");
-    if (mid == NULL) {
-        return NULL;
-    }
+    CHECK_NULL_RETURN(mid, NULL);
 
     /* SECURITY: This is safe, because static methods cannot
      *           be overridden, and this method does not invoke
@@ -919,6 +918,11 @@
         (aData->awt_depth >= 15))
     {
         clazz = (*env)->FindClass(env,"java/awt/image/DirectColorModel");
+        if (clazz == NULL) {
+            (*env)->PopLocalFrame(env, 0);
+            return NULL;
+        }
+
         if (!aData->isTranslucencySupported) {
 
             mid = (*env)->GetMethodID(env,clazz,"<init>","(IIIII)V");
@@ -1005,6 +1009,10 @@
         }
 
         clazz = (*env)->FindClass(env,"java/awt/image/ComponentColorModel");
+        if (clazz == NULL) {
+            (*env)->PopLocalFrame(env, 0);
+            return NULL;
+        }
 
         mid = (*env)->GetMethodID(env,clazz,"<init>",
             "(Ljava/awt/color/ColorSpace;[IZZII)V");
@@ -1253,6 +1261,7 @@
     if (!JNU_IsNull(env,this))
     {
         SYSCLR_class = (*env)->FindClass(env, "java/awt/SystemColor");
+        CHECK_NULL_RETURN(SYSCLR_class, 0);
 
         if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
                 /* SECURITY: This is safe, because there is no way
@@ -1264,6 +1273,7 @@
                                           ,this
                                           ,"getRGB"
                                           ,"()I").i;
+                JNU_CHECK_EXCEPTION_RETURN(env, 0);
         } else {
                 col = (int)(*env)->GetIntField(env,this,colorValueID);
         }
@@ -1370,6 +1380,8 @@
             AWT_UNLOCK ();
         }
         sysColors = (*env)->FindClass (env, "java/awt/SystemColor");
+        CHECK_NULL(sysColors);
+
         if (lock) {
             AWT_LOCK ();
         }
@@ -1377,6 +1389,13 @@
                                                    "systemColors",
                                                    "[I");
 
+        if (colorID == NULL) {
+            if (lock) {
+                AWT_UNLOCK();
+            }
+            return;
+        }
+
         colors = (jintArray) (*env)->GetStaticObjectField
                                                 (env, sysColors, colorID);
 
--- a/jdk/src/solaris/native/sun/awt/awt.h	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt.h	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -77,8 +77,22 @@
 
 #define AWT_LOCK_IMPL() \
     (*env)->CallStaticVoidMethod(env, tkClass, awtLockMID)
+
 #define AWT_NOFLUSH_UNLOCK_IMPL() \
-    (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID)
+    do { \
+      jthrowable pendingException; \
+      if ((pendingException = (*env)->ExceptionOccurred(env)) != NULL) { \
+         (*env)->ExceptionClear(env); \
+      } \
+      (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID); \
+      if (pendingException) { \
+         if ((*env)->ExceptionCheck(env)) { \
+            (*env)->ExceptionDescribe(env); \
+            (*env)->ExceptionClear(env); \
+         } \
+         (*env)->Throw(env, pendingException); \
+      } \
+    } while (0)
 #define AWT_WAIT_IMPL(tm) \
     (*env)->CallStaticVoidMethod(env, tkClass, awtWaitMID, (jlong)(tm))
 #define AWT_NOTIFY_IMPL() \
--- a/jdk/src/solaris/native/sun/awt/awt_AWTEvent.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_AWTEvent.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2011, 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
@@ -49,22 +49,22 @@
 JNIEXPORT void JNICALL
 Java_java_awt_AWTEvent_initIDs(JNIEnv *env, jclass cls)
 {
-    awtEventIDs.bdata = (*env)->GetFieldID(env, cls, "bdata", "[B");
-    awtEventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z");
-    awtEventIDs.id = (*env)->GetFieldID(env, cls, "id", "I");
+    CHECK_NULL(awtEventIDs.bdata = (*env)->GetFieldID(env, cls, "bdata", "[B"));
+    CHECK_NULL(awtEventIDs.consumed = (*env)->GetFieldID(env, cls, "consumed", "Z"));
+    CHECK_NULL(awtEventIDs.id = (*env)->GetFieldID(env, cls, "id", "I"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_event_InputEvent_initIDs(JNIEnv *env, jclass cls)
 {
-    inputEventIDs.modifiers = (*env)->GetFieldID(env, cls, "modifiers", "I");
+    CHECK_NULL(inputEventIDs.modifiers = (*env)->GetFieldID(env, cls, "modifiers", "I"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_event_KeyEvent_initIDs(JNIEnv *env, jclass cls)
 {
-    keyEventIDs.keyCode = (*env)->GetFieldID(env, cls, "keyCode", "I");
-    keyEventIDs.keyChar = (*env)->GetFieldID(env, cls, "keyChar", "C");
+    CHECK_NULL(keyEventIDs.keyCode = (*env)->GetFieldID(env, cls, "keyCode", "I"));
+    CHECK_NULL(keyEventIDs.keyChar = (*env)->GetFieldID(env, cls, "keyChar", "C"));
 }
 
 JNIEXPORT void JNICALL
--- a/jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -78,6 +78,8 @@
 
     /* Make sure the target is a java.awt.Component */
     componentClass = (*env)->FindClass(env, "java/awt/Component");
+    CHECK_NULL_RETURN(componentClass, (jint)JAWT_LOCK_ERROR);
+
     if (!(*env)->IsInstanceOf(env, target, componentClass)) {
 #ifdef DEBUG
             fprintf(stderr, "Target is not a component\n");
@@ -126,6 +128,8 @@
 
     /* Make sure the target is a java.awt.Component */
     componentClass = (*env)->FindClass(env, "java/awt/Component");
+    CHECK_NULL_RETURN(componentClass, (int32_t) 0);
+
     if (!(*env)->IsInstanceOf(env, target, componentClass)) {
 #ifdef DEBUG
         fprintf(stderr, "DrawingSurface target must be a component\n");
@@ -195,6 +199,8 @@
 
     /* Make sure the target is a java.awt.Component */
     componentClass = (*env)->FindClass(env, "java/awt/Component");
+    CHECK_NULL_RETURN(componentClass, NULL);
+
     if (!(*env)->IsInstanceOf(env, target, componentClass)) {
 #ifdef DEBUG
         fprintf(stderr, "DrawingSurface target must be a component\n");
@@ -292,6 +298,8 @@
 
     /* Make sure the target component is a java.awt.Component */
     componentClass = (*env)->FindClass(env, "java/awt/Component");
+    CHECK_NULL_RETURN(componentClass, NULL);
+
     if (!(*env)->IsInstanceOf(env, target, componentClass)) {
 #ifdef DEBUG
         fprintf(stderr,
@@ -354,6 +362,10 @@
     if (window != None) {
         peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit",
             "windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l;
+        if ((*env)->ExceptionCheck(env)) {
+            AWT_UNLOCK();
+            return (jobject)NULL;
+        }
     }
     if ((peer != NULL) &&
         (JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) {
@@ -361,6 +373,7 @@
     }
 
     if (target == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowNullPointerException(env, "NullPointerException");
         AWT_UNLOCK();
         return (jobject)NULL;
--- a/jdk/src/solaris/native/sun/awt/awt_Font.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_Font.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -86,14 +86,13 @@
 #ifndef HEADLESS
     /** We call "NoClientCode" methods because they won't invoke client
         code on the privileged toolkit thread **/
-    fontIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J");
-    fontIDs.style = (*env)->GetFieldID(env, cls, "style", "I");
-    fontIDs.size = (*env)->GetFieldID(env, cls, "size", "I");
-    fontIDs.getPeer = (*env)->GetMethodID(env, cls, "getPeer_NoClientCode",
-                                           "()Ljava/awt/peer/FontPeer;");
-    fontIDs.getFamily =
-      (*env)->GetMethodID(env, cls, "getFamily_NoClientCode",
-                                            "()Ljava/lang/String;");
+    CHECK_NULL(fontIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J"));
+    CHECK_NULL(fontIDs.style = (*env)->GetFieldID(env, cls, "style", "I"));
+    CHECK_NULL(fontIDs.size = (*env)->GetFieldID(env, cls, "size", "I"));
+    CHECK_NULL(fontIDs.getPeer = (*env)->GetMethodID(env, cls, "getPeer_NoClientCode",
+                                                     "()Ljava/awt/peer/FontPeer;"));
+    CHECK_NULL(fontIDs.getFamily = (*env)->GetMethodID(env, cls, "getFamily_NoClientCode",
+                                                       "()Ljava/lang/String;"));
 #endif /* !HEADLESS */
 }
 
@@ -120,12 +119,10 @@
   (JNIEnv *env, jclass cls)
 {
 #ifndef HEADLESS
-    fontDescriptorIDs.nativeName =
-      (*env)->GetFieldID(env, cls, "nativeName",
-                         "Ljava/lang/String;");
-    fontDescriptorIDs.charsetName =
-      (*env)->GetFieldID(env, cls, "charsetName",
-                         "Ljava/lang/String;");
+    CHECK_NULL(fontDescriptorIDs.nativeName =
+               (*env)->GetFieldID(env, cls, "nativeName", "Ljava/lang/String;"));
+    CHECK_NULL(fontDescriptorIDs.charsetName =
+               (*env)->GetFieldID(env, cls, "charsetName", "Ljava/lang/String;"));
 #endif /* !HEADLESS */
 }
 
@@ -144,20 +141,18 @@
   (JNIEnv *env, jclass cls)
 {
 #ifndef HEADLESS
-    platformFontIDs.componentFonts =
-      (*env)->GetFieldID(env, cls, "componentFonts",
-                         "[Lsun/awt/FontDescriptor;");
-    platformFontIDs.fontConfig =
-      (*env)->GetFieldID(env,cls, "fontConfig",
-                         "Lsun/awt/FontConfiguration;");
-
-    platformFontIDs.makeConvertedMultiFontString =
-      (*env)->GetMethodID(env, cls, "makeConvertedMultiFontString",
-                          "(Ljava/lang/String;)[Ljava/lang/Object;");
-
-    platformFontIDs.makeConvertedMultiFontChars =
-      (*env)->GetMethodID(env, cls, "makeConvertedMultiFontChars",
-                          "([CII)[Ljava/lang/Object;");
+    CHECK_NULL(platformFontIDs.componentFonts =
+               (*env)->GetFieldID(env, cls, "componentFonts",
+                                  "[Lsun/awt/FontDescriptor;"));
+    CHECK_NULL(platformFontIDs.fontConfig =
+               (*env)->GetFieldID(env,cls, "fontConfig",
+                                  "Lsun/awt/FontConfiguration;"));
+    CHECK_NULL(platformFontIDs.makeConvertedMultiFontString =
+               (*env)->GetMethodID(env, cls, "makeConvertedMultiFontString",
+                                   "(Ljava/lang/String;)[Ljava/lang/Object;"));
+    CHECK_NULL(platformFontIDs.makeConvertedMultiFontChars =
+               (*env)->GetMethodID(env, cls, "makeConvertedMultiFontChars",
+                                   "([CII)[Ljava/lang/Object;"));
 #endif /* !HEADLESS */
 }
 
@@ -385,6 +380,11 @@
         return 0;
     }
     cname = (char *) JNU_GetStringPlatformChars(env, name, NULL);
+    if (cname == NULL) {
+        (*env)->ExceptionClear(env);
+        JNU_ThrowOutOfMemoryError(env, "Could not create font name");
+        return 0;
+    }
 
     /* additional default font names */
     if (strcmp(cname, "serif") == 0) {
@@ -448,6 +448,8 @@
     }
 
     if (!JNU_IsNull(env, font) && awtJNI_IsMultiFont(env, font)) {
+        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
+
         struct FontData *fdata = NULL;
         int32_t i, size;
         char *fontsetname = NULL;
@@ -492,7 +494,12 @@
 
             if (!JNU_IsNull(env, fontDescriptorName)) {
                 nativename = (char *) JNU_GetStringPlatformChars(env, fontDescriptorName, NULL);
-                doFree = TRUE;
+                if (nativename == NULL) {
+                    nativename = "";
+                    doFree = FALSE;
+                } else {
+                    doFree = TRUE;
+                }
             } else {
                 nativename = "";
                 doFree = FALSE;
@@ -516,6 +523,11 @@
 
             fdata->flist[i].charset_name = (char *)
                 JNU_GetStringPlatformChars(env, charsetName, NULL);
+            if (fdata->flist[i].charset_name == NULL) {
+                (*env)->ExceptionClear(env);
+                JNU_ThrowOutOfMemoryError(env, "Could not create charset name");
+                return NULL;
+            }
 
             /* We are done with the objects. */
             (*env)->DeleteLocalRef(env, fontDescriptor);
--- a/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, 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
@@ -152,8 +152,11 @@
     x11GraphicsConfigIDs.screen = NULL;
 
     x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J");
+    CHECK_NULL(x11GraphicsConfigIDs.aData);
     x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I");
+    CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel);
     x11GraphicsConfigIDs.screen = (*env)->GetFieldID (env, cls, "screen", "Lsun/awt/X11GraphicsDevice;");
+    CHECK_NULL(x11GraphicsConfigIDs.screen);
 
     if (x11GraphicsConfigIDs.aData == NULL ||
             x11GraphicsConfigIDs.bitsPerPixel == NULL ||
@@ -1346,7 +1349,6 @@
 
     /* Make Color Model object for this GraphicsConfiguration */
     colorModel = awtJNI_GetColorModel (env, adata);
-
     AWT_UNLOCK ();
 
     return colorModel;
@@ -1374,6 +1376,7 @@
         JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData);
 
     clazz = (*env)->FindClass(env, "java/awt/Rectangle");
+    CHECK_NULL_RETURN(clazz, NULL);
     mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
     if (mid != NULL) {
         if (usingXinerama) {
@@ -1543,7 +1546,7 @@
     clazz = (*env)->GetObjectClass(env, this);
     midAddVisual = (*env)->GetMethodID(env, clazz, "addDoubleBufferVisual",
         "(I)V");
-
+    CHECK_NULL(midAddVisual);
     AWT_LOCK();
     rootWindow = RootWindow(awt_display, xinawareScreen);
     visScreenInfo = XdbeGetVisualInfo(awt_display, &rootWindow, &n);
@@ -1739,6 +1742,7 @@
     jint validRefreshRate = refreshRate;
 
     displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode");
+    CHECK_NULL_RETURN(displayModeClass, NULL);
     if (JNU_IsNull(env, displayModeClass)) {
         JNU_ThrowInternalError(env,
                                "Could not get display mode class");
@@ -1746,6 +1750,7 @@
     }
 
     cid = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
+    CHECK_NULL_RETURN(cid, NULL);
     if (cid == NULL) {
         JNU_ThrowInternalError(env,
                                "Could not get display mode constructor");
@@ -1779,6 +1784,7 @@
         }
         mid = (*env)->GetMethodID(env, arrayListClass, "add",
                                   "(Ljava/lang/Object;)Z");
+        CHECK_NULL(mid);
         if (mid == NULL) {
             JNU_ThrowInternalError(env,
                 "Could not get method java.util.ArrayList.add()");
@@ -1955,6 +1961,9 @@
                                          size.height,
                                          BIT_DEPTH_MULTI,
                                          rates[j]);
+                    if ((*env)->ExceptionCheck(env)) {
+                        break;
+                    }
                 }
             }
         }
--- a/jdk/src/solaris/native/sun/awt/awt_InputMethod.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_InputMethod.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, 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
@@ -319,6 +319,7 @@
         JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod,
                              "flushText",
                              "()V");
+        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
         /* IMPORTANT:
            The order of the following calls is critical since "imInstance" may
            point to the global reference itself, if "freeX11InputMethodData" is called
@@ -1120,6 +1121,9 @@
         if (text->string.multi_byte != NULL) {
             if (pre_draw->text->encoding_is_wchar == False) {
                 javastr = JNU_NewStringPlatform(env, (const char *)text->string.multi_byte);
+                if (javastr == NULL) {
+                    goto finally;
+                }
             } else {
                 char *mbstr = wcstombsdmp(text->string.wide_char, text->length);
                 if (mbstr == NULL) {
@@ -1127,6 +1131,9 @@
                 }
                 javastr = JNU_NewStringPlatform(env, (const char *)mbstr);
                 free(mbstr);
+                if (javastr == NULL) {
+                    goto finally;
+                }
             }
         }
         if (text->feedback != NULL) {
@@ -1135,6 +1142,7 @@
 
             style = (*env)->NewIntArray(env, text->length);
             if (JNU_IsNull(env, style)) {
+                (*env)->ExceptionClear(env);
                 THROW_OUT_OF_MEMORY_ERROR();
                 goto finally;
             }
@@ -1395,14 +1403,17 @@
     pX11IMData->lookup_buf = 0;
     pX11IMData->lookup_buf_len = 0;
 
-    if (createXIC(env, pX11IMData, (Window)window)
-        == False) {
+    if (createXIC(env, pX11IMData, (Window)window) == False) {
         destroyX11InputMethodData((JNIEnv *) NULL, pX11IMData);
         pX11IMData = (X11InputMethodData *) NULL;
+        if ((*env)->ExceptionCheck(env)) {
+            goto finally;
+        }
     }
 
     setX11InputMethodData(env, this, pX11IMData);
 
+finally:
     AWT_UNLOCK();
     return (pX11IMData != NULL);
 }
--- a/jdk/src/solaris/native/sun/awt/awt_Insets.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_Insets.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2001, 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
@@ -34,8 +34,8 @@
 JNIEXPORT void JNICALL
 Java_java_awt_Insets_initIDs(JNIEnv *env, jclass cls)
 {
-    insetsIDs.top = (*env)->GetFieldID(env, cls, "top", "I");
-    insetsIDs.bottom = (*env)->GetFieldID(env, cls, "bottom", "I");
-    insetsIDs.left = (*env)->GetFieldID(env, cls, "left", "I");
-    insetsIDs.right = (*env)->GetFieldID(env, cls, "right", "I");
+    CHECK_NULL(insetsIDs.top = (*env)->GetFieldID(env, cls, "top", "I"));
+    CHECK_NULL(insetsIDs.bottom = (*env)->GetFieldID(env, cls, "bottom", "I"));
+    CHECK_NULL(insetsIDs.left = (*env)->GetFieldID(env, cls, "left", "I"));
+    CHECK_NULL(insetsIDs.right = (*env)->GetFieldID(env, cls, "right", "I"));
 }
--- a/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -77,11 +77,16 @@
     return isHeadless;
 }
 
+#define CHECK_EXCEPTION_FATAL(env, message) \
+    if ((*env)->ExceptionCheck(env)) { \
+        (*env)->ExceptionClear(env); \
+        (*env)->FatalError(env, message); \
+    }
+
 /*
  * Pathnames to the various awt toolkits
  */
 
-
 #ifdef MACOSX
   #define LWAWT_PATH "/libawt_lwawt.dylib"
   #define DEFAULT_PATH LWAWT_PATH
@@ -125,6 +130,8 @@
      */
 
     fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager");
+    CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager property");
+
 #ifdef MACOSX
         fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager");
         tk = LWAWT_PATH;
@@ -132,10 +139,13 @@
         fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager");
         tk = XAWT_PATH;
 #endif
+    CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager name");
+
     if (fmanager && fmProp) {
         JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
                                    "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
                                    fmProp, fmanager);
+        CHECK_EXCEPTION_FATAL(env, "Could not allocate set properties");
     }
 
 #ifndef MACOSX
@@ -154,9 +164,11 @@
         (*env)->DeleteLocalRef(env, fmanager);
     }
 
+    jstring jbuf = JNU_NewStringPlatform(env, buf);
+    CHECK_EXCEPTION_FATAL(env, "Could not allocate library name");
     JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
                                "(Ljava/lang/String;)V",
-                               JNU_NewStringPlatform(env, buf));
+                               jbuf);
 
     awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
 
--- a/jdk/src/solaris/native/sun/awt/awt_Robot.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_Robot.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, 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
@@ -175,10 +175,13 @@
 
     num_buttons = numberOfButtons;
     tmp = (*env)->GetIntArrayElements(env, buttonDownMasks, JNI_FALSE);
+    CHECK_NULL(tmp);
+
     masks = (jint *)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), num_buttons);
     if (masks == (jint *) NULL) {
+        (*env)->ExceptionClear(env);
+        (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
         JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL);
-        (*env)->ReleaseIntArrayElements(env, buttonDownMasks, tmp, 0);
         return;
     }
     for (i = 0; i < num_buttons; i++) {
--- a/jdk/src/solaris/native/sun/awt/awt_UNIXToolkit.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_UNIXToolkit.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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
@@ -98,6 +98,7 @@
                                           (*env)->GetObjectClass(env, this));
         icon_upcall_method = (*env)->GetMethodID(env, this_class,
                                  "loadIconCallback", "([BIIIIIZ)V");
+        CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE);
     }
 
     if (pixbuf != NULL)
@@ -112,6 +113,8 @@
 
         /* Copy the data array into a Java structure so we can pass it back. */
         jbyteArray data = (*env)->NewByteArray(env, (row_stride * height));
+        JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
+
         (*env)->SetByteArrayRegion(env, data, 0, (row_stride * height),
                                    (jbyte *)pixbuf_data);
 
--- a/jdk/src/solaris/native/sun/awt/awt_util.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/awt_util.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -76,6 +76,7 @@
         Boolean err = FALSE;
         if (threadClass == NULL) {
             jclass tc = (*env)->FindClass(env, "java/lang/Thread");
+            CHECK_NULL(tc);
             threadClass = (*env)->NewGlobalRef(env, tc);
             (*env)->DeleteLocalRef(env, tc);
             if (threadClass != NULL) {
--- a/jdk/src/solaris/native/sun/awt/fontpath.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/fontpath.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, 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
@@ -161,17 +161,22 @@
 
     if (! isLocalSet) {
       jclass geCls = (*env)->FindClass(env, "java/awt/GraphicsEnvironment");
+      CHECK_NULL_RETURN(geCls, JNI_FALSE);
       jmethodID getLocalGE = (*env)->GetStaticMethodID(env, geCls,
                                                  "getLocalGraphicsEnvironment",
                                            "()Ljava/awt/GraphicsEnvironment;");
+      CHECK_NULL_RETURN(getLocalGE, JNI_FALSE);
       jobject ge = (*env)->CallStaticObjectMethod(env, geCls, getLocalGE);
+      JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
 
       jclass sgeCls = (*env)->FindClass(env,
                                         "sun/java2d/SunGraphicsEnvironment");
+      CHECK_NULL_RETURN(sgeCls, JNI_FALSE);
       if ((*env)->IsInstanceOf(env, ge, sgeCls)) {
         jmethodID isDisplayLocal = (*env)->GetMethodID(env, sgeCls,
                                                        "isDisplayLocal",
                                                        "()Z");
+        JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
         isLocal = (*env)->CallBooleanMethod(env, ge, isDisplayLocal);
       } else {
         isLocal = True;
@@ -1005,50 +1010,38 @@
     jmethodID fcFontCons;
     char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS");
 
+    CHECK_NULL(fcInfoObj);
+    CHECK_NULL(fcCompFontArray);
+
     jclass fcInfoClass =
         (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo");
+    CHECK_NULL(fcInfoClass);
     jclass fcCompFontClass =
         (*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont");
+    CHECK_NULL(fcCompFontClass);
     jclass fcFontClass =
          (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont");
-
-    if (fcInfoObj == NULL || fcCompFontArray == NULL || fcInfoClass == NULL ||
-        fcCompFontClass == NULL || fcFontClass == NULL) {
-        return;
-    }
-
-    fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I");
+    CHECK_NULL(fcFontClass);
 
-    fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
-                                       "[Ljava/lang/String;");
-
-    fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
-                                  "fcName", "Ljava/lang/String;");
-    fcFirstFontID =
-        (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
-                           "Lsun/font/FontConfigManager$FontConfigFont;");
 
-    fcAllFontsID =
-        (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
-                           "[Lsun/font/FontConfigManager$FontConfigFont;");
-
-    fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V");
-
-    familyNameID = (*env)->GetFieldID(env, fcFontClass,
-                                      "familyName", "Ljava/lang/String;");
-    styleNameID = (*env)->GetFieldID(env, fcFontClass,
-                                    "styleStr", "Ljava/lang/String;");
-    fullNameID = (*env)->GetFieldID(env, fcFontClass,
-                                    "fullName", "Ljava/lang/String;");
-    fontFileID = (*env)->GetFieldID(env, fcFontClass,
-                                    "fontFile", "Ljava/lang/String;");
-
-    if (fcVersionID == NULL || fcCacheDirsID == NULL || fcNameID == NULL ||
-        fcFirstFontID == NULL || fcAllFontsID == NULL || fcFontCons == NULL ||
-        familyNameID == NULL || styleNameID == NULL || fullNameID == NULL ||
-        fontFileID == NULL) {
-        return;
-    }
+    CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"));
+    CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
+                                                  "[Ljava/lang/String;"));
+    CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
+                                             "fcName", "Ljava/lang/String;"));
+    CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
+                                        "Lsun/font/FontConfigManager$FontConfigFont;"));
+    CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
+                                        "[Lsun/font/FontConfigManager$FontConfigFont;"));
+    CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"));
+    CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass,
+                                      "familyName", "Ljava/lang/String;"));
+    CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass,
+                                    "styleStr", "Ljava/lang/String;"));
+    CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass,
+                                    "fullName", "Ljava/lang/String;"));
+    CHECK_NULL(fontFileID = (*env)->GetFieldID(env, fcFontClass,
+                                    "fontFile", "Ljava/lang/String;"));
 
     if ((libfontconfig = openFontConfig()) == NULL) {
         return;
@@ -1129,6 +1122,8 @@
         if (cacheDirs != NULL) {
             while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) {
                 jstr = (*env)->NewStringUTF(env, (const char*)cacheDir);
+                JNU_CHECK_EXCEPTION(env);
+
                 (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
             }
             (*FcStrListDone)(cacheDirs);
@@ -1136,6 +1131,11 @@
     }
 
     locale = (*env)->GetStringUTFChars(env, localeStr, 0);
+    if (locale == NULL) {
+        (*env)->ExceptionClear(env);
+        JNU_ThrowOutOfMemoryError(env, "Could not create locale");
+        return;
+    }
 
     arrlen = (*env)->GetArrayLength(env, fcCompFontArray);
     for (i=0; i<arrlen; i++) {
--- a/jdk/src/solaris/native/sun/awt/initIDs.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/initIDs.c	Tue Mar 25 16:31:02 2014 +0400
@@ -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
@@ -47,9 +47,6 @@
   (JNIEnv *env, jclass clazz)
 {
     colorValueID = (*env)->GetFieldID(env, clazz, "value", "I");
-
-    if(colorValueID == NULL)
-        JNU_ThrowNullPointerException (env, "Can't get java/awt/Color.value fieldID");
 }
 
 JNIEXPORT void JNICALL
--- a/jdk/src/solaris/native/sun/awt/multi_font.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/multi_font.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -74,7 +74,7 @@
     jobject temp = NULL;
     jboolean validRet = JNI_FALSE;
 
-    if ((*env)->EnsureLocalCapacity(env, 2) < 0)
+    if ((*env)->EnsureLocalCapacity(env, 2) < 0 || (*env)->ExceptionCheck(env))
         goto done;
 
     peer = (*env)->CallObjectMethod(env,font,fontIDs.getPeer);
@@ -162,7 +162,7 @@
 
     font = JNU_CallMethodByName(env, NULL, this, "getFont_NoClientCode",
                                 "()Ljava/awt/Font;").l;
-    if (JNU_IsNull(env, font)) {
+    if (JNU_IsNull(env, font) || (*env)->ExceptionCheck(env)) {
         return JNI_FALSE;
     }
 
@@ -318,6 +318,10 @@
     }
 
     fdata = awtJNI_GetFontData(env, font, &err);
+    if ((*env)->ExceptionCheck(env)) {
+        (*env)->DeleteLocalRef(env, dataArray);
+        return 0;
+    }
 
     stringCount = (*env)->GetArrayLength(env, dataArray);
 
@@ -336,6 +340,11 @@
         }
 
         j = awtJNI_GetFontDescriptorNumber(env, font, fontDescriptor);
+        if ((*env)->ExceptionCheck(env)) {
+            (*env)->DeleteLocalRef(env, fontDescriptor);
+            (*env)->DeleteLocalRef(env, data);
+            break;
+        }
 
         if (fdata->flist[j].load == 0) {
             xf = loadFont(awt_display,
@@ -356,6 +365,14 @@
 
         stringData =
             (unsigned char *)(*env)->GetPrimitiveArrayCritical(env, data,NULL);
+        if (stringData == NULL) {
+            (*env)->DeleteLocalRef(env, fontDescriptor);
+            (*env)->DeleteLocalRef(env, data);
+            (*env)->ExceptionClear(env);
+            JNU_ThrowOutOfMemoryError(env, "Could not get string data");
+            break;
+        }
+
         length = (stringData[0] << 24) | (stringData[1] << 16) |
             (stringData[2] << 8) | stringData[3];
         offsetStringData = (char *)(stringData + (4 * sizeof(char)));
--- a/jdk/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c	Mon Mar 24 23:02:05 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c	Tue Mar 25 16:31:02 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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
@@ -45,10 +45,12 @@
     filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx,
             "filenameFilterCallback", "(Ljava/lang/String;)Z");
     DASSERT(filenameFilterCallbackMethodID != NULL);
+    CHECK_NULL(filenameFilterCallbackMethodID);
 
     setFileInternalMethodID = (*env)->GetMethodID(env, cx,
             "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V");
     DASSERT(setFileInternalMethodID != NULL);
+    CHECK_NULL(setFileInternalMethodID);
 
     widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J");
     DASSERT(widgetFieldID != NULL);
@@ -63,6 +65,7 @@
     env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     filename = (*env)->NewStringUTF(env, filter_info->filename);
+    JNU_CHECK_EXCEPTION_RETURN(env, FALSE);
 
     return (*env)->CallBooleanMethod(env, obj, filenameFilterCallbackMethodID,
             filename);
@@ -173,13 +176,14 @@
 
     stringCls = (*env)->FindClass(env, "java/lang/String");
     if (stringCls == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowInternalError(env, "Could not get java.lang.String class");
         return NULL;
     }
 
-    array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
-            NULL);
+    array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls, NULL);
     if (array == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowInternalError(env, "Could not instantiate array files array");
         return NULL;
     }
@@ -189,7 +193,9 @@
         entry = (char*) iterator->data;
         entry = strrchr(entry, '/') + 1;
         str = (*env)->NewStringUTF(env, entry);
-        (*env)->SetObjectArrayElement(env, array, i, str);
+        if (str && !(*env)->ExceptionCheck(env)) {
+            (*env)->SetObjectArrayElement(env, array, i, str);
+        }
         i++;
     }
 
@@ -215,13 +221,14 @@
 
     stringCls = (*env)->FindClass(env, "java/lang/String");
     if (stringCls == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowInternalError(env, "Could not get java.lang.String class");
         return NULL;
     }
 
-    array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls,
-            NULL);
+    array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls, NULL);
     if (array == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowInternalError(env, "Could not instantiate array files array");
         return NULL;
     }
@@ -236,7 +243,9 @@
         }
 
         str = (*env)->NewStringUTF(env, entry);
-        (*env)->SetObjectArrayElement(env, array, i, str);
+        if (str && !(*env)->ExceptionCheck(env)) {
+            (*env)->SetObjectArrayElement(env, array, i, str);
+        }
         i++;
     }
 
@@ -268,16 +277,17 @@
     if (full_path_names) {
         //This is a hack for use with "Recent Folders" in gtk where each
         //file could have its own directory.
+        jfilenames = toPathAndFilenamesArray(env, filenames);
         jcurrent_folder = (*env)->NewStringUTF(env, "/");
-        jfilenames = toPathAndFilenamesArray(env, filenames);
     } else {
-        jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
         jfilenames = toFilenamesArray(env, filenames);
+        jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
     }
-    (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
-            jfilenames);
+    if (!(*env)->ExceptionCheck(env)) {
+        (*env)->CallVoidMethod(env, obj, setFileInternalMethodID,
+                               jcurrent_folder, jfilenames);
+    }
     fp_g_free(current_folder);
-
     quit(env, (jobject)obj, TRUE);
 }
 
@@ -296,11 +306,17 @@
 
     if (jvm == NULL) {
         (*env)->GetJavaVM(env, &jvm);
+        JNU_CHECK_EXCEPTION(env);
     }
 
     fp_gdk_threads_enter();
 
     const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0);
+    if (title == NULL) {
+        (*env)->ExceptionClear(env);
+        JNU_ThrowOutOfMemoryError(env, "Could not get title");
+        return;
+    }
 
     if (mode == java_awt_FileDialog_SAVE) {
         /* Save action */
@@ -328,6 +344,11 @@
     /* Set the directory */
     if (jdir != NULL) {
         const char *dir = (*env)->GetStringUTFChars(env, jdir, 0);
+        if (dir == NULL) {
+            (*env)->ExceptionClear(env);
+            JNU_ThrowOutOfMemoryError(env, "Could not get dir");
+            return;
+        }
         fp_gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
         (*env)->ReleaseStringUTFChars(env, jdir, dir);
     }
@@ -335,6 +356,11 @@
     /* Set the filename */
     if (jfile != NULL) {
         const char *filename = (*env)->GetStringUTFChars(env, jfile, 0);
+        if (filename == NULL) {
+            (*env)->ExceptionClear(env);
+            JNU_ThrowOutOfMemoryError(env, "Could not get filename");
+            return;
+        }
         if (mode == java_awt_FileDialog_SAVE) {
             fp_gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
         } else {