changeset 6949:bdb4082bc3e9

Fix to RT-36644: [Glass, Mac] Native code needs to handle JNI exceptions reported by Parfait Reviewed by Anthony Petrov and Kevin Rusthforth
author Chien Yang <chien.yang@oracle.com>
date Mon, 05 May 2014 18:16:42 -0700
parents 9db01136330d
children a1f6444766df
files modules/graphics/src/main/native-glass/mac/GlassApplication.m modules/graphics/src/main/native-glass/mac/GlassDialogs.m modules/graphics/src/main/native-glass/mac/GlassHelper.m modules/graphics/src/main/native-glass/mac/GlassKey.m modules/graphics/src/main/native-glass/mac/GlassMenu.m modules/graphics/src/main/native-glass/mac/GlassPasteboard.m modules/graphics/src/main/native-glass/mac/GlassScreen.m modules/graphics/src/main/native-glass/mac/GlassStatics.m modules/graphics/src/main/native-glass/mac/GlassView.m modules/graphics/src/main/native-glass/mac/GlassView3D.m modules/graphics/src/main/native-glass/mac/GlassViewDelegate.m modules/graphics/src/main/native-glass/mac/GlassWindow.m
diffstat 12 files changed, 171 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/mac/GlassApplication.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassApplication.m	Mon May 05 18:16:42 2014 -0700
@@ -164,12 +164,14 @@
             if ((*env)->ExceptionCheck(env) == JNI_TRUE)
             {
                 (*env)->ExceptionDescribe(env);
+                (*env)->ExceptionClear(env);
             }
 
             jmethodID runMethod = (*env)->GetMethodID(env, runnableClass, "run", "()V");
             if ((*env)->ExceptionCheck(env) == JNI_TRUE)
             {
                 (*env)->ExceptionDescribe(env);
+                (*env)->ExceptionClear(env);
             }
 
             if ((runnableClass != 0) && (runMethod != 0))
@@ -178,10 +180,11 @@
                 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
                 {
                     (*env)->ExceptionDescribe(env);
+                    (*env)->ExceptionClear(env);
                 }
                 else
                 {
-                    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(GlassApplicationDidChangeScreenParameters) name:NSApplicationDidChangeScreenParametersNotification object:nil];
+                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(GlassApplicationDidChangeScreenParameters) name:NSApplicationDidChangeScreenParametersNotification object:nil];
                 }
             }
             else if (runnableClass == 0)
@@ -328,12 +331,14 @@
     {
         NSUInteger count = [filenames count];
         jobjectArray files = (*env)->NewObjectArray(env, (jsize)count, [GlassHelper ClassForName:"java.lang.String" withEnv:env], NULL);
+        GLASS_CHECK_EXCEPTION(env);
         for (NSUInteger i=0; i<count; i++)
         {
             NSString *file = [filenames objectAtIndex:i];
             if (file != nil)
             {
                 (*env)->SetObjectArrayElement(env, files, (jsize)i, (*env)->NewStringUTF(env, [file UTF8String]));
+                GLASS_CHECK_EXCEPTION(env);
             }
         }
         (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyOpenFilesMethod], files);
@@ -463,6 +468,7 @@
                 // make the name available to Java side, before Launchable.fnishLaunching callback
                 jstring jname = (*jEnv)->NewStringUTF(jEnv, [appName UTF8String]);
                 jmethodID setNameMethod = (*jEnv)->GetMethodID(jEnv, cls, "setName", "(Ljava/lang/String;)V");
+                GLASS_CHECK_EXCEPTION(jEnv);
                 if (setNameMethod != NULL) {
                     (*jEnv)->CallVoidMethod(jEnv, glassApp->jApplication, setNameMethod, jname);
                 }
@@ -721,19 +727,26 @@
 
     javaIDs.Application.createPixels = (*env)->GetStaticMethodID(
             env, jClass, "createPixels", "(II[IF)Lcom/sun/glass/ui/Pixels;");
+    if ((*env)->ExceptionCheck(env)) return;
 
     javaIDs.Application.getScaleFactor = (*env)->GetStaticMethodID(
             env, jClass, "getScaleFactor", "(IIII)F");
+    if ((*env)->ExceptionCheck(env)) return;
 
     javaIDs.Application.reportException = (*env)->GetStaticMethodID(
             env, jClass, "reportException", "(Ljava/lang/Throwable;)V");
