mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-29 08:05:14 +00:00
8359268: 3 JNI exception pending defect groups in 2 files
Reviewed-by: dfuchs, djelinski Backport-of: 1fa090524a7c3bb5f2c92fb0f7217b9277ade9d9
This commit is contained in:
parent
fdb3e37c71
commit
a84946dde4
@ -91,14 +91,7 @@ DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
}
|
||||
|
||||
static int enhancedExceptionsInitialized = 0;
|
||||
static int enhancedExceptionsAllowed = -1;
|
||||
|
||||
#define CHECK_NULL_THROW_ERROR(X) \
|
||||
if (X == NULL) { \
|
||||
JNU_ThrowByName(env, "java/lang/InternalError", \
|
||||
"can't initialize enhanced exceptions"); \
|
||||
return -1; \
|
||||
}
|
||||
static int enhancedExceptionsAllowed = 0;
|
||||
|
||||
int getEnhancedExceptionsAllowed(JNIEnv *env) {
|
||||
jclass cls;
|
||||
@ -108,9 +101,9 @@ int getEnhancedExceptionsAllowed(JNIEnv *env) {
|
||||
return enhancedExceptionsAllowed;
|
||||
}
|
||||
cls = (*env)->FindClass(env, "jdk/internal/util/Exceptions");
|
||||
CHECK_NULL_THROW_ERROR(cls);
|
||||
CHECK_NULL_RETURN(cls, ENH_INIT_ERROR);
|
||||
fid = (*env)->GetStaticFieldID(env, cls, "enhancedNonSocketExceptionText", "Z");
|
||||
CHECK_NULL_THROW_ERROR(fid);
|
||||
CHECK_NULL_RETURN(fid, ENH_INIT_ERROR);
|
||||
enhancedExceptionsAllowed = (*env)->GetStaticBooleanField(env, cls, fid);
|
||||
enhancedExceptionsInitialized = 1;
|
||||
return enhancedExceptionsAllowed;
|
||||
|
||||
@ -183,6 +183,11 @@ int lookupCharacteristicsToAddressFamily(int characteristics);
|
||||
|
||||
int addressesInSystemOrder(int characteristics);
|
||||
|
||||
/* return codes */
|
||||
#define ENH_INIT_ERROR -1 /* initialization error: check exceptions */
|
||||
#define ENH_DISABLED 0 /* enhanced exceptions disabled */
|
||||
#define ENH_ENABLED 1 /* enhanced exceptions enabled */
|
||||
|
||||
int getEnhancedExceptionsAllowed(JNIEnv *env);
|
||||
|
||||
#endif /* NET_UTILS_H */
|
||||
|
||||
@ -188,8 +188,11 @@ void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
|
||||
if (error_string == NULL)
|
||||
error_string = "unknown error";
|
||||
int enhancedExceptions = getEnhancedExceptionsAllowed(env);
|
||||
if (enhancedExceptions == ENH_INIT_ERROR && (*env)->ExceptionCheck(env)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enhancedExceptions) {
|
||||
if (enhancedExceptions == ENH_ENABLED) {
|
||||
size = strlen(hostname);
|
||||
} else {
|
||||
size = 0;
|
||||
@ -200,7 +203,7 @@ void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
|
||||
if (buf) {
|
||||
jstring s;
|
||||
int n;
|
||||
if (enhancedExceptions) {
|
||||
if (enhancedExceptions == ENH_ENABLED) {
|
||||
n = snprintf(buf, size, "%s: %s", hostname, error_string);
|
||||
} else {
|
||||
n = snprintf(buf, size, " %s", error_string);
|
||||
|
||||
@ -88,9 +88,12 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
|
||||
if (error) {
|
||||
// report error
|
||||
NET_ThrowByNameWithLastError(
|
||||
env, "java/net/UnknownHostException",
|
||||
getEnhancedExceptionsAllowed(env) ? hostname : "");
|
||||
int enh = getEnhancedExceptionsAllowed(env);
|
||||
if (enh == ENH_INIT_ERROR && (*env)->ExceptionCheck(env)) {
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
const char *hmsg = (enh == ENH_ENABLED) ? hostname : "";
|
||||
NET_ThrowByNameWithLastError( env, "java/net/UnknownHostException", hmsg);
|
||||
goto cleanupAndReturn;
|
||||
} else {
|
||||
int i = 0;
|
||||
|
||||
@ -83,8 +83,12 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
|
||||
if (error) {
|
||||
// report error
|
||||
NET_ThrowByNameWithLastError(env, "java/net/UnknownHostException",
|
||||
getEnhancedExceptionsAllowed(env) ? hostname : "");
|
||||
int enh = getEnhancedExceptionsAllowed(env);
|
||||
if (enh == ENH_INIT_ERROR && (*env)->ExceptionCheck(env)) {
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
const char *hmsg = (enh == ENH_ENABLED) ? hostname : "";
|
||||
NET_ThrowByNameWithLastError(env, "java/net/UnknownHostException", hmsg);
|
||||
goto cleanupAndReturn;
|
||||
} else {
|
||||
int i = 0, inetCount = 0, inet6Count = 0, inetIndex = 0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user