changeset 9256:97dd049af730

8033370: [parfait] warning from b126 for solaris/native/sun/util/locale/provider: JNI exception pending Reviewed-by: msheppar
author naoto
date Thu, 06 Feb 2014 10:06:09 -0800
parents cc300f920f7f
children 509b6635b84f
files make/mapfiles/libjava/mapfile-vers src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c src/solaris/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java src/solaris/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c src/windows/native/java/lang/java_props_md.c src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c
diffstat 6 files changed, 155 insertions(+), 221 deletions(-) [+]
line wrap: on
line diff
--- a/make/mapfiles/libjava/mapfile-vers	Thu Feb 06 11:01:27 2014 -0500
+++ b/make/mapfiles/libjava/mapfile-vers	Thu Feb 06 10:06:09 2014 -0800
@@ -285,8 +285,6 @@
 #		Java_sun_misc_VM_unsuspendSomeThreads;		threads.c
 #		Java_sun_misc_VM_unsuspendThreads;		threads.c
 
-		Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPattern;
-
 	# Outcalls from libjvm done using dlsym().
 
 		VerifyClassCodes;
--- a/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Thu Feb 06 11:01:27 2014 -0500
+++ b/src/macosx/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Thu Feb 06 10:06:09 2014 -0800
@@ -24,6 +24,7 @@
  */
 
 #include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
+#include "jni_util.h"
 #include <CoreFoundation/CoreFoundation.h>
 #include <stdio.h>
 
@@ -63,6 +64,10 @@
     localeString = getMacOSXLocale(posixCat);
     if (localeString == NULL) {
         localeString = getPosixLocale(posixCat);
+        if (localeString == NULL) {
+            JNU_ThrowOutOfMemoryError(env, NULL);
+            return NULL;
+        }
     }
     ret = (*env)->NewStringUTF(env, localeString);
     free(localeString);
@@ -127,6 +132,7 @@
 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
     CFLocaleRef cflocale = CFLocaleCopyCurrent();