+    if ((*env)->ExceptionCheck(env)) return;
 
     javaIDs.MacApplication.notifyApplicationDidTerminate = (*env)->GetMethodID(
             env, jClass, "notifyApplicationDidTerminate", "()V");
+    if ((*env)->ExceptionCheck(env)) return;
 
     if (jRunnableRun == NULL)
     {
-        jRunnableRun = (*env)->GetMethodID(env, (*env)->FindClass(env, "java/lang/Runnable"), "run", "()V");
+        jclass jcls = (*env)->FindClass(env, "java/lang/Runnable");
+        if ((*env)->ExceptionCheck(env)) return;
+        jRunnableRun = (*env)->GetMethodID(env, jcls, "run", "()V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
 }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassDialogs.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassDialogs.m	Mon May 05 18:16:42 2014 -0700
@@ -140,11 +140,13 @@
 {
     GET_MAIN_JENV;
     DialogDispatcher *dd = self;
+    
+    jobject jobj = (*env)->NewObject(env,
+            [GlassHelper ClassForName:"com.sun.glass.ui.EventLoop" withEnv:env],
+            javaIDs.EventLoop.init);
+    if ((*env)->ExceptionCheck(env)) return;
 
-    dd->eventLoop = (*env)->NewGlobalRef(env, (*env)->NewObject(env,
-            [GlassHelper ClassForName:"com.sun.glass.ui.EventLoop" withEnv:env],
-            javaIDs.EventLoop.init));
-
+    dd->eventLoop = (*env)->NewGlobalRef(env, jobj);
 
     if (owner) {
         [panel beginSheetModalForWindow: owner completionHandler:^(NSInteger result)
@@ -250,9 +252,10 @@
     const jclass MacCommonDialogsCls = [GlassHelper ClassForName:"com.sun.glass.ui.mac.MacCommonDialogs" withEnv:env];
 
     // Performance doesn't matter here, so call the method every time 
-    if ((*env)->CallStaticBooleanMethod(env,
-                MacCommonDialogsCls,
-                javaIDs.MacCommonDialogs.isFileNSURLEnabled))
+    jboolean result = (*env)->CallStaticBooleanMethod(env, MacCommonDialogsCls,
+                javaIDs.MacCommonDialogs.isFileNSURLEnabled);
+    GLASS_CHECK_EXCEPTION(env);
+    if (result)
     {
         [url retain]; //NOTE: an app must call MacFileURL.dispoes() to release it
 
@@ -260,13 +263,17 @@
         ret = (*env)->NewObject(env,
                 MacFileNSURLCls,
                 javaIDs.MacFileNSURL.init, path, ptr_to_jlong(url));
+        GLASS_CHECK_EXCEPTION(env);
         (*env)->DeleteLocalRef(env, MacFileNSURLCls);
     }
     else
     {
+        jclass jcls = (*env)->FindClass(env, "java/io/File");
+        GLASS_CHECK_EXCEPTION(env);
         ret = (*env)->NewObject(env,
-                (*env)->FindClass(env, "java/io/File"),
+                jcls,
                 javaIDs.File.init, path);
+        GLASS_CHECK_EXCEPTION(env);
     }
 
     (*env)->DeleteLocalRef(env, MacCommonDialogsCls);
@@ -424,11 +431,15 @@
 (JNIEnv *env, jclass cls)
 {
     javaIDs.MacCommonDialogs.isFileNSURLEnabled = (*env)->GetStaticMethodID(env, cls, "isFileNSURLEnabled", "()Z");
+    if ((*env)->ExceptionCheck(env)) return;
 
     cls = [GlassHelper ClassForName:"com.sun.glass.ui.EventLoop" withEnv:env];
     javaIDs.EventLoop.init  = (*env)->GetMethodID(env, cls, "<init>", "()V");
+    if ((*env)->ExceptionCheck(env)) return;
     javaIDs.EventLoop.enter = (*env)->GetMethodID(env, cls, "enter", "()Ljava/lang/Object;");
+    if ((*env)->ExceptionCheck(env)) return;
     javaIDs.EventLoop.leave = (*env)->GetMethodID(env, cls, "leave", "(Ljava/lang/Object;)V");
+    if ((*env)->ExceptionCheck(env)) return;
 
     initJavaIDsList(env);
     initJavaIDsArrayList(env);
@@ -436,8 +447,10 @@
 
     cls = [GlassHelper ClassForName:"com.sun.glass.ui.CommonDialogs$ExtensionFilter" withEnv:env];
     javaIDs.ExtensionFilter.getDescription = (*env)->GetMethodID(env, cls, "getDescription", "()Ljava/lang/String;");
+    if ((*env)->ExceptionCheck(env)) return;
     javaIDs.ExtensionFilter.extensionsToArray  = (*env)->GetMethodID(env, cls, "extensionsToArray", "()[Ljava/lang/String;");
-    
+    if ((*env)->ExceptionCheck(env)) return;
+
     cls = [GlassHelper ClassForName:"com.sun.glass.ui.CommonDialogs$FileChooserResult" withEnv:env];
     javaIDs.FileChooserResult.init = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/util/List;Lcom/sun/glass/ui/CommonDialogs$ExtensionFilter;)V");
 }
@@ -484,13 +497,18 @@
             [dispatcher performSelectorOnMainThread:@selector(runModally) withObject:nil waitUntilDone:YES];
             NSArray *urls = [panel URLs];
 
-            chosenFiles = (*env)->NewObject(env, (*env)->FindClass(env, "java/util/ArrayList"), javaIDs.ArrayList.init);
+            jclass jcls = (*env)->FindClass(env, "java/util/ArrayList");
+            GLASS_CHECK_EXCEPTION(env);
+            chosenFiles = (*env)->NewObject(env, jcls, javaIDs.ArrayList.init);
+            GLASS_CHECK_EXCEPTION(env);
+            
             if (([dispatcher getButton] == NSFileHandlingPanelOKButton) && ([urls count] > 0))
             {
                 for (NSUInteger i=0; i<[urls count]; i++)
                 {
                     NSURL *url = [urls objectAtIndex:i];
                     (*env)->CallBooleanMethod(env, chosenFiles, javaIDs.List.add, convertNSURLtoFile(env, url));
+                    GLASS_CHECK_EXCEPTION(env);
                 }
             }
             
@@ -498,6 +516,7 @@
             {
                 chosenFilter = (*env)->GetObjectArrayElement(env, jExtensionFilters,
                                                              [(NSPopUpButton*)[panel accessoryView] indexOfSelectedItem]);
+                GLASS_CHECK_EXCEPTION(env);
             }
         }
         [dispatcher release];
@@ -554,16 +573,21 @@
             [dispatcher performSelectorOnMainThread:@selector(runModally) withObject:nil waitUntilDone:YES];
             NSURL *url = [panel URL];
 
-            chosenFile = (*env)->NewObject(env, (*env)->FindClass(env, "java/util/ArrayList"), javaIDs.ArrayList.init);
+            jclass jcls = (*env)->FindClass(env, "java/util/ArrayList");
+            GLASS_CHECK_EXCEPTION(env);
+            chosenFile = (*env)->NewObject(env, jcls, javaIDs.ArrayList.init);
+            GLASS_CHECK_EXCEPTION(env);
             if (([dispatcher getButton] == NSFileHandlingPanelOKButton) && (url != nil))
             {
                 (*env)->CallBooleanMethod(env, chosenFile, javaIDs.List.add, convertNSURLtoFile(env, url));
+                GLASS_CHECK_EXCEPTION(env);
             }
             
             if (jExtensionFilters != NULL && (*env)->GetArrayLength(env, jExtensionFilters) > 0)
             {
                 chosenFilter = (*env)->GetObjectArrayElement(env, jExtensionFilters,
                                                              [(NSPopUpButton*)[panel accessoryView] indexOfSelectedItem]);
+                GLASS_CHECK_EXCEPTION(env);
             }
         }
         [dispatcher release];
--- a/modules/graphics/src/main/native-glass/mac/GlassHelper.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassHelper.m	Mon May 05 18:16:42 2014 -0700
@@ -49,7 +49,14 @@
     static jclass classCls = NULL;
     if (classCls == NULL)
     {
-        classCls = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Class"));
+        jclass jcls = (*env)->FindClass(env, "java/lang/Class");
+        GLASS_CHECK_EXCEPTION(env);
+        if (jcls == NULL)
+        {
+            NSLog(@"GlassHelper error: jcls == NULL");
+            return NULL;            
+        }
+        classCls = (*env)->NewGlobalRef(env, jcls);
     }
     if (classCls == NULL)
     {
@@ -61,6 +68,7 @@
     if (forNameMID == NULL)
     {
         forNameMID = (*env)->GetStaticMethodID(env, classCls, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
+        GLASS_CHECK_EXCEPTION(env);
     }
     if (forNameMID == NULL)
     {
@@ -77,6 +85,7 @@
 
     jclass foundClass = (*env)->CallStaticObjectMethod(env, classCls,
         forNameMID,classNameStr, JNI_TRUE, glassClassLoader);
+    GLASS_CHECK_EXCEPTION(env);
     (*env)->DeleteLocalRef(env, classNameStr);
 
     return foundClass;
--- a/modules/graphics/src/main/native-glass/mac/GlassKey.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassKey.m	Mon May 05 18:16:42 2014 -0700
@@ -268,6 +268,7 @@
     [chars getCharacters:jc range:NSMakeRange(0, [chars length])];
     jcharArray jChars = (*env)->NewCharArray(env, (jsize)[chars length]);
     (*env)->SetCharArrayRegion(env, jChars, 0, (jsize)[chars length], jc);
+    GLASS_CHECK_EXCEPTION(env);
     return jChars;
 }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassMenu.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassMenu.m	Mon May 05 18:16:42 2014 -0700
@@ -360,9 +360,13 @@
     jclass jMenuClass = [GlassHelper ClassForName:"com.sun.glass.ui.Menu" withEnv:env];
     
     jMenuActionMethod  = (*env)->GetMethodID(env, jCallbackClass,   "action",  "()V");
+    if ((*env)->ExceptionCheck(env)) return;
     jMenuValidateMethod = (*env)->GetMethodID(env, jCallbackClass,   "validate",  "()V");
+    if ((*env)->ExceptionCheck(env)) return;
     jMenuOpeningMethod = (*env)->GetMethodID(env, jMenuClass, "notifyMenuOpening", "()V");
+    if ((*env)->ExceptionCheck(env)) return;
     jMenuClosedMethod  = (*env)->GetMethodID(env, jMenuClass, "notifyMenuClosed",  "()V");
+    if ((*env)->ExceptionCheck(env)) return;
     jDelegateMenuField = (*env)->GetFieldID(env,  jMenuDelegateClass, "menu", "Lcom/sun/glass/ui/Menu;");
 }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassPasteboard.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassPasteboard.m	Mon May 05 18:16:42 2014 -0700
@@ -115,17 +115,26 @@
         {
             jbyte *w = (jbyte*)&width;
             (*env)->SetByteArrayRegion(env, javaArray, 0, 1, (jbyte *)&w[3]);
+            GLASS_CHECK_EXCEPTION(env);
             (*env)->SetByteArrayRegion(env, javaArray, 1, 1, (jbyte *)&w[2]);
+            GLASS_CHECK_EXCEPTION(env);
             (*env)->SetByteArrayRegion(env, javaArray, 2, 1, (jbyte *)&w[1]);
+            GLASS_CHECK_EXCEPTION(env);
             (*env)->SetByteArrayRegion(env, javaArray, 3, 1, (jbyte *)&w[0]);
-            
+            GLASS_CHECK_EXCEPTION(env);
+
             jbyte *h = (jbyte*)&height;
             (*env)->SetByteArrayRegion(env, javaArray, 4, 1, (jbyte *)&h[3]);
+            GLASS_CHECK_EXCEPTION(env);
             (*env)->SetByteArrayRegion(env, javaArray, 5, 1, (jbyte *)&h[2]);
+            GLASS_CHECK_EXCEPTION(env);
             (*env)->SetByteArrayRegion(env, javaArray, 6, 1, (jbyte *)&h[1]);
+            GLASS_CHECK_EXCEPTION(env);
             (*env)->SetByteArrayRegion(env, javaArray, 7, 1, (jbyte *)&h[0]);
-            
+            GLASS_CHECK_EXCEPTION(env);
+
             (*env)->SetByteArrayRegion(env, javaArray, 8, length, (jbyte *)data);
+            GLASS_CHECK_EXCEPTION(env);
         }
     }
     
@@ -144,6 +153,7 @@
         if (javaArray != NULL)
         {
             (*env)->SetByteArrayRegion(env, javaArray, 0, (jsize)[data length], (jbyte *)[data bytes]);
+            GLASS_CHECK_EXCEPTION(env);
         }
     }
     
