From f4cb8698484692e98b76c08405ea2cf1eda03197 Mon Sep 17 00:00:00 2001 From: okutsu Date: Sun, 3 Aug 2014 10:47:57 +0900 Subject: [PATCH] 8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending Reviewed-by: naoto --- src/share/classes/java/util/TimeZone.java | 9 ++--- src/share/native/java/util/TimeZone.c | 34 ++++++------------- src/solaris/native/java/util/TimeZone_md.c | 4 +-- src/solaris/native/java/util/TimeZone_md.h | 4 +-- src/windows/native/java/util/TimeZone_md.c | 38 ++++++++-------------- src/windows/native/java/util/TimeZone_md.h | 4 +-- 6 files changed, 32 insertions(+), 61 deletions(-) diff --git a/src/share/classes/java/util/TimeZone.java b/src/share/classes/java/util/TimeZone.java index 96497939f..356f33be3 100644 --- a/src/share/classes/java/util/TimeZone.java +++ b/src/share/classes/java/util/TimeZone.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, 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 @@ -591,8 +591,7 @@ abstract public class TimeZone implements Serializable, Cloneable { /** * Gets the platform defined TimeZone ID. **/ - private static native String getSystemTimeZoneID(String javaHome, - String country); + private static native String getSystemTimeZoneID(String javaHome); /** * Gets the custom time zone ID based on the GMT offset of the @@ -650,12 +649,10 @@ abstract public class TimeZone implements Serializable, Cloneable { // if the time zone ID is not set (yet), perform the // platform to Java time zone ID mapping. if (zoneID == null || zoneID.isEmpty()) { - String country = AccessController.doPrivileged( - new GetPropertyAction("user.country")); String javaHome = AccessController.doPrivileged( new GetPropertyAction("java.home")); try { - zoneID = getSystemTimeZoneID(javaHome, country); + zoneID = getSystemTimeZoneID(javaHome); if (zoneID == null) { zoneID = GMT_ID; } diff --git a/src/share/native/java/util/TimeZone.c b/src/share/native/java/util/TimeZone.c index d061b334a..95e4e0a54 100644 --- a/src/share/native/java/util/TimeZone.c +++ b/src/share/native/java/util/TimeZone.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2004, 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 @@ -38,42 +38,28 @@ */ JNIEXPORT jstring JNICALL Java_java_util_TimeZone_getSystemTimeZoneID(JNIEnv *env, jclass ign, - jstring java_home, jstring country) + jstring java_home) { - const char *cname; const char *java_home_dir; char *javaTZ; + jstring jstrJavaTZ = NULL; - if (java_home == NULL) - return NULL; + CHECK_NULL_RETURN(java_home, NULL); java_home_dir = JNU_GetStringPlatformChars(env, java_home, 0); - if (java_home_dir == NULL) - return NULL; - - if (country != NULL) { - cname = JNU_GetStringPlatformChars(env, country, 0); - /* ignore error cases for cname */ - } else { - cname = NULL; - } + CHECK_NULL_RETURN(java_home_dir, NULL); /* * Invoke platform dependent mapping function */ - javaTZ = findJavaTZ_md(java_home_dir, cname); - - free((void *)java_home_dir); - if (cname != NULL) { - free((void *)cname); - } - + javaTZ = findJavaTZ_md(java_home_dir); if (javaTZ != NULL) { - jstring jstrJavaTZ = JNU_NewStringPlatform(env, javaTZ); + jstrJavaTZ = JNU_NewStringPlatform(env, javaTZ); free((void *)javaTZ); - return jstrJavaTZ; } - return NULL; + + JNU_ReleaseStringPlatformChars(env, java_home, java_home_dir); + return jstrJavaTZ; } /* diff --git a/src/solaris/native/java/util/TimeZone_md.c b/src/solaris/native/java/util/TimeZone_md.c index c90fcee25..76c3f394b 100644 --- a/src/solaris/native/java/util/TimeZone_md.c +++ b/src/solaris/native/java/util/TimeZone_md.c @@ -652,11 +652,11 @@ static char *mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz * using /lib/tzmappings. If the TZ value is not found, it * trys some libc implementation dependent mappings. If it still * can't map to a Java time zone ID, it falls back to the GMT+/-hh:mm - * form. `country', which can be null, is not used for UNIX platforms. + * form. */ /*ARGSUSED1*/ char * -findJavaTZ_md(const char *java_home_dir, const char *country) +findJavaTZ_md(const char *java_home_dir) { char *tz; char *javatz = NULL; diff --git a/src/solaris/native/java/util/TimeZone_md.h b/src/solaris/native/java/util/TimeZone_md.h index 9d20bcaf9..99e01920f 100644 --- a/src/solaris/native/java/util/TimeZone_md.h +++ b/src/solaris/native/java/util/TimeZone_md.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2001, 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 @@ -26,7 +26,7 @@ #ifndef _TIMEZONE_MD_H #define _TIMEZONE_MD_H -char *findJavaTZ_md(const char *java_home_dir, const char *region); +char *findJavaTZ_md(const char *java_home_dir); char *getGMTOffsetID(); #endif diff --git a/src/windows/native/java/util/TimeZone_md.c b/src/windows/native/java/util/TimeZone_md.c index 57d4b526b..7cb23e098 100644 --- a/src/windows/native/java/util/TimeZone_md.c +++ b/src/windows/native/java/util/TimeZone_md.c @@ -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 @@ -394,31 +394,34 @@ static int getWinTimeZone(char *winZoneName, char *winMapID) * * value_type is one of the following values: * VALUE_KEY for exact key matching - * VALUE_MAPID for MapID and country-based mapping (this is + * VALUE_MAPID for MapID (this is * required for the old Windows, such as NT 4.0 SP3). */ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName, - char *mapID, const char *country) + char *mapID) { int line; int IDmatched = 0; FILE *fp; char *javaTZName = NULL; char *items[TZ_NITEMS]; - char mapFileName[_MAX_PATH + 1]; + char *mapFileName; char lineBuffer[MAX_ZONE_CHAR * 4]; - char bestMatch[MAX_ZONE_CHAR]; - int noMapID = *mapID == '\0'; /* no mapID on Vista */ - - bestMatch[0] = '\0'; + int noMapID = *mapID == '\0'; /* no mapID on Vista and later */ + mapFileName = malloc(strlen(java_home_dir) + strlen(MAPPINGS_FILE) + 1); + if (mapFileName == NULL) { + return NULL; + } strcpy(mapFileName, java_home_dir); strcat(mapFileName, MAPPINGS_FILE); if ((fp = fopen(mapFileName, "r")) == NULL) { jio_fprintf(stderr, "can't open %s.\n", mapFileName); + free((void *) mapFileName); return NULL; } + free((void *) mapFileName); line = 0; while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) { @@ -469,18 +472,6 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName javaTZName = _strdup(items[TZ_JAVA_NAME]); break; } - /* - * Try to find the most likely time zone. - */ - if (*items[TZ_REGION] == '\0') { - strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR); - } else if (country != NULL && strcmp(items[TZ_REGION], country) == 0) { - if (value_type == VALUE_MAPID) { - javaTZName = _strdup(items[TZ_JAVA_NAME]); - break; - } - strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR); - } } else { if (IDmatched == 1) { /* @@ -492,9 +483,6 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName } fclose(fp); - if (javaTZName == NULL && bestMatch[0] != '\0') { - javaTZName = _strdup(bestMatch); - } return javaTZName; illegal_format: @@ -506,7 +494,7 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName /* * Detects the platform time zone which maps to a Java time zone ID. */ -char *findJavaTZ_md(const char *java_home_dir, const char *country) +char *findJavaTZ_md(const char *java_home_dir) { char winZoneName[MAX_ZONE_CHAR]; char winMapID[MAX_MAPID_LENGTH]; @@ -521,7 +509,7 @@ char *findJavaTZ_md(const char *java_home_dir, const char *country) std_timezone = _strdup(winZoneName); } else { std_timezone = matchJavaTZ(java_home_dir, result, - winZoneName, winMapID, country); + winZoneName, winMapID); } } diff --git a/src/windows/native/java/util/TimeZone_md.h b/src/windows/native/java/util/TimeZone_md.h index 9d20bcaf9..99e01920f 100644 --- a/src/windows/native/java/util/TimeZone_md.h +++ b/src/windows/native/java/util/TimeZone_md.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2001, 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 @@ -26,7 +26,7 @@ #ifndef _TIMEZONE_MD_H #define _TIMEZONE_MD_H -char *findJavaTZ_md(const char *java_home_dir, const char *region); +char *findJavaTZ_md(const char *java_home_dir); char *getGMTOffsetID(); #endif -- GitLab