+    jstring tmp_string;
     if (cflocale != NULL) {
         CFDateFormatterRef df = CFDateFormatterCreate(kCFAllocatorDefault,
                                                   cflocale,
@@ -138,13 +144,18 @@
             if (amStr != NULL) {
                 CFStringGetCString(amStr, buf, BUFLEN, kCFStringEncodingUTF8);
                 CFRelease(amStr);
-                (*env)->SetObjectArrayElement(env, ampms, 0, (*env)->NewStringUTF(env, buf));
+                tmp_string = (*env)->NewStringUTF(env, buf);
+                if (tmp_string != NULL) {
+                    (*env)->SetObjectArrayElement(env, ampms, 0, tmp_string);
+                }
             }
-            CFStringRef pmStr = CFDateFormatterCopyProperty(df, kCFDateFormatterPMSymbol);
-            if (pmStr != NULL) {
-                CFStringGetCString(pmStr, buf, BUFLEN, kCFStringEncodingUTF8);
-                CFRelease(pmStr);
-                (*env)->SetObjectArrayElement(env, ampms, 1, (*env)->NewStringUTF(env, buf));
+            if (!(*env)->ExceptionCheck(env)){
+                CFStringRef pmStr = CFDateFormatterCopyProperty(df, kCFDateFormatterPMSymbol);
+                if (pmStr != NULL) {
+                    CFStringGetCString(pmStr, buf, BUFLEN, kCFStringEncodingUTF8);
+                    CFRelease(pmStr);
+                    (*env)->SetObjectArrayElement(env, ampms, 1, (*env)->NewStringUTF(env, buf));
+                }
             }
             CFRelease(df);
         }
@@ -647,10 +658,16 @@
 
 static void copyArrayElements(JNIEnv *env, CFArrayRef cfarray, jobjectArray jarray, CFIndex sindex, int dindex, int count) {
     char buf[BUFLEN];
+    jstring tmp_string;
 
     for (; count > 0; sindex++, dindex++, count--) {
         CFStringGetCString(CFArrayGetValueAtIndex(cfarray, sindex), buf, BUFLEN, kCFStringEncodingUTF8);
-        (*env)->SetObjectArrayElement(env, jarray, dindex, (*env)->NewStringUTF(env, buf));
+        tmp_string = (*env)->NewStringUTF(env, buf);
+        if (tmp_string != NULL) {
+            (*env)->SetObjectArrayElement(env, jarray, dindex, tmp_string);
+        } else {
+            break;
+        }
     }
 }
 
--- a/src/solaris/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Thu Feb 06 11:01:27 2014 -0500
+++ b/src/solaris/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java	Thu Feb 06 10:06:09 2014 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -25,100 +25,10 @@
 
 package sun.util.locale.provider;
 
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.text.spi.DateFormatProvider;
-import java.util.Locale;
-
 /**
  * LocaleProviderAdapter implementation for the Unix locale data
  *
  * @author Naoto Sato
  */
 public class HostLocaleProviderAdapterImpl {
-    static Locale[] supported = {Locale.getDefault(Locale.Category.FORMAT)};
-
-    public static DateFormatProvider getDateFormatProvider() {
-        return new DateFormatProvider() {
-            String posixPattern;
-
-            @Override
-            public Locale[] getAvailableLocales() {
-                // not implemented yet
-                return new Locale[0];
-            }
-            @Override
-            public DateFormat getDateInstance(int style, Locale locale) {
-                posixPattern = getPattern(style, -1, locale.toLanguageTag());
-                return new SimpleDateFormat(convertPosixToJava(posixPattern), locale);
-            }
-            @Override
-            public DateFormat getTimeInstance(int style, Locale locale) {
-                posixPattern = getPattern(-1, style, locale.toLanguageTag());
-                return new SimpleDateFormat(convertPosixToJava(posixPattern), locale);
-            }
-            @Override
-            public DateFormat getDateTimeInstance(int dateStyle,
-                    int timeStyle, Locale locale) {
-                posixPattern = getPattern(dateStyle, timeStyle, locale.toLanguageTag());
-                return new SimpleDateFormat(convertPosixToJava(posixPattern), locale);
-            }
-        };
-    }
-
-    private static String convertPosixToJava(String posixPattern) {
-        StringBuilder sb = new StringBuilder();
-        boolean conversion = false;
-
-        for (int index = 0; index < posixPattern.length(); index++) {
-            char c = posixPattern.charAt(index);
-            if (conversion) {
-                switch (c) {
-                case 'a':
-                    sb.append("EEE");
-                    break;
-                case 'b':
-                    sb.append("MMM");
-                    break;
-                case 'e':
-                    sb.append("dd");
-                    break;
-                case 'H':
-                    sb.append("kk");
-                    break;
-                case 'M':
-                    sb.append("mm");
-                    break;
-                case 'S':
-                    sb.append("ss");
-                    break;
-                case 'Y':
-                    sb.append("yyyy");
-                    break;
-                case 'm':
-                    sb.append("MM");
-                    break;
-                case 'd':
-                    sb.append("dd");
-                    break;
-                case 'r':
-                    sb.append("hh:mm:ss aa");
-                    break;
-                case 'Z':
-                    sb.append("zzz");
-                    break;
-                }
-                conversion = false;
-            } else {
-                if (c == '%') {
-                    conversion = true;
-                } else {
-                    sb.append(c);
-                }
-            }
-        }
-        return sb.toString();
-    }
-
-    private static native String getPattern(int dateStyle, int timeStyle, String langtag);
 }
--- a/src/solaris/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Thu Feb 06 11:01:27 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2012, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
-#include <gdefs.h>
-#include <string.h>
-#include <langinfo.h>
-#include <locale.h>
-
-#define BUFLEN 64
-
-/*
- * Class:     sun_util_locale_provider_HostLocaleProviderAdapterImpl
- * Method:    getPattern
- * Signature: (IILjava/lang/String;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPattern
-  (JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
-
-    // TEMPORARY!
-    char locale[BUFLEN];
-    char * pch;
-    char * old;
-    char * ret;
-    const char *langtag = (*env)->GetStringUTFChars(env, jlangtag, JNI_FALSE);
-
-    strcpy(locale, langtag);
-    pch = strchr(locale, '-');
-    if (pch != NULL) {
-        *pch = '_';
-    }
-    pch = strchr(locale, '-');
-    if (pch != NULL) {
-        *pch = '\0';
-    }
-    strcat(locale, ".UTF-8");
-    old = setlocale(LC_TIME, "");
-    setlocale(LC_TIME, locale);
-
-    if (dateStyle != (-1) && timeStyle != (-1)) {
-        ret = nl_langinfo(D_T_FMT);
-    } else if (dateStyle != (-1)) {
-        ret = nl_langinfo(D_FMT);
-    } else if (timeStyle != (-1)) {
-        ret = nl_langinfo(T_FMT);
-    } else {
-        ret = "yyyy/MM/dd";
-    }
-
-    setlocale(LC_TIME, old);
-
-    (*env)->ReleaseStringUTFChars(env, jlangtag, langtag);
-
-    return (*env)->NewStringUTF(env, ret);
-}
--- a/src/windows/native/java/lang/java_props_md.c	Thu Feb 06 11:01:27 2014 -0500
+++ b/src/windows/native/java/lang/java_props_md.c	Thu Feb 06 10:06:09 2014 -0800
@@ -28,6 +28,9 @@
 #define _WIN32_WINNT 0x0601
 #endif
 
+#include "jni.h"
+#include "jni_util.h"
+
 #include <windows.h>
 #include <shlobj.h>
 #include <objidl.h>
@@ -51,7 +54,7 @@
 #endif
 
 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
-static void SetupI18nProps(LCID lcid, char** language, char** script, char** country,
+static boolean SetupI18nProps(LCID lcid, char** language, char** script, char** country,
                char** variant, char** encoding);
 
 #define PROPSIZE 9      // eight-letter + null terminator
@@ -60,8 +63,11 @@
 static char *
 getEncodingInternal(LCID lcid)
 {
+    int codepage;
     char * ret = malloc(16);
-    int codepage;
+    if (ret == NULL) {
+        return NULL;
+    }
 
     if (GetLocaleInfo(lcid,
                       LOCALE_IDEFAULTANSICODEPAGE,
@@ -132,7 +138,11 @@
 static char* getConsoleEncoding()
 {
     char* buf = malloc(16);
-    int cp = GetConsoleCP();
+    int cp;
+    if (buf == NULL) {
+        return NULL;
+    }
+    cp = GetConsoleCP();
     if (cp >= 874 && cp <= 950)
         sprintf(buf, "ms%d", cp);
     else
@@ -152,25 +162,33 @@
 getJavaIDFromLangID(LANGID langID)
 {
     char * elems[5]; // lang, script, ctry, variant, encoding
-    char * ret = malloc(SNAMESIZE);
+    char * ret;
     int index;
 
-    SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
-                   &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]));
-
-    // there always is the "language" tag
-    strcpy(ret, elems[0]);
-
-    // append other elements, if any
-    for (index = 1; index < 4; index++) {
-        if ((elems[index])[0] != '\0') {
-            strcat(ret, "-");
-            strcat(ret, elems[index]);
-        }
+    ret = malloc(SNAMESIZE);
+    if (ret == NULL) {
+        return NULL;
     }
 
-    for (index = 0; index < 5; index++) {
-        free(elems[index]);
+    if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
+                   &(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
+
+        // there always is the "language" tag
+        strcpy(ret, elems[0]);
+
+        // append other elements, if any
+        for (index = 1; index < 4; index++) {
+            if ((elems[index])[0] != '\0') {
+                strcat(ret, "-");
+                strcat(ret, elems[index]);
+            }
+        }
+
+        for (index = 0; index < 5; index++) {
+            free(elems[index]);
+        }
+    } else {
+        ret = NULL;
     }
 
     return ret;
@@ -259,12 +277,15 @@
     return NULL;
 }
 
-static void
+static boolean
 SetupI18nProps(LCID lcid, char** language, char** script, char** country,
                char** variant, char** encoding) {
     /* script */
     char tmp[SNAMESIZE];
     *script = malloc(PROPSIZE);
+    if (*script == NULL) {
+        return FALSE;
+    }
     if (GetLocaleInfo(lcid,
                       LOCALE_SNAME, tmp, SNAMESIZE) == 0 ||
         sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 ||
@@ -274,6 +295,9 @@
 
     /* country */
     *country = malloc(PROPSIZE);
+    if (*country == NULL) {
+        return FALSE;
+    }
     if (GetLocaleInfo(lcid,
                       LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 &&
         GetLocaleInfo(lcid,
@@ -283,6 +307,9 @@
 
     /* language */
     *language = malloc(PROPSIZE);
+    if (*language == NULL) {
+        return FALSE;
+    }
     if (GetLocaleInfo(lcid,
                       LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 &&
         GetLocaleInfo(lcid,
@@ -294,6 +321,9 @@
 
     /* variant */
     *variant = malloc(PROPSIZE);
+    if (*variant == NULL) {
+        return FALSE;
+    }
     (*variant)[0] = '\0';
 
     /* handling for Norwegian */
@@ -308,6 +338,10 @@
 
     /* encoding */
     *encoding = getEncodingInternal(lcid);
+    if (*encoding == NULL) {
+        return FALSE;
+    }
+    return TRUE;
 }
 
 java_props_t *
--- a/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Thu Feb 06 11:01:27 2014 -0500
+++ b/src/windows/native/sun/util/locale/provider/HostLocaleProviderAdapter_md.c	Thu Feb 06 10:06:09 2014 -0800
@@ -24,6 +24,7 @@
  */
 
 #include "sun_util_locale_provider_HostLocaleProviderAdapterImpl.h"
+#include "jni_util.h"
 #include <windows.h>
 #include <gdefs.h>
 #include <stdlib.h>
@@ -197,8 +198,13 @@
     }
 
     localeString = (char *)getJavaIDFromLangID(langid);
-    ret = (*env)->NewStringUTF(env, localeString);
-    free(localeString);
+    if (localeString != NULL) {
+        ret = (*env)->NewStringUTF(env, localeString);
+        free(localeString);
+    } else {
+        JNU_ThrowOutOfMemoryError(env, "memory allocation error");
+        ret = NULL;
+    }
     return ret;
 }
 
@@ -211,6 +217,7 @@
   (JNIEnv *env, jclass cls, jint dateStyle, jint timeStyle, jstring jlangtag) {
     WCHAR pattern[BUFLEN];
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, NULL);
 
     pattern[0] = L'\0';
 
@@ -238,8 +245,11 @@
  */
 JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarID
   (JNIEnv *env, jclass cls, jstring jlangtag) {
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    jint ret = getCalendarID(langtag);
+    const jchar *langtag;
+    jint ret;
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, 0);
+    ret = getCalendarID(langtag);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
     return ret;
 }
@@ -252,10 +262,13 @@
 JNIEXPORT jobjectArray JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getAmPmStrings
   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray ampms) {
     WCHAR buf[BUFLEN];
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    const jchar *langtag;
 
     // AM
-    int got = getLocaleInfoWrapper(langtag, LOCALE_S1159, buf, BUFLEN);
+    int got;
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, NULL);
+    got = getLocaleInfoWrapper(langtag, LOCALE_S1159, buf, BUFLEN);
     if (got) {
         (*env)->SetObjectArrayElement(env, ampms, 0, (*env)->NewString(env, buf, wcslen(buf)));
     }
@@ -280,6 +293,7 @@
   (JNIEnv *env, jclass cls, jstring jlangtag, jobjectArray eras) {
     WCHAR ad[BUFLEN];
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, eras);
 
     getCalendarInfoWrapper(langtag, getCalendarID(langtag), NULL,
                       CAL_SERASTRING, ad, BUFLEN, NULL);
@@ -347,10 +361,14 @@
  */
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNumberPattern
   (JNIEnv *env, jclass cls, jint numberStyle, jstring jlangtag) {
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    const jchar *langtag;
     jstring ret;
+    WCHAR * pattern;
 
-    WCHAR * pattern = getNumberPattern(langtag, numberStyle);
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, NULL);
+    pattern = getNumberPattern(langtag, numberStyle);
+    CHECK_NULL_RETURN(pattern, NULL);
 
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
     ret = (*env)->NewString(env, pattern, wcslen(pattern));
@@ -367,8 +385,10 @@
 JNIEXPORT jboolean JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_isNativeDigit
   (JNIEnv *env, jclass cls, jstring jlangtag) {
     DWORD num;
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag,
+    CHECK_NULL_RETURN(langtag, JNI_FALSE);
+    got = getLocaleInfoWrapper(langtag,
         LOCALE_IDIGITSUBSTITUTION | LOCALE_RETURN_NUMBER,
         (LPWSTR)&num, sizeof(num));
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
@@ -384,8 +404,10 @@
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCurrencySymbol
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring currencySymbol) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SCURRENCY, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, currencySymbol);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SCURRENCY, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -403,8 +425,10 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getDecimalSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar decimalSeparator) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SDECIMAL, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, decimalSeparator);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SDECIMAL, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -422,8 +446,10 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getGroupingSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar groupingSeparator) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_STHOUSAND, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, groupingSeparator);
+    got = getLocaleInfoWrapper(langtag, LOCALE_STHOUSAND, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -441,8 +467,10 @@
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInfinity
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring infinity) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SPOSINFINITY, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, infinity);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SPOSINFINITY, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -460,8 +488,10 @@
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getInternationalCurrencySymbol
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring internationalCurrencySymbol) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SINTLSYMBOL, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, internationalCurrencySymbol);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SINTLSYMBOL, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -479,8 +509,10 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMinusSign
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar minusSign) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SNEGATIVESIGN, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, minusSign);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SNEGATIVESIGN, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -498,8 +530,10 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getMonetaryDecimalSeparator
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar monetaryDecimalSeparator) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SMONDECIMALSEP, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, monetaryDecimalSeparator);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SMONDECIMALSEP, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -517,8 +551,10 @@
 JNIEXPORT jstring JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getNaN
   (JNIEnv *env, jclass cls, jstring jlangtag, jstring nan) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SNAN, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, nan);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SNAN, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -536,8 +572,10 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPercent
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar percent) {
     WCHAR buf[BUFLEN];
+    int got;
     const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SPERCENT, buf, BUFLEN);