@@ -430,7 +440,10 @@
         NSArray *items = [pasteboard pasteboardItems];
         if ([items count] > 0)
         {
-            utfs = (*env)->NewObjectArray(env, (jsize)[items count], (*env)->FindClass(env, "java/lang/Object"), NULL);
+            jclass jcls = (*env)->FindClass(env, "java/lang/Object");
+            GLASS_CHECK_EXCEPTION(env);
+            utfs = (*env)->NewObjectArray(env, (jsize)[items count], jcls, NULL);
+            GLASS_CHECK_EXCEPTION(env);
             for (NSUInteger i=0; i<[items count]; i++)
             {
                 NSPasteboardItem *item = [items objectAtIndex:i];
@@ -438,7 +451,10 @@
                 NSArray *types = [item types];
                 if ([types count] > 0)
                 {
-                    jobjectArray array = (*env)->NewObjectArray(env, (jsize)[types count], (*env)->FindClass(env, "java/lang/String"), NULL);
+                    jcls = (*env)->FindClass(env, "java/lang/String");
+                    GLASS_CHECK_EXCEPTION(env);
+                    jobjectArray array = (*env)->NewObjectArray(env, (jsize)[types count], jcls, NULL);
+                    GLASS_CHECK_EXCEPTION(env);
                     for (NSUInteger j=0; j<[types count]; j++)
                     {
                         NSString *type = [types objectAtIndex:j];
@@ -446,9 +462,11 @@
                         //if (property != nil) // allow null as the platform itself does
                         {
                             (*env)->SetObjectArrayElement(env, array, (jsize)j, (*env)->NewStringUTF(env, [type UTF8String]));
+                            GLASS_CHECK_EXCEPTION(env);
                         }
                     }
                     (*env)->SetObjectArrayElement(env, utfs, (jsize)i, array);
+                    GLASS_CHECK_EXCEPTION(env);
                 }
             }
         }
