8030787: [Parfait] JNI-related warnings from b119 for jdk/src/share/native/sun/awt/image
authorpchelko
Thu, 13 Mar 2014 12:52:29 +0400
changeset 23644 0cdb97daeef5
parent 23643 7e8d79551a13
child 23645 5492589fa926
8030787: [Parfait] JNI-related warnings from b119 for jdk/src/share/native/sun/awt/image Reviewed-by: serb, prr
jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c
jdk/src/share/native/sun/awt/image/DataBufferNative.c
jdk/src/share/native/sun/awt/image/awt_ImageRep.c
jdk/src/share/native/sun/awt/image/awt_parseImage.c
jdk/src/share/native/sun/awt/image/gif/gifdecoder.c
jdk/src/share/native/sun/awt/image/imageInitIDs.c
jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c
jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c
--- a/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c	Thu Mar 13 12:52:29 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2012, 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
@@ -69,17 +69,14 @@
     }
 
     clsICMCD = (*env)->NewWeakGlobalRef(env, cd);
-    initICMCDmID = (*env)->GetMethodID(env, cd, "<init>", "(J)V");
-    pDataID = (*env)->GetFieldID(env, cd, "pData", "J");
-
-    rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I");
-    allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z");
-    mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I");
-    colorDataID = (*env)->GetFieldID(env, icm, "colorData",
-        "Lsun/awt/image/BufImgSurfaceData$ICMColorData;");
-    if (allGrayID == 0 || rgbID == 0 || mapSizeID == 0 || pDataID == 0|| colorDataID == 0 || initICMCDmID == 0) {
-        JNU_ThrowInternalError(env, "Could not get field IDs");
-    }
+    JNU_CHECK_EXCEPTION(env);
+    CHECK_NULL(initICMCDmID = (*env)->GetMethodID(env, cd, "<init>", "(J)V"));
+    CHECK_NULL(pDataID = (*env)->GetFieldID(env, cd, "pData", "J"));
+    CHECK_NULL(rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I"));
+    CHECK_NULL(allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z"));
+    CHECK_NULL(mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I"));
+    CHECK_NULL(colorDataID = (*env)->GetFieldID(env, icm, "colorData",
+                                           "Lsun/awt/image/BufImgSurfaceData$ICMColorData;"));
 }
 
 /*
@@ -120,6 +117,7 @@
     bisdo->sdOps.Unlock = NULL;
     bisdo->sdOps.Dispose = BufImg_Dispose;
     bisdo->array = (*env)->NewWeakGlobalRef(env, array);
+    JNU_CHECK_EXCEPTION(env);
     bisdo->offset = offset;
     bisdo->bitoffset = bitoffset;
     bisdo->scanStr = scanStr;
@@ -131,6 +129,7 @@
     } else {
         jobject lutarray = (*env)->GetObjectField(env, icm, rgbID);
         bisdo->lutarray = (*env)->NewWeakGlobalRef(env, lutarray);
+        JNU_CHECK_EXCEPTION(env);
         bisdo->lutsize = (*env)->GetIntField(env, icm, mapSizeID);
         bisdo->icm = (*env)->NewWeakGlobalRef(env, icm);
     }
@@ -174,8 +173,8 @@
     {
         bipriv->cData = BufImg_SetupICM(env, bisdo);
         if (bipriv->cData == NULL) {
-            JNU_ThrowNullPointerException(env, "Could not initialize "
-                                          "inverse tables");
+            (*env)->ExceptionClear(env);
+            JNU_ThrowNullPointerException(env, "Could not initialize inverse tables");
             return SD_FAILURE;
         }
     } else {
@@ -201,6 +200,7 @@
     if ((bipriv->lockFlags & (SD_LOCK_RD_WR)) != 0) {
         bipriv->base =
             (*env)->GetPrimitiveArrayCritical(env, bisdo->array, NULL);
+        CHECK_NULL(bipriv->base);
     }
     if ((bipriv->lockFlags & (SD_LOCK_LUT)) != 0) {
         bipriv->lutbase =
@@ -291,6 +291,7 @@
             = (*env)->GetBooleanField(env, bisdo->icm, allGrayID);
         int *pRgb = (int *)
             ((*env)->GetPrimitiveArrayCritical(env, bisdo->lutarray, NULL));
+        CHECK_NULL_RETURN(pRgb, (ColorData*)NULL);
         cData->img_clr_tbl = initCubemap(pRgb, bisdo->lutsize, 32);
         if (allGray == JNI_TRUE) {
             initInverseGrayLut(pRgb, bisdo->lutsize, cData);
@@ -303,6 +304,7 @@
         if (JNU_IsNull(env, colorData)) {
             jlong pData = ptr_to_jlong(cData);
             colorData = (*env)->NewObjectA(env, clsICMCD, initICMCDmID, (jvalue *)&pData);
+            JNU_CHECK_EXCEPTION_RETURN(env, (ColorData*)NULL);
             (*env)->SetObjectField(env, bisdo->icm, colorDataID, colorData);
         }
     }
--- a/jdk/src/share/native/sun/awt/image/DataBufferNative.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/DataBufferNative.c	Thu Mar 13 12:52:29 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2012, 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
@@ -74,6 +74,7 @@
     SurfaceDataOps *ops;
 
     ops = SurfaceData_GetOps(env, sd);
+    JNU_CHECK_EXCEPTION_RETURN(env, -1);
 
     if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo,
                                          ops, SD_LOCK_READ)))
@@ -115,6 +116,7 @@
 
 
     ops = SurfaceData_GetOps(env, sd);
+    JNU_CHECK_EXCEPTION(env);
 
     if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo,
                                          ops, SD_LOCK_WRITE)))
--- a/jdk/src/share/native/sun/awt/image/awt_ImageRep.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/awt_ImageRep.c	Thu Mar 13 12:52:29 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
@@ -97,9 +97,9 @@
 
 JNIEXPORT void JNICALL
 Java_sun_awt_image_ImageRepresentation_initIDs(JNIEnv *env, jclass cls) {
-    s_JnumSrcLUTID = (*env)->GetFieldID(env, cls, "numSrcLUT", "I");
-    s_JsrcLUTtransIndexID = (*env)->GetFieldID(env, cls, "srcLUTtransIndex",
-                                               "I");
+    CHECK_NULL(s_JnumSrcLUTID = (*env)->GetFieldID(env, cls, "numSrcLUT", "I"));
+    CHECK_NULL(s_JsrcLUTtransIndexID = (*env)->GetFieldID(env, cls,
+                                                          "srcLUTtransIndex", "I"));
 }
 
 /*
@@ -166,6 +166,7 @@
 
     cOffs = (int *) (*env)->GetPrimitiveArrayCritical(env, joffs, NULL);
     if (cOffs == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowNullPointerException(env, "Null channel offset array");
         return JNI_FALSE;
     }
@@ -190,6 +191,7 @@
 
     srcLUT = (int *) (*env)->GetPrimitiveArrayCritical(env, jlut, NULL);
     if (srcLUT == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowNullPointerException(env, "Null IndexColorModel LUT");
         return JNI_FALSE;
     }
@@ -198,6 +200,7 @@
                                                                   NULL);
     if (srcData == NULL) {
         (*env)->ReleasePrimitiveArrayCritical(env, jlut, srcLUT, JNI_ABORT);
+        (*env)->ExceptionClear(env);
         JNU_ThrowNullPointerException(env, "Null data array");
         return JNI_FALSE;
     }
@@ -206,6 +209,7 @@
     if (dstData == NULL) {
         (*env)->ReleasePrimitiveArrayCritical(env, jlut, srcLUT, JNI_ABORT);
         (*env)->ReleasePrimitiveArrayCritical(env, jpix, srcData, JNI_ABORT);
+        (*env)->ExceptionClear(env);
         JNU_ThrowNullPointerException(env, "Null tile data array");
         return JNI_FALSE;
     }
--- a/jdk/src/share/native/sun/awt/image/awt_parseImage.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/awt_parseImage.c	Thu Mar 13 12:52:29 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
@@ -226,8 +226,11 @@
 
     rasterP->sppsm.isUsed = 0;
 
+    jclass singlePixelPackedSampleModelClass = (*env)->FindClass(env,
+                            "java/awt/image/SinglePixelPackedSampleModel");
+    CHECK_NULL_RETURN(singlePixelPackedSampleModelClass, -1);
     if ((*env)->IsInstanceOf(env, rasterP->jsampleModel,
-       (*env)->FindClass(env,"java/awt/image/SinglePixelPackedSampleModel"))) {
+                             singlePixelPackedSampleModelClass)) {
         jobject jmask, joffs, jnbits;
 
         rasterP->sppsm.isUsed = 1;
@@ -261,8 +264,19 @@
                                                     rasterP->jsampleModel,
                                                     g_SMHeightID);
 
-    if ((*env)->IsInstanceOf(env, jraster,
-         (*env)->FindClass(env, "sun/awt/image/IntegerComponentRaster"))){
+    jclass integerComponentRasterClass = (*env)->FindClass(env,
+                                    "sun/awt/image/IntegerComponentRaster");
+    CHECK_NULL_RETURN(integerComponentRasterClass, -1);
+    jclass byteComponentRasterClass = (*env)->FindClass(env,
+                                    "sun/awt/image/ByteComponentRaster");
+    CHECK_NULL_RETURN(byteComponentRasterClass, -1);
+    jclass shortComponentRasterClass = (*env)->FindClass(env,
+                                    "sun/awt/image/ShortComponentRaster");
+    CHECK_NULL_RETURN(shortComponentRasterClass, -1);
+    jclass bytePackedRasterClass = (*env)->FindClass(env,
+                                    "sun/awt/image/BytePackedRaster");
+    CHECK_NULL_RETURN(bytePackedRasterClass, -1);
+    if ((*env)->IsInstanceOf(env, jraster, integerComponentRasterClass)){
         rasterP->jdata = (*env)->GetObjectField(env, jraster, g_ICRdataID);
         rasterP->dataType = INT_DATA_TYPE;
         rasterP->dataSize = 4;
@@ -273,8 +287,7 @@
         rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_ICRpixstrID);
         joffs = (*env)->GetObjectField(env, jraster, g_ICRdataOffsetsID);
     }
-    else if ((*env)->IsInstanceOf(env, jraster,
-            (*env)->FindClass(env, "sun/awt/image/ByteComponentRaster"))){
+    else if ((*env)->IsInstanceOf(env, jraster, byteComponentRasterClass)){
         rasterP->jdata = (*env)->GetObjectField(env, jraster, g_BCRdataID);
         rasterP->dataType = BYTE_DATA_TYPE;
         rasterP->dataSize = 1;
@@ -285,8 +298,7 @@
         rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_BCRpixstrID);
         joffs = (*env)->GetObjectField(env, jraster, g_BCRdataOffsetsID);
     }
-    else if ((*env)->IsInstanceOf(env, jraster,
-            (*env)->FindClass(env, "sun/awt/image/ShortComponentRaster"))){
+    else if ((*env)->IsInstanceOf(env, jraster, shortComponentRasterClass)){
         rasterP->jdata = (*env)->GetObjectField(env, jraster, g_SCRdataID);
         rasterP->dataType = SHORT_DATA_TYPE;
         rasterP->dataSize = 2;
@@ -297,8 +309,7 @@
         rasterP->pixelStride = (*env)->GetIntField(env, jraster, g_SCRpixstrID);
         joffs = (*env)->GetObjectField(env, jraster, g_SCRdataOffsetsID);
     }
-    else if ((*env)->IsInstanceOf(env, jraster,
-            (*env)->FindClass(env, "sun/awt/image/BytePackedRaster"))){
+    else if ((*env)->IsInstanceOf(env, jraster, bytePackedRasterClass)){
         rasterP->rasterType = PACKED_RASTER_TYPE;
         rasterP->dataType = BYTE_DATA_TYPE;
         rasterP->dataSize = 1;
@@ -397,30 +408,41 @@
 }
 
 static int getColorModelType(JNIEnv *env, jobject jcmodel) {
-    int type = UNKNOWN_CM_TYPE;
+    jclass colorModelClass;
 
-    if ((*env)->IsInstanceOf(env, jcmodel,
-                 (*env)->FindClass(env, "java/awt/image/IndexColorModel")))
+    colorModelClass = (*env)->FindClass(env,
+                                        "java/awt/image/IndexColorModel");
+    CHECK_NULL_RETURN(colorModelClass, UNKNOWN_CM_TYPE);
+
+    if ((*env)->IsInstanceOf(env, jcmodel, colorModelClass))
     {
-        type = INDEX_CM_TYPE;
-    } else if ((*env)->IsInstanceOf(env, jcmodel,
-                 (*env)->FindClass(env, "java/awt/image/PackedColorModel")))
+        return INDEX_CM_TYPE;
+    }
+
+    colorModelClass = (*env)->FindClass(env,
+                                        "java/awt/image/PackedColorModel");
+    CHECK_NULL_RETURN(colorModelClass, UNKNOWN_CM_TYPE);
+    if ((*env)->IsInstanceOf(env, jcmodel, colorModelClass))
     {
-        if  ((*env)->IsInstanceOf(env, jcmodel,
-                (*env)->FindClass(env, "java/awt/image/DirectColorModel"))) {
-            type = DIRECT_CM_TYPE;
+        colorModelClass = (*env)->FindClass(env,
+                                            "java/awt/image/DirectColorModel");
+        CHECK_NULL_RETURN(colorModelClass, UNKNOWN_CM_TYPE);
+        if  ((*env)->IsInstanceOf(env, jcmodel, colorModelClass)) {
+            return DIRECT_CM_TYPE;
         }
         else {
-            type = PACKED_CM_TYPE;
+            return PACKED_CM_TYPE;
         }
     }
-    else if ((*env)->IsInstanceOf(env, jcmodel,
-                 (*env)->FindClass(env, "java/awt/image/ComponentColorModel")))
+    colorModelClass = (*env)->FindClass(env,
+                                        "java/awt/image/ComponentColorModel");
+    CHECK_NULL_RETURN(colorModelClass, UNKNOWN_CM_TYPE);
+    if ((*env)->IsInstanceOf(env, jcmodel, colorModelClass))
     {
-        type = COMPONENT_CM_TYPE;
+        return COMPONENT_CM_TYPE;
     }
 
-    return type;
+    return UNKNOWN_CM_TYPE;
 }
 
 int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
@@ -506,12 +528,13 @@
         if (s_jdefCM == NULL) {
             jobject defCM;
             jclass jcm = (*env)->FindClass(env, "java/awt/image/ColorModel");
+            CHECK_NULL_RETURN(jcm, -1);
             defCM = (*env)->CallStaticObjectMethod(env, jcm,
                                                    g_CMgetRGBdefaultMID, NULL);
             s_jdefCM = (*env)->NewGlobalRef(env, defCM);
             if (defCM == NULL || s_jdefCM == NULL) {
-                JNU_ThrowNullPointerException(env,
-                                              "Unable to find default CM");
+                (*env)->ExceptionClear(env);
+                JNU_ThrowNullPointerException(env, "Unable to find default CM");
                 return -1;
             }
         }
@@ -931,6 +954,7 @@
 
     jdata = (*env)->NewIntArray(env, maxSamples);
     if (JNU_IsNull(env, jdata)) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowOutOfMemoryError(env, "Out of Memory");
         return -1;
     }
@@ -1028,6 +1052,7 @@
 
     jdata = (*env)->NewIntArray(env, maxSamples);
     if (JNU_IsNull(env, jdata)) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowOutOfMemoryError(env, "Out of Memory");
         return -1;
     }
--- a/jdk/src/share/native/sun/awt/image/gif/gifdecoder.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/gif/gifdecoder.c	Thu Mar 13 12:52:29 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2006, 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
@@ -104,12 +104,12 @@
 JNIEXPORT void JNICALL
 Java_sun_awt_image_GifImageDecoder_initIDs(JNIEnv *env, jclass this)
 {
-    readID = (*env)->GetMethodID(env, this, "readBytes", "([BII)I");
-    sendID = (*env)->GetMethodID(env, this, "sendPixels",
-                                 "(IIII[BLjava/awt/image/ColorModel;)I");
-    prefixID = (*env)->GetFieldID(env, this, "prefix", "[S");
-    suffixID = (*env)->GetFieldID(env, this, "suffix", "[B");
-    outCodeID = (*env)->GetFieldID(env, this, "outCode", "[B");
+    CHECK_NULL(readID = (*env)->GetMethodID(env, this, "readBytes", "([BII)I"));
+    CHECK_NULL(sendID = (*env)->GetMethodID(env, this, "sendPixels",
+                                 "(IIII[BLjava/awt/image/ColorModel;)I"));
+    CHECK_NULL(prefixID = (*env)->GetFieldID(env, this, "prefix", "[S"));
+    CHECK_NULL(suffixID = (*env)->GetFieldID(env, this, "suffix", "[B"));
+    CHECK_NULL(outCodeID = (*env)->GetFieldID(env, this, "outCode", "[B"));
 }
 
 JNIEXPORT jboolean JNICALL
@@ -291,8 +291,10 @@
              * reads the immediately subsequent code as uncompressed data.
              */
             if (verbose) {
+                RELEASE_ARRAYS();
                 fprintf(stdout, ".");
                 fflush(stdout);
+                GET_ARRAYS();
             }
 
             /* Note that freeCode is one less than it is supposed to be,
@@ -318,10 +320,10 @@
             /* make sure we read the whole block of pixels. */
         flushit:
             while (!blockEnd) {
+                RELEASE_ARRAYS();
                 if (verbose) {
                     fprintf(stdout, "flushing %d bytes\n", blockLength);
                 }
-                RELEASE_ARRAYS();
                 if ((*env)->CallIntMethod(env, this, readID,
                                           blockh, 0, blockLength + 1) != 0
                     || (*env)->ExceptionOccurred(env))
--- a/jdk/src/share/native/sun/awt/image/imageInitIDs.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/imageInitIDs.c	Thu Mar 13 12:52:29 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 1998, 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
@@ -29,211 +29,139 @@
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_BufferedImage_initIDs(JNIEnv *env, jclass cls) {
-    g_BImgRasterID     = (*env)->GetFieldID(env, cls, "raster",
-                                            "Ljava/awt/image/WritableRaster;");
-    g_BImgTypeID = (*env)->GetFieldID(env, cls, "imageType", "I");
-    g_BImgCMID = (*env)->GetFieldID(env, cls, "colorModel",
-                                    "Ljava/awt/image/ColorModel;");
-    g_BImgGetRGBMID = (*env)->GetMethodID(env, cls, "getRGB",
-                                          "(IIII[III)[I");
-    g_BImgSetRGBMID = (*env)->GetMethodID(env, cls, "setRGB",
-                                          "(IIII[III)V");
-    if (g_BImgRasterID == NULL || g_BImgTypeID == NULL || g_BImgCMID == NULL
-        || g_BImgGetRGBMID == NULL) {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_BImgRasterID = (*env)->GetFieldID(env, cls, "raster",
+                                        "Ljava/awt/image/WritableRaster;"));
+    CHECK_NULL(g_BImgTypeID = (*env)->GetFieldID(env, cls, "imageType", "I"));
+    CHECK_NULL(g_BImgCMID = (*env)->GetFieldID(env, cls, "colorModel",
+                                        "Ljava/awt/image/ColorModel;"));
+    CHECK_NULL(g_BImgGetRGBMID = (*env)->GetMethodID(env, cls, "getRGB",
+                                        "(IIII[III)[I"));
+    CHECK_NULL(g_BImgSetRGBMID = (*env)->GetMethodID(env, cls, "setRGB",
+                                        "(IIII[III)V"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_Raster_initIDs(JNIEnv *env, jclass cls) {
-    g_RasterWidthID    = (*env)->GetFieldID(env, cls, "width", "I");
-    g_RasterHeightID   = (*env)->GetFieldID(env, cls, "height", "I");
-    g_RasterNumBandsID = (*env)->GetFieldID(env, cls, "numBands", "I");
-    g_RasterGetDataMID = (*env)->GetMethodID(env, cls, "getDataElements",
-                              "(IIIILjava/lang/Object;)Ljava/lang/Object;");
-    g_RasterMinXID  = (*env)->GetFieldID(env, cls, "minX", "I");
-    g_RasterMinYID  = (*env)->GetFieldID(env, cls, "minY", "I");
-    g_RasterBaseOriginXID  = (*env)->GetFieldID(env, cls,
-                                 "sampleModelTranslateX", "I");
-    g_RasterBaseOriginYID  = (*env)->GetFieldID(env, cls,
-                                 "sampleModelTranslateY", "I");
-    g_RasterSampleModelID = (*env)->GetFieldID(env, cls,
-                                 "sampleModel","Ljava/awt/image/SampleModel;");
-    g_RasterNumDataElementsID = (*env)->GetFieldID(env, cls, "numDataElements",
-                                                   "I");
-    g_RasterNumBandsID = (*env)->GetFieldID(env, cls, "numBands", "I");
-    g_RasterDataBufferID = (*env)->GetFieldID(env, cls, "dataBuffer",
-                                              "Ljava/awt/image/DataBuffer;");
-    if (g_RasterWidthID == NULL || g_RasterHeightID == NULL
-        || g_RasterNumBandsID == NULL || g_RasterGetDataMID == NULL
-        || g_RasterMinXID == NULL || g_RasterMinYID == NULL
-        || g_RasterBaseOriginXID == NULL || g_RasterBaseOriginYID == NULL
-        || g_RasterSampleModelID == NULL || g_RasterNumDataElementsID == NULL
-        || g_RasterNumBandsID == NULL || g_RasterDataBufferID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_RasterWidthID    = (*env)->GetFieldID(env, cls, "width", "I"));
+    CHECK_NULL(g_RasterHeightID   = (*env)->GetFieldID(env, cls, "height", "I"));
+    CHECK_NULL(g_RasterNumBandsID = (*env)->GetFieldID(env, cls, "numBands", "I"));
+    CHECK_NULL(g_RasterGetDataMID = (*env)->GetMethodID(env, cls, "getDataElements",
+                                        "(IIIILjava/lang/Object;)Ljava/lang/Object;"));
+    CHECK_NULL(g_RasterMinXID  = (*env)->GetFieldID(env, cls, "minX", "I"));
+    CHECK_NULL(g_RasterMinYID  = (*env)->GetFieldID(env, cls, "minY", "I"));
+    CHECK_NULL(g_RasterBaseOriginXID  = (*env)->GetFieldID(env, cls,
+                                        "sampleModelTranslateX", "I"));
+    CHECK_NULL(g_RasterBaseOriginYID  = (*env)->GetFieldID(env, cls,
+                                        "sampleModelTranslateY", "I"));
+    CHECK_NULL(g_RasterSampleModelID = (*env)->GetFieldID(env, cls,
+                                        "sampleModel","Ljava/awt/image/SampleModel;"));
+    CHECK_NULL(g_RasterNumDataElementsID = (*env)->GetFieldID(env, cls,
+                                        "numDataElements", "I"));
+    CHECK_NULL(g_RasterNumBandsID = (*env)->GetFieldID(env, cls, "numBands", "I"));
+    CHECK_NULL(g_RasterDataBufferID = (*env)->GetFieldID(env, cls, "dataBuffer",
+                                        "Ljava/awt/image/DataBuffer;"));
 }
 
 JNIEXPORT void JNICALL
 Java_sun_awt_image_ByteComponentRaster_initIDs(JNIEnv *env, jclass cls) {
-    g_BCRdataID = (*env)->GetFieldID(env, cls, "data", "[B");
-    g_BCRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I");
-    g_BCRpixstrID = (*env)->GetFieldID(env, cls, "pixelStride", "I");
-    g_BCRbandoffsID = (*env)->GetFieldID(env, cls, "bandOffset", "I");
-    g_BCRdataOffsetsID = (*env)->GetFieldID(env, cls, "dataOffsets", "[I");
-    g_BCRtypeID = (*env)->GetFieldID(env, cls, "type", "I");
-    if (g_BCRdataID == NULL || g_BCRscanstrID == NULL ||
-        g_BCRpixstrID == NULL || g_BCRbandoffsID == NULL ||
-        g_BCRtypeID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_BCRdataID = (*env)->GetFieldID(env, cls, "data", "[B"));
+    CHECK_NULL(g_BCRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I"));
+    CHECK_NULL(g_BCRpixstrID = (*env)->GetFieldID(env, cls, "pixelStride", "I"));
+    CHECK_NULL(g_BCRbandoffsID = (*env)->GetFieldID(env, cls, "bandOffset", "I"));
+    CHECK_NULL(g_BCRdataOffsetsID = (*env)->GetFieldID(env, cls, "dataOffsets", "[I"));
+    CHECK_NULL(g_BCRtypeID = (*env)->GetFieldID(env, cls, "type", "I"));
 }
 
 JNIEXPORT void JNICALL
 Java_sun_awt_image_BytePackedRaster_initIDs(JNIEnv *env, jclass cls) {
-    g_BPRdataID = (*env)->GetFieldID(env, cls, "data", "[B");
-    g_BPRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I");
-    g_BPRpixstrID = (*env)->GetFieldID(env, cls, "pixelBitStride", "I");
-    g_BPRtypeID = (*env)->GetFieldID(env, cls, "type", "I");
-    g_BPRdataBitOffsetID = (*env)->GetFieldID(env, cls, "dataBitOffset", "I");
-    if (g_BPRdataID == NULL || g_BPRscanstrID == NULL ||
-        g_BPRpixstrID == NULL ||  g_BPRtypeID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_BPRdataID = (*env)->GetFieldID(env, cls, "data", "[B"));
+    CHECK_NULL(g_BPRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I"));
+    CHECK_NULL(g_BPRpixstrID = (*env)->GetFieldID(env, cls, "pixelBitStride", "I"));
+    CHECK_NULL(g_BPRtypeID = (*env)->GetFieldID(env, cls, "type", "I"));
+    CHECK_NULL(g_BPRdataBitOffsetID = (*env)->GetFieldID(env, cls, "dataBitOffset", "I"));
 }
 
 JNIEXPORT void JNICALL
 Java_sun_awt_image_ShortComponentRaster_initIDs(JNIEnv *env, jclass cls) {
-    g_SCRdataID = (*env)->GetFieldID(env, cls, "data", "[S");
-    g_SCRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I");
-    g_SCRpixstrID = (*env)->GetFieldID(env, cls, "pixelStride", "I");
-    g_SCRbandoffsID = (*env)->GetFieldID(env, cls, "bandOffset", "I");
-    g_SCRdataOffsetsID = (*env)->GetFieldID(env, cls, "dataOffsets", "[I");
-    g_SCRtypeID = (*env)->GetFieldID(env, cls, "type", "I");
-    if (g_SCRdataID == NULL || g_SCRscanstrID == NULL ||
-        g_SCRpixstrID == NULL || g_SCRbandoffsID == NULL ||
-        g_SCRdataOffsetsID == NULL || g_SCRtypeID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_SCRdataID = (*env)->GetFieldID(env, cls, "data", "[S"));
+    CHECK_NULL(g_SCRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I"));
+    CHECK_NULL(g_SCRpixstrID = (*env)->GetFieldID(env, cls, "pixelStride", "I"));
+    CHECK_NULL(g_SCRbandoffsID = (*env)->GetFieldID(env, cls, "bandOffset", "I"));
+    CHECK_NULL(g_SCRdataOffsetsID = (*env)->GetFieldID(env, cls, "dataOffsets", "[I"));
+    CHECK_NULL(g_SCRtypeID = (*env)->GetFieldID(env, cls, "type", "I"));
 }
 JNIEXPORT void JNICALL
 Java_sun_awt_image_IntegerComponentRaster_initIDs(JNIEnv *env, jclass cls) {
-    g_ICRdataID = (*env)->GetFieldID(env, cls, "data", "[I");
-    g_ICRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I");
-    g_ICRpixstrID = (*env)->GetFieldID(env, cls, "pixelStride", "I");
-    g_ICRdataOffsetsID = (*env)->GetFieldID(env, cls, "dataOffsets", "[I");
-    g_ICRbandoffsID = (*env)->GetFieldID(env, cls, "bandOffset", "I");
-    g_ICRputDataMID  = (*env)->GetMethodID(env, cls, "setDataElements",
-                                     "(IIIILjava/lang/Object;)V");
-    g_ICRtypeID = (*env)->GetFieldID(env, cls, "type", "I");
-    if (g_ICRdataID == NULL || g_ICRscanstrID == NULL
-        || g_ICRpixstrID == NULL || g_ICRbandoffsID == NULL
-        || g_ICRputDataMID == NULL || g_ICRdataOffsetsID == NULL || g_ICRtypeID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_ICRdataID = (*env)->GetFieldID(env, cls, "data", "[I"));
+    CHECK_NULL(g_ICRscanstrID = (*env)->GetFieldID(env, cls, "scanlineStride", "I"));
+    CHECK_NULL(g_ICRpixstrID = (*env)->GetFieldID(env, cls, "pixelStride", "I"));
+    CHECK_NULL(g_ICRdataOffsetsID = (*env)->GetFieldID(env, cls, "dataOffsets", "[I"));
+    CHECK_NULL(g_ICRbandoffsID = (*env)->GetFieldID(env, cls, "bandOffset", "I"));
+    CHECK_NULL(g_ICRputDataMID  = (*env)->GetMethodID(env, cls, "setDataElements",
+                                     "(IIIILjava/lang/Object;)V"));
+    CHECK_NULL(g_ICRtypeID = (*env)->GetFieldID(env, cls, "type", "I"));
 }
 
 JNIEXPORT void JNICALL
-Java_java_awt_image_SinglePixelPackedSampleModel_initIDs(JNIEnv *env,
-                                                         jclass cls) {
-    g_SPPSMmaskArrID = (*env)->GetFieldID(env, cls, "bitMasks", "[I");
-    g_SPPSMmaskOffID = (*env)->GetFieldID(env, cls, "bitOffsets", "[I");
-    g_SPPSMnBitsID   = (*env)->GetFieldID(env, cls, "bitSizes", "[I");
-    g_SPPSMmaxBitID  = (*env)->GetFieldID(env, cls, "maxBitSize", "I");
-
-    if (g_SPPSMmaskArrID == NULL || g_SPPSMmaskOffID == NULL ||
-        g_SPPSMnBitsID == NULL || g_SPPSMmaxBitID == NULL) {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+Java_java_awt_image_SinglePixelPackedSampleModel_initIDs(JNIEnv *env, jclass cls) {
+    CHECK_NULL(g_SPPSMmaskArrID = (*env)->GetFieldID(env, cls, "bitMasks", "[I"));
+    CHECK_NULL(g_SPPSMmaskOffID = (*env)->GetFieldID(env, cls, "bitOffsets", "[I"));
+    CHECK_NULL(g_SPPSMnBitsID   = (*env)->GetFieldID(env, cls, "bitSizes", "[I"));
+    CHECK_NULL(g_SPPSMmaxBitID  = (*env)->GetFieldID(env, cls, "maxBitSize", "I"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_ColorModel_initIDs(JNIEnv *env, jclass cls) {
-    g_CMpDataID = (*env)->GetFieldID (env, cls, "pData", "J");
-    g_CMnBitsID  = (*env)->GetFieldID(env, cls, "nBits", "[I");
-    g_CMcspaceID = (*env)->GetFieldID(env, cls, "colorSpace",
-                                    "Ljava/awt/color/ColorSpace;");
-    g_CMnumComponentsID = (*env)->GetFieldID(env, cls, "numComponents", "I");
-    g_CMsuppAlphaID  = (*env)->GetFieldID(env, cls, "supportsAlpha", "Z");
-    g_CMisAlphaPreID = (*env)->GetFieldID(env, cls, "isAlphaPremultiplied",
-                                          "Z");
-    g_CMtransparencyID = (*env)->GetFieldID(env, cls, "transparency", "I");
-    g_CMgetRGBMID      = (*env)->GetMethodID(env, cls, "getRGB",
-                                             "(Ljava/lang/Object;)I");
-    g_CMcsTypeID       = (*env)->GetFieldID(env, cls, "colorSpaceType", "I");
-    g_CMis_sRGBID      = (*env)->GetFieldID(env, cls, "is_sRGB", "Z");
-    g_CMgetRGBdefaultMID   = (*env)->GetStaticMethodID(env, cls,
+    CHECK_NULL(g_CMpDataID = (*env)->GetFieldID (env, cls, "pData", "J"));
+    CHECK_NULL(g_CMnBitsID  = (*env)->GetFieldID(env, cls, "nBits", "[I"));
+    CHECK_NULL(g_CMcspaceID = (*env)->GetFieldID(env, cls, "colorSpace",
+                                    "Ljava/awt/color/ColorSpace;"));
+    CHECK_NULL(g_CMnumComponentsID = (*env)->GetFieldID(env, cls, "numComponents", "I"));
+    CHECK_NULL(g_CMsuppAlphaID  = (*env)->GetFieldID(env, cls, "supportsAlpha", "Z"));
+    CHECK_NULL(g_CMisAlphaPreID = (*env)->GetFieldID(env, cls, "isAlphaPremultiplied",
+                                          "Z"));
+    CHECK_NULL(g_CMtransparencyID = (*env)->GetFieldID(env, cls, "transparency", "I"));
+    CHECK_NULL(g_CMgetRGBMID      = (*env)->GetMethodID(env, cls, "getRGB",
+                                             "(Ljava/lang/Object;)I"));
+    CHECK_NULL(g_CMcsTypeID       = (*env)->GetFieldID(env, cls, "colorSpaceType", "I"));
+    CHECK_NULL(g_CMis_sRGBID      = (*env)->GetFieldID(env, cls, "is_sRGB", "Z"));
+    CHECK_NULL(g_CMgetRGBdefaultMID   = (*env)->GetStaticMethodID(env, cls,
                                                        "getRGBdefault",
-                                             "()Ljava/awt/image/ColorModel;");
-    if (g_CMnBitsID == NULL || g_CMcspaceID == NULL
-        || g_CMnumComponentsID == NULL || g_CMsuppAlphaID == NULL
-        || g_CMisAlphaPreID == NULL || g_CMtransparencyID == NULL
-        || g_CMgetRGBMID == NULL || g_CMgetRGBMID == NULL
-        || g_CMis_sRGBID == NULL || g_CMgetRGBdefaultMID == NULL
-        || g_CMpDataID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+                                             "()Ljava/awt/image/ColorModel;"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_IndexColorModel_initIDs(JNIEnv *env, jclass cls) {
-    g_ICMtransIdxID = (*env)->GetFieldID(env, cls, "transparent_index", "I");
-    g_ICMmapSizeID  = (*env)->GetFieldID(env, cls, "map_size", "I");
-    g_ICMrgbID      = (*env)->GetFieldID(env, cls, "rgb", "[I");
-    if (g_ICMtransIdxID == NULL || g_ICMmapSizeID == NULL
-        || g_ICMrgbID == NULL) {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_ICMtransIdxID = (*env)->GetFieldID(env, cls, "transparent_index", "I"));
+    CHECK_NULL(g_ICMmapSizeID  = (*env)->GetFieldID(env, cls, "map_size", "I"));
+    CHECK_NULL(g_ICMrgbID      = (*env)->GetFieldID(env, cls, "rgb", "[I"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_SampleModel_initIDs(JNIEnv *env, jclass cls) {
-    g_SMWidthID = (*env)->GetFieldID(env, cls, "width","I");
-    g_SMHeightID = (*env)->GetFieldID(env, cls, "height","I");
-    g_SMGetPixelsMID = (*env)->GetMethodID(env, cls, "getPixels",
-                                      "(IIII[ILjava/awt/image/DataBuffer;)[I");
-    g_SMSetPixelsMID = (*env)->GetMethodID(env, cls, "setPixels",
-                                      "(IIII[ILjava/awt/image/DataBuffer;)V");
-    if (g_SMWidthID == NULL || g_SMHeightID == NULL || g_SMGetPixelsMID == NULL
-        || g_SMSetPixelsMID == NULL) {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_SMWidthID = (*env)->GetFieldID(env, cls, "width","I"));
+    CHECK_NULL(g_SMHeightID = (*env)->GetFieldID(env, cls, "height","I"));
+    CHECK_NULL(g_SMGetPixelsMID = (*env)->GetMethodID(env, cls, "getPixels",
+                                      "(IIII[ILjava/awt/image/DataBuffer;)[I"));
+    CHECK_NULL(g_SMSetPixelsMID = (*env)->GetMethodID(env, cls, "setPixels",
+                                      "(IIII[ILjava/awt/image/DataBuffer;)V"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_ComponentSampleModel_initIDs(JNIEnv *env, jclass cls) {
-    g_CSMPixStrideID = (*env)->GetFieldID(env, cls, "pixelStride", "I");
-    g_CSMScanStrideID = (*env)->GetFieldID(env, cls, "scanlineStride", "I");
-    g_CSMBandOffsetsID = (*env)->GetFieldID(env, cls, "bandOffsets", "[I");
-    if (g_CSMPixStrideID == NULL || g_CSMScanStrideID == NULL ||
-        g_CSMBandOffsetsID == NULL) {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_CSMPixStrideID = (*env)->GetFieldID(env, cls, "pixelStride", "I"));
+    CHECK_NULL(g_CSMScanStrideID = (*env)->GetFieldID(env, cls, "scanlineStride", "I"));
+    CHECK_NULL(g_CSMBandOffsetsID = (*env)->GetFieldID(env, cls, "bandOffsets", "[I"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_Kernel_initIDs(JNIEnv *env, jclass cls) {
-    g_KernelWidthID   = (*env)->GetFieldID(env, cls, "width", "I");
-    g_KernelHeightID  = (*env)->GetFieldID(env, cls, "height", "I");
-    g_KernelDataID    = (*env)->GetFieldID(env, cls, "data", "[F");
-    if (g_KernelWidthID == NULL || g_KernelHeightID == NULL
-        || g_KernelDataID == NULL)
-    {
-        JNU_ThrowNullPointerException(env, "Unable to grab field ids");
-    }
+    CHECK_NULL(g_KernelWidthID   = (*env)->GetFieldID(env, cls, "width", "I"));
+    CHECK_NULL(g_KernelHeightID  = (*env)->GetFieldID(env, cls, "height", "I"));
+    CHECK_NULL(g_KernelDataID    = (*env)->GetFieldID(env, cls, "data", "[F"));
 }
 
 JNIEXPORT void JNICALL
 Java_java_awt_image_DataBufferInt_initIDs(JNIEnv *env, jclass cls) {
-    g_DataBufferIntPdataID = (*env)->GetFieldID(env, cls, "pData", "J");
-    if (g_DataBufferIntPdataID == NULL) {
-        JNU_ThrowNullPointerException(env, "Unable to grab DataBufferInt.pData");
-        return;
-    }
+    CHECK_NULL(g_DataBufferIntPdataID = (*env)->GetFieldID(env, cls, "pData", "J"));
 }
--- a/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c	Thu Mar 13 12:52:29 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
@@ -153,6 +153,7 @@
     /* Initialize a new buffer */
     jbyteArray hInputBuffer = (*env)->NewByteArray(env, STREAMBUF_SIZE);
     if (hInputBuffer == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName( env,
                          "java/lang/OutOfMemoryError",
                          "Initializing Reader");
@@ -557,6 +558,7 @@
 
   // Create a new java string from the message
   string = (*env)->NewStringUTF(env, buffer);
+  CHECK_NULL(string);
 
   theObject = data->imageIOobj;
 
@@ -591,12 +593,7 @@
     /* Now we need a new weak global reference for the I/O provider */
     if (io != NULL) { // Fix for 4411955
         sb->ioRef = (*env)->NewWeakGlobalRef(env, io);
-        if (sb->ioRef == NULL) {
-            JNU_ThrowByName(env,
-                            "java/lang/OutOfMemoryError",
-                            "Setting I/O provider");
-            return;
-        }
+        CHECK_NULL(sb->ioRef);
     }
 
     /* And finally reset state */
@@ -693,6 +690,7 @@
     }
     for (i = 0; i < qlen; i++) {
         table = (*env)->GetObjectArrayElement(env, qtables, i);
+        CHECK_NULL_RETURN(table, 0);
         qdata = (*env)->GetObjectField(env, table, JPEGQTable_tableID);
         qdataBody = (*env)->GetPrimitiveArrayCritical(env, qdata, NULL);
 
@@ -724,7 +722,7 @@
     return qlen;
 }
 
-static void setHuffTable(JNIEnv *env,
+static boolean setHuffTable(JNIEnv *env,
                          JHUFF_TBL *huff_ptr,
                          jobject table) {
 
@@ -742,6 +740,8 @@
     hlensBody = (*env)->GetShortArrayElements(env,
                                               huffLens,
                                               NULL);
+    CHECK_NULL_RETURN(hlensBody, FALSE);
+
     if (hlensLen > 16) {
         /* Ignore extra elements of bits array. Only 16 elements can be
            stored. 0-th element is not used. (see jpeglib.h, line 107)  */
@@ -762,6 +762,7 @@
     hvalsBody = (*env)->GetShortArrayElements(env,
                                               huffValues,
                                               NULL);
+    CHECK_NULL_RETURN(hvalsBody, FALSE);
 
     if (hvalsLen > 256) {
         /* Ignore extra elements of hufval array. Only 256 elements
@@ -775,6 +776,7 @@
                                       huffValues,
                                       hvalsBody,
                                       JNI_ABORT);
+    return TRUE;
 }
 
 static int setHTables(JNIEnv *env,
@@ -810,7 +812,9 @@
             huff_ptr = comp->dc_huff_tbl_ptrs[i];
         }
         table = (*env)->GetObjectArrayElement(env, DCHuffmanTables, i);
-        setHuffTable(env, huff_ptr, table);
+        if (table == NULL || !setHuffTable(env, huff_ptr, table)) {
+            return 0;
+        }
         huff_ptr->sent_table = !write;
     }
     hlen = (*env)->GetArrayLength(env, ACHuffmanTables);
@@ -835,7 +839,9 @@
             huff_ptr = comp->ac_huff_tbl_ptrs[i];
         }
         table = (*env)->GetObjectArrayElement(env, ACHuffmanTables, i);
-        setHuffTable(env, huff_ptr, table);
+        if(table == NULL || !setHuffTable(env, huff_ptr, table)) {
+            return 0;
+        }
         huff_ptr->sent_table = !write;
     }
     return hlen;
@@ -1405,57 +1411,57 @@
      jclass qTableClass,
      jclass huffClass) {
 
-    JPEGImageReader_readInputDataID = (*env)->GetMethodID(env,
+    CHECK_NULL(JPEGImageReader_readInputDataID = (*env)->GetMethodID(env,
                                                   cls,
                                                   "readInputData",
-                                                  "([BII)I");
-    JPEGImageReader_skipInputBytesID = (*env)->GetMethodID(env,
+                                                  "([BII)I"));
+    CHECK_NULL(JPEGImageReader_skipInputBytesID = (*env)->GetMethodID(env,
                                                        cls,
                                                        "skipInputBytes",
-                                                       "(J)J");
-    JPEGImageReader_warningOccurredID = (*env)->GetMethodID(env,
+                                                       "(J)J"));
+    CHECK_NULL(JPEGImageReader_warningOccurredID = (*env)->GetMethodID(env,
                                                             cls,
                                                             "warningOccurred",
-                                                            "(I)V");
-    JPEGImageReader_warningWithMessageID =
+                                                            "(I)V"));
+    CHECK_NULL(JPEGImageReader_warningWithMessageID =
         (*env)->GetMethodID(env,
                             cls,
                             "warningWithMessage",
-                            "(Ljava/lang/String;)V");
-    JPEGImageReader_setImageDataID = (*env)->GetMethodID(env,
+                            "(Ljava/lang/String;)V"));
+    CHECK_NULL(JPEGImageReader_setImageDataID = (*env)->GetMethodID(env,
                                                          cls,
                                                          "setImageData",
-                                                         "(IIIII[B)V");
-    JPEGImageReader_acceptPixelsID = (*env)->GetMethodID(env,
+                                                         "(IIIII[B)V"));
+    CHECK_NULL(JPEGImageReader_acceptPixelsID = (*env)->GetMethodID(env,
                                                          cls,
                                                          "acceptPixels",
-                                                         "(IZ)V");
-    JPEGImageReader_passStartedID = (*env)->GetMethodID(env,
+                                                         "(IZ)V"));
+    CHECK_NULL(JPEGImageReader_passStartedID = (*env)->GetMethodID(env,
                                                         cls,
                                                         "passStarted",
-                                                        "(I)V");
-    JPEGImageReader_passCompleteID = (*env)->GetMethodID(env,
+                                                        "(I)V"));
+    CHECK_NULL(JPEGImageReader_passCompleteID = (*env)->GetMethodID(env,
                                                          cls,
                                                          "passComplete",
-                                                         "()V");
-    JPEGImageReader_pushBackID = (*env)->GetMethodID(env,
+                                                         "()V"));
+    CHECK_NULL(JPEGImageReader_pushBackID = (*env)->GetMethodID(env,
                                                      cls,
                                                      "pushBack",
-                                                     "(I)V");
-    JPEGQTable_tableID = (*env)->GetFieldID(env,
+                                                     "(I)V"));
+    CHECK_NULL(JPEGQTable_tableID = (*env)->GetFieldID(env,
                                             qTableClass,
                                             "qTable",
-                                            "[I");
-
-    JPEGHuffmanTable_lengthsID = (*env)->GetFieldID(env,
+                                            "[I"));
+
+    CHECK_NULL(JPEGHuffmanTable_lengthsID = (*env)->GetFieldID(env,
                                                     huffClass,
                                                     "lengths",
-                                                    "[S");
-
-    JPEGHuffmanTable_valuesID = (*env)->GetFieldID(env,
+                                                    "[S"));
+
+    CHECK_NULL(JPEGHuffmanTable_valuesID = (*env)->GetFieldID(env,
                                                     huffClass,
                                                     "values",
-                                                    "[S");
+                                                    "[S"));
 }
 
 JNIEXPORT jlong JNICALL
@@ -1536,9 +1542,9 @@
     /* set up the association to persist for future calls */
     ret = initImageioData(env, (j_common_ptr) cinfo, this);
     if (ret == NULL) {
-        JNU_ThrowByName( env,
-                         "java/lang/OutOfMemoryError",
-                         "Initializing Reader");
+        (*env)->ExceptionClear(env);
+        JNU_ThrowByName(env, "java/lang/OutOfMemoryError",
+                        "Initializing Reader");
         imageio_dispose((j_common_ptr)cinfo);
         return 0;
     }
@@ -1633,6 +1639,7 @@
 #endif
 
     if (GET_ARRAYS(env, data, &src->next_input_byte) == NOT_OK) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName(env,
                         "javax/imageio/IIOException",
                         "Array pin failed");
@@ -1896,6 +1903,7 @@
 
     body = (*env)->GetIntArrayElements(env, srcBands, NULL);
     if (body == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName( env,
                          "java/lang/OutOfMemoryError",
                          "Initializing Read");
@@ -1954,6 +1962,7 @@
     }
 
     if (GET_ARRAYS(env, data, &src->next_input_byte) == NOT_OK) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName(env,
                         "javax/imageio/IIOException",
                         "Array pin failed");
@@ -2399,44 +2408,39 @@
      jclass qTableClass,
      jclass huffClass) {
 
-    JPEGImageWriter_writeOutputDataID = (*env)->GetMethodID(env,
+    CHECK_NULL(JPEGImageWriter_writeOutputDataID = (*env)->GetMethodID(env,
                                                     cls,
                                                     "writeOutputData",
-                                                    "([BII)V");
-
-    JPEGImageWriter_warningOccurredID = (*env)->GetMethodID(env,
+                                                    "([BII)V"));
+    CHECK_NULL(JPEGImageWriter_warningOccurredID = (*env)->GetMethodID(env,
                                                             cls,
                                                             "warningOccurred",
-                                                            "(I)V");
-    JPEGImageWriter_warningWithMessageID =
-        (*env)->GetMethodID(env,
-                            cls,
-                            "warningWithMessage",
-                            "(Ljava/lang/String;)V");
-
-    JPEGImageWriter_writeMetadataID = (*env)->GetMethodID(env,
+                                                            "(I)V"));
+    CHECK_NULL(JPEGImageWriter_warningWithMessageID =
+                                        (*env)->GetMethodID(env,
+                                                            cls,
+                                                            "warningWithMessage",
+                                                            "(Ljava/lang/String;)V"));
+    CHECK_NULL(JPEGImageWriter_writeMetadataID = (*env)->GetMethodID(env,
                                                           cls,
                                                           "writeMetadata",
-                                                          "()V");
-    JPEGImageWriter_grabPixelsID = (*env)->GetMethodID(env,
+                                                          "()V"));
+    CHECK_NULL(JPEGImageWriter_grabPixelsID = (*env)->GetMethodID(env,
                                                        cls,
                                                        "grabPixels",
-                                                       "(I)V");
-
-    JPEGQTable_tableID = (*env)->GetFieldID(env,
+                                                       "(I)V"));
+    CHECK_NULL(JPEGQTable_tableID = (*env)->GetFieldID(env,
                                             qTableClass,
                                             "qTable",
-                                            "[I");
-
-    JPEGHuffmanTable_lengthsID = (*env)->GetFieldID(env,
+                                            "[I"));
+    CHECK_NULL(JPEGHuffmanTable_lengthsID = (*env)->GetFieldID(env,
                                                     huffClass,
                                                     "lengths",
-                                                    "[S");
-
-    JPEGHuffmanTable_valuesID = (*env)->GetFieldID(env,
+                                                    "[S"));
+    CHECK_NULL(JPEGHuffmanTable_valuesID = (*env)->GetFieldID(env,
                                                     huffClass,
                                                     "values",
-                                                    "[S");
+                                                    "[S"));
 }
 
 JNIEXPORT jlong JNICALL
@@ -2512,6 +2516,7 @@
     /* set up the association to persist for future calls */
     ret = initImageioData(env, (j_common_ptr) cinfo, this);
     if (ret == NULL) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName( env,
                          "java/lang/OutOfMemoryError",
                          "Initializing Writer");
@@ -2589,6 +2594,7 @@
 
     if (GET_ARRAYS(env, data,
                    (const JOCTET **)(&dest->next_output_byte)) == NOT_OK) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName(env,
                         "javax/imageio/IIOException",
                         "Array pin failed");
@@ -2660,6 +2666,7 @@
     imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr);
     j_compress_ptr cinfo;
     UINT8** scale = NULL;
+    boolean success = TRUE;
 
 
     /* verify the inputs */
@@ -2704,13 +2711,14 @@
     }
 
     bandSize = (*env)->GetIntArrayElements(env, bandSizes, NULL);
+    CHECK_NULL_RETURN(bandSize, JNI_FALSE);
 
     for (i = 0; i < numBands; i++) {
         if (bandSize[i] <= 0 || bandSize[i] > JPEG_BAND_SIZE) {
             (*env)->ReleaseIntArrayElements(env, bandSizes,
                                             bandSize, JNI_ABORT);
             JNU_ThrowByName(env, "javax/imageio/IIOException", "Invalid Image");
-            return JNI_FALSE;;
+            return JNI_FALSE;
         }
     }
 
@@ -2821,30 +2829,30 @@
     vfactors = (*env)->GetIntArrayElements(env, VsamplingFactors, NULL);
     qsels = (*env)->GetIntArrayElements(env, QtableSelectors, NULL);
 
-    if ((ids == NULL) ||
-        (hfactors == NULL) || (vfactors == NULL) ||
-        (qsels == NULL)) {
-        JNU_ThrowByName( env,
-                         "java/lang/OutOfMemoryError",
-                         "Writing JPEG");
-        return JNI_FALSE;
+    if (ids && hfactors && vfactors && qsels) {
+        for (i = 0; i < numBands; i++) {
+            cinfo->comp_info[i].component_id = ids[i];
+            cinfo->comp_info[i].h_samp_factor = hfactors[i];
+            cinfo->comp_info[i].v_samp_factor = vfactors[i];
+            cinfo->comp_info[i].quant_tbl_no = qsels[i];
+        }
+    } else {
+        success = FALSE;
     }
 
-    for (i = 0; i < numBands; i++) {
-        cinfo->comp_info[i].component_id = ids[i];
-        cinfo->comp_info[i].h_samp_factor = hfactors[i];
-        cinfo->comp_info[i].v_samp_factor = vfactors[i];
-        cinfo->comp_info[i].quant_tbl_no = qsels[i];
+    if (ids) {
+        (*env)->ReleaseIntArrayElements(env, componentIds, ids, JNI_ABORT);
+    }
+    if (hfactors) {
+        (*env)->ReleaseIntArrayElements(env, HsamplingFactors, hfactors, JNI_ABORT);
     }
-
-    (*env)->ReleaseIntArrayElements(env, componentIds,
-                                    ids, JNI_ABORT);
-    (*env)->ReleaseIntArrayElements(env, HsamplingFactors,
-                                    hfactors, JNI_ABORT);
-    (*env)->ReleaseIntArrayElements(env, VsamplingFactors,
-                                    vfactors, JNI_ABORT);
-    (*env)->ReleaseIntArrayElements(env, QtableSelectors,
-                                    qsels, JNI_ABORT);
+    if (vfactors) {
+        (*env)->ReleaseIntArrayElements(env, VsamplingFactors, vfactors, JNI_ABORT);
+    }
+    if (qsels) {
+        (*env)->ReleaseIntArrayElements(env, QtableSelectors, qsels, JNI_ABORT);
+    }
+    if (!success) return data->abortFlag;
 
     jpeg_suppress_tables(cinfo, TRUE);  // Disable writing any current
 
@@ -2861,6 +2869,7 @@
 
     if (GET_ARRAYS(env, data,
                    (const JOCTET **)(&dest->next_output_byte)) == NOT_OK) {
+        (*env)->ExceptionClear(env);
         JNU_ThrowByName(env,
                         "javax/imageio/IIOException",
                         "Array pin failed");
@@ -2895,6 +2904,7 @@
             cinfo->scan_info = cinfo->script_space;
             scanptr = (int *) cinfo->script_space;
             scanData = (*env)->GetIntArrayElements(env, scanInfo, NULL);
+            CHECK_NULL_RETURN(scanData, data->abortFlag);
             // number of jints per scan is 9
             // We avoid a memcpy to handle different size ints
             for (i = 0; i < numScans*9; i++) {
--- a/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c	Wed Mar 12 09:20:06 2014 -0700
+++ b/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c	Thu Mar 13 12:52:29 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
@@ -462,14 +462,14 @@
 Java_sun_awt_image_JPEGImageDecoder_initIDs(JNIEnv *env, jclass cls,
                                             jclass InputStreamClass)
 {
-    sendHeaderInfoID = (*env)->GetMethodID(env, cls, "sendHeaderInfo",
-                                           "(IIZZZ)Z");
-    sendPixelsByteID = (*env)->GetMethodID(env, cls, "sendPixels", "([BI)Z");
-    sendPixelsIntID = (*env)->GetMethodID(env, cls, "sendPixels", "([II)Z");
-    InputStream_readID = (*env)->GetMethodID(env, InputStreamClass,
-                                             "read", "([BII)I");
-    InputStream_availableID = (*env)->GetMethodID(env, InputStreamClass,
-                                                  "available", "()I");
+    CHECK_NULL(sendHeaderInfoID = (*env)->GetMethodID(env, cls, "sendHeaderInfo",
+                                           "(IIZZZ)Z"));
+    CHECK_NULL(sendPixelsByteID = (*env)->GetMethodID(env, cls, "sendPixels", "([BI)Z"));
+    CHECK_NULL(sendPixelsIntID = (*env)->GetMethodID(env, cls, "sendPixels", "([II)Z"));
+    CHECK_NULL(InputStream_readID = (*env)->GetMethodID(env, InputStreamClass,
+                                             "read", "([BII)I"));
+    CHECK_NULL(InputStream_availableID = (*env)->GetMethodID(env, InputStreamClass,
+                                                  "available", "()I"));
 }