+    CHECK_NULL_RETURN(langtag, percent);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SPERCENT, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -555,8 +593,12 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getPerMill
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar perMill) {
     WCHAR buf[BUFLEN];
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SPERMILLE, buf, BUFLEN);
+    const jchar *langtag;
+    int got;
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, perMill);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SPERMILLE, buf, BUFLEN);
+
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -574,8 +616,12 @@
 JNIEXPORT jchar JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getZeroDigit
   (JNIEnv *env, jclass cls, jstring jlangtag, jchar zeroDigit) {
     WCHAR buf[BUFLEN];
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int got = getLocaleInfoWrapper(langtag, LOCALE_SNATIVEDIGITS, buf, BUFLEN);
+    const jchar *langtag;
+    int got;
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, zeroDigit);
+    got = getLocaleInfoWrapper(langtag, LOCALE_SNATIVEDIGITS, buf, BUFLEN);
+
     (*env)->ReleaseStringChars(env, jlangtag, langtag);
 
     if (got) {
@@ -593,9 +639,11 @@
 JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterImpl_getCalendarDataValue
   (JNIEnv *env, jclass cls, jstring jlangtag, jint type) {
     DWORD num;
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    const jchar *langtag;
     int got = 0;
 
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL_RETURN(langtag, -1);
     switch (type) {
     case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_FIRSTDAYOFWEEK:
         got = getLocaleInfoWrapper(langtag,
@@ -648,6 +696,7 @@
     }
 
     pjChar = (*env)->GetStringChars(env, jStr, JNI_FALSE);
+    CHECK_NULL_RETURN(pjChar, NULL);
     got = getLocaleInfoWrapper(pjChar, lcType, buf, BUFLEN);
     (*env)->ReleaseStringChars(env, jStr, pjChar);
 
@@ -705,8 +754,11 @@
 
 void replaceCalendarArrayElems(JNIEnv *env, jstring jlangtag, jobjectArray jarray, CALTYPE* pCalTypes, int offset, int length) {
     WCHAR name[BUFLEN];
-    const jchar *langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
-    int calid = getCalendarID(langtag);
+    const jchar *langtag;
+    int calid;
+    langtag = (*env)->GetStringChars(env, jlangtag, JNI_FALSE);
+    CHECK_NULL(langtag);
+    calid = getCalendarID(langtag);
 
     if (calid != -1) {
         int i;