@@ -679,6 +697,7 @@
             for (int i=0; i<itemCount; i++)
             {
                 jobject array = (*env)->GetObjectArrayElement(env, jObjects, i);
+                GLASS_CHECK_EXCEPTION(env);
                 if (array != NULL)
                 {
                     NSPasteboardItem *item = NSPasteboardItemFromArray(env, array);
--- a/modules/graphics/src/main/native-glass/mac/GlassScreen.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassScreen.m	Mon May 05 18:16:42 2014 -0700
@@ -101,17 +101,20 @@
 
     if (jScreenClass == NULL)
     {
-        jScreenClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "com/sun/glass/ui/Screen"));
+        jclass jcls = (*env)->FindClass(env, "com/sun/glass/ui/Screen");
+        GLASS_CHECK_EXCEPTION(env);
+        jScreenClass = (*env)->NewGlobalRef(env, jcls);
     }
 
     jobjectArray screenArray = (*env)->NewObjectArray(env,
                                                       [screens count],
                                                       jScreenClass,
                                                       NULL);
-
+    GLASS_CHECK_EXCEPTION(env);
     for (NSUInteger index = 0; index < [screens count]; index++) {
         jobject javaScreen = createJavaScreen(env, [screens objectAtIndex:index]);
         (*env)->SetObjectArrayElement(env, screenArray, index, javaScreen);
+        GLASS_CHECK_EXCEPTION(env);
     }
 
     return screenArray;
