8035320: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_DnDDS.cpp
authorpchelko
Tue, 04 Mar 2014 17:29:40 +0400
changeset 23616 d4680386f38a
parent 23615 a0825e77bfad
child 23617 1d73e27bd778
8035320: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_DnDDS.cpp Reviewed-by: anthony, serb
jdk/src/windows/native/sun/windows/awt_DnDDS.cpp
jdk/src/windows/native/sun/windows/awt_DnDDT.cpp
--- a/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp	Tue Mar 04 17:06:00 2014 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp	Tue Mar 04 17:29:40 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
@@ -643,6 +643,7 @@
          m_lastmods == modifiers) {//cannot move before cursor change
         call_dSCmouseMoved(env, m_peer,
                            m_actions, modifiers, dragPoint.x, dragPoint.y);
+        JNU_CHECK_EXCEPTION_RETURN(env, E_UNEXPECTED);
         m_dragPoint = dragPoint;
     }
 
@@ -977,6 +978,10 @@
     if ((matchedFormatEtc.tymed & TYMED_ISTREAM) != 0) {
         jboolean isCopy;
         jbyte *bBytes = env->GetByteArrayElements(bytes, &isCopy);
+        if (bBytes == NULL) {
+            env->PopLocalFrame(NULL);
+            return E_UNEXPECTED;
+        }
 
         ULONG act;
         HRESULT res = pmedium->pstm->Write((const void *)bBytes, (ULONG)nBytes,
--- a/jdk/src/windows/native/sun/windows/awt_DnDDT.cpp	Tue Mar 04 17:06:00 2014 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_DnDDT.cpp	Tue Mar 04 17:29:40 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
@@ -603,6 +603,10 @@
             jobject local = JNU_NewStringPlatform(
                 env,
                 pmedium->lpszFileName);
+            if (env->ExceptionCheck()) {
+                hr = E_OUTOFMEMORY;
+                break;
+            }
             jstring fileName = (jstring)env->NewGlobalRef(local);
             env->DeleteLocalRef(local);
 
@@ -1220,8 +1224,6 @@
 
 /*****************************************************************************/
 
-jclass WDTCPIStreamWrapper::javaIOExceptionClazz = (jclass)NULL;
-
 /**
  * construct a wrapper
  */
@@ -1233,16 +1235,6 @@
     m_istream   = stgmedium->pstm;
     m_istream->AddRef();
     m_mutex     = ::CreateMutex(NULL, FALSE, NULL);
-
-    if (javaIOExceptionClazz == (jclass)NULL) {
-        javaIOExceptionClazz = env->FindClass("java/io/IOException");
-
-        if (JNU_IsNull(env, javaIOExceptionClazz)) {
-            env->ThrowNew(env->FindClass("java/lang/ClassNotFoundException"),
-                          "Cant find java/io/IOException"
-            );
-        }
-    }
 }
 
 /**
@@ -1291,12 +1283,12 @@
     JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 
     if (m_istream->Stat(&m_statstg, STATFLAG_NONAME) != S_OK) {
-        env->ThrowNew(javaIOExceptionClazz, "IStream::Stat() failed");
+        JNU_ThrowIOException(env, "IStream::Stat() failed");
         return 0;
     }
 
     if (m_statstg.cbSize.QuadPart > 0x7ffffffL) {
-        env->ThrowNew(javaIOExceptionClazz, "IStream::Stat() cbSize > 0x7ffffff");
+        JNU_ThrowIOException(env, "IStream::Stat() cbSize > 0x7ffffff");
         return 0;
     }
 
@@ -1349,7 +1341,7 @@
             return (jint)(actual == 0 ? -1 : b);
 
         default:
-            env->ThrowNew(javaIOExceptionClazz, "IStream::Read failed");
+            JNU_ThrowIOException(env, "IStream::Read failed");
     }
     return (jint)-1;
 }
@@ -1394,6 +1386,7 @@
     ULONG    actual  = 0;
     jbyte*   local   = env->GetByteArrayElements(buf, &isCopy);
     HRESULT  res;
+    CHECK_NULL_RETURN(local, (jint)-1);
 
     switch (res = m_istream->Read((void *)(local + off), (ULONG)len, &actual)) {
         case S_FALSE:
@@ -1406,7 +1399,7 @@
 
         default:
             env->ReleaseByteArrayElements(buf, local, JNI_ABORT);
-            env->ThrowNew(javaIOExceptionClazz, "IStream::Read failed");
+            JNU_ThrowIOException(env, "IStream::Read failed");
     }
 
     return (jint)-1;