changeset 9608:93fdbd0fb4da

8036762: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_Canvas.cpp Reviewed-by: serb, pchelko
author azvegint
date Mon, 17 Mar 2014 20:09:41 +0400
parents cdb25a970c76
children fef8ff53007c
files src/windows/native/sun/windows/awt_Canvas.cpp
diffstat 1 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/sun/windows/awt_Canvas.cpp	Mon Mar 17 19:35:13 2014 +0400
+++ b/src/windows/native/sun/windows/awt_Canvas.cpp	Mon Mar 17 20:09:41 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2009, 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
@@ -63,6 +63,10 @@
     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     jobject target = NULL;
+    jobject graphicsConfig = NULL;
+    jclass canvasClass = NULL;
+    jclass win32cls = NULL;
+
     AwtCanvas *canvas = NULL;
 
     try {
@@ -100,16 +104,24 @@
         // Set the pixel format of the HWND if a GraphicsConfiguration
         // was provided to the Canvas constructor.
 
-        jclass canvasClass = env->FindClass("java/awt/Canvas");
+        canvasClass = env->FindClass("java/awt/Canvas");
+        DASSERT(canvasClass != NULL);
+        if (!canvasClass) {
+            throw std::bad_alloc();
+        }
+
         if ( env->IsInstanceOf( target, canvasClass ) ) {
 
             // Get GraphicsConfig from our target
-            jobject graphicsConfig = env->GetObjectField(target,
+            graphicsConfig = env->GetObjectField(target,
                 AwtComponent::graphicsConfigID);
             if (graphicsConfig != NULL) {
 
-                jclass win32cls = env->FindClass("sun/awt/Win32GraphicsConfig");
+                win32cls = env->FindClass("sun/awt/Win32GraphicsConfig");
                 DASSERT (win32cls != NULL);
+                if (!win32cls) {
+                    throw std::bad_alloc();
+                }
 
                 if ( env->IsInstanceOf( graphicsConfig, win32cls ) ) {
                     // Get the visual ID member from our GC
@@ -131,8 +143,7 @@
                             env->ExceptionClear();
                             env->ThrowNew(excCls,
                              "\nUnable to set Pixel format on Canvas");
-                            env->DeleteLocalRef(target);
-                            return canvas;
+                            env->DeleteLocalRef(excCls);
                         }
                     }
                 }
@@ -141,11 +152,20 @@
     }
     } catch (...) {
         env->DeleteLocalRef(target);
+        env->DeleteLocalRef(graphicsConfig);
+        env->DeleteLocalRef(canvasClass);
+        env->DeleteLocalRef(win32cls);
+
+        env->DeleteGlobalRef(self);
+        env->DeleteGlobalRef(hParent);
         throw;
     }
 
 done:
     env->DeleteLocalRef(target);
+    env->DeleteLocalRef(graphicsConfig);
+    env->DeleteLocalRef(canvasClass);
+    env->DeleteLocalRef(win32cls);
     return canvas;
     CATCH_BAD_ALLOC_RET(0);
 }