@@ -122,9 +125,11 @@
     if (jScreenNotifySettingsChanged == NULL) 
     {
         jScreenNotifySettingsChanged = (*env)->GetStaticMethodID(env, jScreenClass, "notifySettingsChanged", "()V");
+        GLASS_CHECK_EXCEPTION(env);
     }
     
     (*env)->CallStaticVoidMethod(env, jScreenClass, jScreenNotifySettingsChanged);
+    GLASS_CHECK_EXCEPTION(env);
 }
 
 @implementation NSScreen (FullscreenAdditions)
--- a/modules/graphics/src/main/native-glass/mac/GlassStatics.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassStatics.m	Mon May 05 18:16:42 2014 -0700
@@ -27,6 +27,7 @@
 #import <pthread.h>
 #import <QuartzCore/CVDisplayLink.h>
 #import "GlassStatics.h"
+#import "GlassMacros.h"
 
 pthread_key_t GlassThreadDataKey = 0;
 
@@ -91,21 +92,36 @@
 void initJavaIDsList(JNIEnv* env)
 {
     if (!javaIDs.List.add) {
-        javaIDs.List.add = (*env)->GetMethodID(env, (*env)->FindClass(env, "java/util/List"), "add", "(Ljava/lang/Object;)Z");
+        jclass jcls = (*env)->FindClass(env, "java/util/List");
+        GLASS_CHECK_EXCEPTION(env);
+        if (jcls) {
+            javaIDs.List.add = (*env)->GetMethodID(env, jcls, "add", "(Ljava/lang/Object;)Z");
+            GLASS_CHECK_EXCEPTION(env);
+        }
     }
 }
 
 void initJavaIDsArrayList(JNIEnv* env)
 {
     if (!javaIDs.ArrayList.init) {
-        javaIDs.ArrayList.init = (*env)->GetMethodID(env, (*env)->FindClass(env, "java/util/ArrayList"), "<init>", "()V");
+        jclass jcls = (*env)->FindClass(env, "java/util/ArrayList");
+        GLASS_CHECK_EXCEPTION(env);
+        if (jcls) {
+            javaIDs.ArrayList.init = (*env)->GetMethodID(env, jcls, "<init>", "()V");
+            GLASS_CHECK_EXCEPTION(env);
+        }
     }
 }
 
 void initJavaIDsFile(JNIEnv* env)
 {
     if (!javaIDs.File.init) {
-        javaIDs.File.init = (*env)->GetMethodID(env, (*env)->FindClass(env, "java/io/File"), "<init>", "(Ljava/lang/String;)V");
+        jclass jcls = (*env)->FindClass(env, "java/io/File");
+        GLASS_CHECK_EXCEPTION(env);
+        if (jcls) {
+            javaIDs.File.init = (*env)->GetMethodID(env, jcls, "<init>", "(Ljava/lang/String;)V");
+            GLASS_CHECK_EXCEPTION(env);
+        }
     }
 }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassView.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassView.m	Mon May 05 18:16:42 2014 -0700
