提交 f4cb8698 编写于 作者: O okutsu

8032650: [parfait] warning from b124 for jdk/src/share/native/java/util: jni exception pending

Reviewed-by: naoto
上级 272dd1ae
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -591,8 +591,7 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -591,8 +591,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
/** /**
* Gets the platform defined TimeZone ID. * Gets the platform defined TimeZone ID.
**/ **/
private static native String getSystemTimeZoneID(String javaHome, private static native String getSystemTimeZoneID(String javaHome);
String country);
/** /**
* Gets the custom time zone ID based on the GMT offset of the * Gets the custom time zone ID based on the GMT offset of the
...@@ -650,12 +649,10 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -650,12 +649,10 @@ abstract public class TimeZone implements Serializable, Cloneable {
// if the time zone ID is not set (yet), perform the // if the time zone ID is not set (yet), perform the
// platform to Java time zone ID mapping. // platform to Java time zone ID mapping.
if (zoneID == null || zoneID.isEmpty()) { if (zoneID == null || zoneID.isEmpty()) {
String country = AccessController.doPrivileged(
new GetPropertyAction("user.country"));
String javaHome = AccessController.doPrivileged( String javaHome = AccessController.doPrivileged(
new GetPropertyAction("java.home")); new GetPropertyAction("java.home"));
try { try {
zoneID = getSystemTimeZoneID(javaHome, country); zoneID = getSystemTimeZoneID(javaHome);
if (zoneID == null) { if (zoneID == null) {
zoneID = GMT_ID; zoneID = GMT_ID;
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -38,42 +38,28 @@ ...@@ -38,42 +38,28 @@
*/ */
JNIEXPORT jstring JNICALL JNIEXPORT jstring JNICALL
Java_java_util_TimeZone_getSystemTimeZoneID(JNIEnv *env, jclass ign, 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; const char *java_home_dir;
char *javaTZ; char *javaTZ;
jstring jstrJavaTZ = NULL;
if (java_home == NULL) CHECK_NULL_RETURN(java_home, NULL);
return NULL;
java_home_dir = JNU_GetStringPlatformChars(env, java_home, 0); java_home_dir = JNU_GetStringPlatformChars(env, java_home, 0);
if (java_home_dir == NULL) CHECK_NULL_RETURN(java_home_dir, NULL);
return NULL;
if (country != NULL) {
cname = JNU_GetStringPlatformChars(env, country, 0);
/* ignore error cases for cname */
} else {
cname = NULL;
}
/* /*
* Invoke platform dependent mapping function * Invoke platform dependent mapping function
*/ */
javaTZ = findJavaTZ_md(java_home_dir, cname); javaTZ = findJavaTZ_md(java_home_dir);
free((void *)java_home_dir);
if (cname != NULL) {
free((void *)cname);
}
if (javaTZ != NULL) { if (javaTZ != NULL) {
jstring jstrJavaTZ = JNU_NewStringPlatform(env, javaTZ); jstrJavaTZ = JNU_NewStringPlatform(env, javaTZ);
free((void *)javaTZ); free((void *)javaTZ);
return jstrJavaTZ;
} }
return NULL;
JNU_ReleaseStringPlatformChars(env, java_home, java_home_dir);
return jstrJavaTZ;
} }
/* /*
......
...@@ -652,11 +652,11 @@ static char *mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz ...@@ -652,11 +652,11 @@ static char *mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz
* using <java_home>/lib/tzmappings. If the TZ value is not found, it * using <java_home>/lib/tzmappings. If the TZ value is not found, it
* trys some libc implementation dependent mappings. If it still * 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 * 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*/ /*ARGSUSED1*/
char * char *
findJavaTZ_md(const char *java_home_dir, const char *country) findJavaTZ_md(const char *java_home_dir)
{ {
char *tz; char *tz;
char *javatz = NULL; char *javatz = NULL;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#ifndef _TIMEZONE_MD_H #ifndef _TIMEZONE_MD_H
#define _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(); char *getGMTOffsetID();
#endif #endif
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -394,31 +394,34 @@ static int getWinTimeZone(char *winZoneName, char *winMapID) ...@@ -394,31 +394,34 @@ static int getWinTimeZone(char *winZoneName, char *winMapID)
* *
* value_type is one of the following values: * value_type is one of the following values:
* VALUE_KEY for exact key matching * 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). * required for the old Windows, such as NT 4.0 SP3).
*/ */
static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName, static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName,
char *mapID, const char *country) char *mapID)
{ {
int line; int line;
int IDmatched = 0; int IDmatched = 0;
FILE *fp; FILE *fp;
char *javaTZName = NULL; char *javaTZName = NULL;
char *items[TZ_NITEMS]; char *items[TZ_NITEMS];
char mapFileName[_MAX_PATH + 1]; char *mapFileName;
char lineBuffer[MAX_ZONE_CHAR * 4]; char lineBuffer[MAX_ZONE_CHAR * 4];
char bestMatch[MAX_ZONE_CHAR]; int noMapID = *mapID == '\0'; /* no mapID on Vista and later */
int noMapID = *mapID == '\0'; /* no mapID on Vista */
bestMatch[0] = '\0';
mapFileName = malloc(strlen(java_home_dir) + strlen(MAPPINGS_FILE) + 1);
if (mapFileName == NULL) {
return NULL;
}
strcpy(mapFileName, java_home_dir); strcpy(mapFileName, java_home_dir);
strcat(mapFileName, MAPPINGS_FILE); strcat(mapFileName, MAPPINGS_FILE);
if ((fp = fopen(mapFileName, "r")) == NULL) { if ((fp = fopen(mapFileName, "r")) == NULL) {
jio_fprintf(stderr, "can't open %s.\n", mapFileName); jio_fprintf(stderr, "can't open %s.\n", mapFileName);
free((void *) mapFileName);
return NULL; return NULL;
} }
free((void *) mapFileName);
line = 0; line = 0;
while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) { while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) {
...@@ -469,18 +472,6 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName ...@@ -469,18 +472,6 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName
javaTZName = _strdup(items[TZ_JAVA_NAME]); javaTZName = _strdup(items[TZ_JAVA_NAME]);
break; 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 { } else {
if (IDmatched == 1) { if (IDmatched == 1) {
/* /*
...@@ -492,9 +483,6 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName ...@@ -492,9 +483,6 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName
} }
fclose(fp); fclose(fp);
if (javaTZName == NULL && bestMatch[0] != '\0') {
javaTZName = _strdup(bestMatch);
}
return javaTZName; return javaTZName;
illegal_format: illegal_format:
...@@ -506,7 +494,7 @@ static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName ...@@ -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. * 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 winZoneName[MAX_ZONE_CHAR];
char winMapID[MAX_MAPID_LENGTH]; char winMapID[MAX_MAPID_LENGTH];
...@@ -521,7 +509,7 @@ char *findJavaTZ_md(const char *java_home_dir, const char *country) ...@@ -521,7 +509,7 @@ char *findJavaTZ_md(const char *java_home_dir, const char *country)
std_timezone = _strdup(winZoneName); std_timezone = _strdup(winZoneName);
} else { } else {
std_timezone = matchJavaTZ(java_home_dir, result, std_timezone = matchJavaTZ(java_home_dir, result,
winZoneName, winMapID, country); winZoneName, winMapID);
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#ifndef _TIMEZONE_MD_H #ifndef _TIMEZONE_MD_H
#define _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(); char *getGMTOffsetID();
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册