@@ -90,118 +90,145 @@
     
     if (jIntegerClass == NULL)
     {
-        jIntegerClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Integer"));
+        jclass jcls = (*env)->FindClass(env, "java/lang/Integer");
+        if ((*env)->ExceptionCheck(env)) return;
+        jIntegerClass = (*env)->NewGlobalRef(env, jcls);
     }
     
     if (jMapClass == NULL)
     {
-        jMapClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/util/Map"));
+        jclass jcls = (*env)->FindClass(env, "java/util/Map");
+        if ((*env)->ExceptionCheck(env)) return;
+        jMapClass = (*env)->NewGlobalRef(env, jcls);
     }
     
     if (jBooleanClass == NULL)
     {
-        jBooleanClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Boolean"));
+        jclass jcls = (*env)->FindClass(env, "java/lang/Boolean");
+        if ((*env)->ExceptionCheck(env)) return;
+        jBooleanClass = (*env)->NewGlobalRef(env, jcls);
     }
     
     if (jViewNotifyEvent == NULL)
     {
         jViewNotifyEvent = (*env)->GetMethodID(env, jViewClass, "notifyView", "(I)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyRepaint == NULL)
     {
         jViewNotifyRepaint = (*env)->GetMethodID(env, jViewClass, "notifyRepaint", "(IIII)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyResize == NULL)
     {
         jViewNotifyResize = (*env)->GetMethodID(env, jViewClass, "notifyResize", "(II)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyKey == NULL)
     {
         jViewNotifyKey = (*env)->GetMethodID(env, jViewClass, "notifyKey", "(II[CI)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyMenu == NULL)
     {
         jViewNotifyMenu = (*env)->GetMethodID(env, jViewClass, "notifyMenu", "(IIIIZ)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyMouse == NULL)
     {
         jViewNotifyMouse = (*env)->GetMethodID(env, jViewClass, "notifyMouse", "(IIIIIIIZZ)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyInputMethod == NULL)
     {
         jViewNotifyInputMethod = (*env)->GetMethodID(env, jViewClass, "notifyInputMethod", "(Ljava/lang/String;[I[I[BIII)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyInputMethodMac == NULL)
     {
         jclass jMacViewClass = [GlassHelper ClassForName:"com.sun.glass.ui.mac.MacView" withEnv:env];
         jViewNotifyInputMethodMac = (*env)->GetMethodID(env, jMacViewClass, "notifyInputMethodMac", "(Ljava/lang/String;III)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if(jViewNotifyInputMethodCandidatePosRequest == NULL)
     {
         jViewNotifyInputMethodCandidatePosRequest = (*env)->GetMethodID(env, jViewClass, "notifyInputMethodCandidatePosRequest", "(I)[D");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyDragEnter == NULL)
     {
         jViewNotifyDragEnter = (*env)->GetMethodID(env, jViewClass, "notifyDragEnter", "(IIIII)I");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyDragOver == NULL)
     {
         jViewNotifyDragOver = (*env)->GetMethodID(env, jViewClass, "notifyDragOver", "(IIIII)I");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyDragLeave == NULL)
     {
         jViewNotifyDragLeave = (*env)->GetMethodID(env, jViewClass, "notifyDragLeave", "()V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyDragDrop == NULL)
     {
         jViewNotifyDragDrop = (*env)->GetMethodID(env, jViewClass, "notifyDragDrop", "(IIIII)I");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jViewNotifyDragEnd == NULL)
     {
         jViewNotifyDragEnd = (*env)->GetMethodID(env, jViewClass, "notifyDragEnd", "(I)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
 
     if (jViewGetAccessible == NULL)
     {
         jViewGetAccessible = (*env)->GetMethodID(env, jViewClass, "getAccessible", "()J");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jMapGetMethod == NULL)
     {
         jMapGetMethod = (*env)->GetMethodID(env, jMapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jBooleanValueMethod == NULL)
     {
         jBooleanValueMethod = (*env)->GetMethodID(env, jBooleanClass, "booleanValue", "()Z");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jIntegerInitMethod == NULL)
     {
         jIntegerInitMethod = (*env)->GetMethodID(env, jIntegerClass, "<init>", "(I)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jIntegerValueMethod == NULL)
     {
         jIntegerValueMethod = (*env)->GetMethodID(env, jIntegerClass, "intValue", "()I");
+        if ((*env)->ExceptionCheck(env)) return;
     }
         
     if (jLongClass == NULL)
     {
-        jLongClass = (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Long"));
+        jclass jcls = (*env)->FindClass(env, "java/lang/Long");
+        if ((*env)->ExceptionCheck(env)) return;
+        jLongClass = (*env)->NewGlobalRef(env, jcls);
     }
     
     if (jLongValueMethod == NULL)
@@ -291,7 +318,9 @@
         [view setAutoresizingMask:(NSViewWidthSizable|NSViewHeightSizable)];
         
         [hostView addSubview:view];
-        (*env)->SetLongField(env, jView, (*env)->GetFieldID(env, jViewClass, "ptr", "J"), ptr_to_jlong(view));
+        jfieldID jfID = (*env)->GetFieldID(env, jViewClass, "ptr", "J");
+        GLASS_CHECK_EXCEPTION(env);
+        (*env)->SetLongField(env, jView, jfID, ptr_to_jlong(view));
         
         value = ptr_to_jlong(view);
 
--- a/modules/graphics/src/main/native-glass/mac/GlassView3D.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassView3D.m	Mon May 05 18:16:42 2014 -0700
@@ -120,10 +120,13 @@
     if (jproperties != NULL)
     {
         jobject k3dDepthKey = (*env)->NewObject(env, jIntegerClass, jIntegerInitMethod, com_sun_glass_ui_View_Capability_k3dDepthKeyValue);
+        GLASS_CHECK_EXCEPTION(env);
         jobject k3dDepthKeyValue = (*env)->CallObjectMethod(env, jproperties, jMapGetMethod, k3dDepthKey);
+        GLASS_CHECK_EXCEPTION(env);
         if (k3dDepthKeyValue != NULL)
         {
             depthBits = (*env)->CallIntMethod(env, k3dDepthKeyValue, jIntegerValueMethod);
+            GLASS_CHECK_EXCEPTION(env);
         }
     }
     
@@ -132,9 +135,11 @@
     {
         jobject sharedContextPtrKey = (*env)->NewStringUTF(env, "shareContextPtr");
         jobject sharedContextPtrValue = (*env)->CallObjectMethod(env, jproperties, jMapGetMethod, sharedContextPtrKey);
+        GLASS_CHECK_EXCEPTION(env);
         if (sharedContextPtrValue != NULL)
         {
             jlong jsharedContextPtr = (*env)->CallLongMethod(env, sharedContextPtrValue, jLongValueMethod);
+            GLASS_CHECK_EXCEPTION(env);
             if (jsharedContextPtr != 0)
             {
                 NSOpenGLContext *sharedContextNS = (NSOpenGLContext*)jlong_to_ptr(jsharedContextPtr);
@@ -148,9 +153,11 @@
     {
         jobject contextPtrKey = (*env)->NewStringUTF(env, "contextPtr");
         jobject contextPtrValue = (*env)->CallObjectMethod(env, jproperties, jMapGetMethod, contextPtrKey);
+        GLASS_CHECK_EXCEPTION(env);
         if (contextPtrValue != NULL)
         {
             jlong jcontextPtr = (*env)->CallLongMethod(env, contextPtrValue, jLongValueMethod);
+            GLASS_CHECK_EXCEPTION(env);
             if (jcontextPtr != 0)
             {
                 NSOpenGLContext *clientContextNS = (NSOpenGLContext*)jlong_to_ptr(jcontextPtr);
@@ -173,10 +180,13 @@
     if (jproperties != NULL)
     {
         jobject kHiDPIAwareKey = (*env)->NewObject(env, jIntegerClass, jIntegerInitMethod, com_sun_glass_ui_View_Capability_kHiDPIAwareKeyValue);
+        GLASS_CHECK_EXCEPTION(env);
         jobject kHiDPIAwareValue = (*env)->CallObjectMethod(env, jproperties, jMapGetMethod, kHiDPIAwareKey);
+        GLASS_CHECK_EXCEPTION(env);
         if (kHiDPIAwareValue != NULL)
         {
             self->isHiDPIAware = (*env)->CallBooleanMethod(env, kHiDPIAwareValue, jBooleanValueMethod) ? YES : NO;
+            GLASS_CHECK_EXCEPTION(env);
         }
     }
 
--- a/modules/graphics/src/main/native-glass/mac/GlassViewDelegate.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassViewDelegate.m	Mon May 05 18:16:42 2014 -0700
@@ -237,6 +237,7 @@
         }
         (*env)->CallVoidMethod(env, self->jView, jViewNotifyEvent, com_sun_glass_events_ViewEvent_REMOVE);
     }
+    GLASS_CHECK_EXCEPTION(env);
 }
 
 - (void)setFrameOrigin:(NSPoint)newOrigin
@@ -1005,6 +1006,7 @@
                                                     self->jView, 
                                                     jViewNotifyInputMethodCandidatePosRequest, 
                                                     pos);
+        GLASS_CHECK_EXCEPTION(env);
         if (theArray != NULL) {
             jint n = (*env)->GetArrayLength(env, theArray);
             if (n == 2) {
--- a/modules/graphics/src/main/native-glass/mac/GlassWindow.m	Tue May 06 00:52:21 2014 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassWindow.m	Mon May 05 18:16:42 2014 -0700
@@ -70,7 +70,9 @@
 {
     if (jview != NULL)
     {
-        return (NSView<GlassView>*)jlong_to_ptr((*env)->GetLongField(env, jview, (*env)->GetFieldID(env, jViewClass, "ptr", "J")));
+        jfieldID jfID = (*env)->GetFieldID(env, jViewClass, "ptr", "J");
+        GLASS_CHECK_EXCEPTION(env);
+        return (NSView<GlassView>*)jlong_to_ptr((*env)->GetLongField(env, jview, jfID));
     }
     else
     {
@@ -604,41 +606,49 @@
     if (jWindowNotifyMove == NULL)
     {
         jWindowNotifyMove = (*env)->GetMethodID(env, jWindowClass, "notifyMove", "(II)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyResize == NULL)
     {
         jWindowNotifyResize = (*env)->GetMethodID(env, jWindowClass, "notifyResize", "(III)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyMoveToAnotherScreen == NULL)
     {
         jWindowNotifyMoveToAnotherScreen = (*env)->GetMethodID(env, jWindowClass, "notifyMoveToAnotherScreen", "(Lcom/sun/glass/ui/Screen;)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyClose == NULL)
     {
         jWindowNotifyClose = (*env)->GetMethodID(env, jWindowClass, "notifyClose", "()V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyFocus == NULL)
     {
         jWindowNotifyFocus = (*env)->GetMethodID(env, jWindowClass, "notifyFocus", "(I)V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyFocusUngrab == NULL)
     {
         jWindowNotifyFocusUngrab = (*env)->GetMethodID(env, jWindowClass, "notifyFocusUngrab", "()V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyFocusDisabled == NULL)
     {
         jWindowNotifyFocusDisabled = (*env)->GetMethodID(env, jWindowClass, "notifyFocusDisabled", "()V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyDestroy == NULL)
     {
         jWindowNotifyDestroy = (*env)->GetMethodID(env, jWindowClass, "notifyDestroy", "()V");
+        if ((*env)->ExceptionCheck(env)) return;
     }
     
     if (jWindowNotifyDelegatePtr == NULL)