8027961: Inet[4|6]Address native initializing code should check field/MethodID values
Reviewed-by: michaelm, rriggs
diff --git a/src/share/native/java/net/Inet4Address.c b/src/share/native/java/net/Inet4Address.c
index 2030471..b2f2541 100644
--- a/src/share/native/java/net/Inet4Address.c
+++ b/src/share/native/java/net/Inet4Address.c
@@ -46,5 +46,4 @@
ia4_class = (*env)->NewGlobalRef(env, c);
CHECK_NULL(ia4_class);
ia4_ctrID = (*env)->GetMethodID(env, ia4_class, "<init>", "()V");
- CHECK_NULL(ia4_ctrID);
}
diff --git a/src/share/native/java/net/Inet6Address.c b/src/share/native/java/net/Inet6Address.c
index 54c4149..729fe78 100644
--- a/src/share/native/java/net/Inet6Address.c
+++ b/src/share/native/java/net/Inet6Address.c
@@ -65,9 +65,8 @@
ia6_cachedscopeidID = (*env)->GetFieldID(env, ia6_class, "cached_scope_id", "I");
CHECK_NULL(ia6_cachedscopeidID);
ia6_scopeidsetID = (*env)->GetFieldID(env, ia6h_class, "scope_id_set", "Z");
- CHECK_NULL(ia6_scopeidID);
+ CHECK_NULL(ia6_scopeidsetID);
ia6_scopeifnameID = (*env)->GetFieldID(env, ia6h_class, "scope_ifname", "Ljava/net/NetworkInterface;");
CHECK_NULL(ia6_scopeifnameID);
ia6_ctrID = (*env)->GetMethodID(env, ia6_class, "<init>", "()V");
- CHECK_NULL(ia6_ctrID);
}
diff --git a/src/share/native/java/net/InetAddress.c b/src/share/native/java/net/InetAddress.c
index 3111573..e9fd097 100644
--- a/src/share/native/java/net/InetAddress.c
+++ b/src/share/native/java/net/InetAddress.c
@@ -64,5 +64,4 @@
iac_familyID = (*env)->GetFieldID(env, iac_class, "family", "I");
CHECK_NULL(iac_familyID);
iac_hostNameID = (*env)->GetFieldID(env, iac_class, "hostName", "Ljava/lang/String;");
- CHECK_NULL(iac_hostNameID);
}
diff --git a/src/solaris/native/java/net/Inet4AddressImpl.c b/src/solaris/native/java/net/Inet4AddressImpl.c
index 6ef0aca..ea67245 100644
--- a/src/solaris/native/java/net/Inet4AddressImpl.c
+++ b/src/solaris/native/java/net/Inet4AddressImpl.c
@@ -55,17 +55,23 @@
static jclass ni_ia4cls;
static jmethodID ni_ia4ctrID;
-static void initializeInetClasses(JNIEnv *env)
+static jboolean initializeInetClasses(JNIEnv *env)
{
static int initialized = 0;
if (!initialized) {
ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
+ CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
+ CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
+ CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
+ CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
+ CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE);
initialized = 1;
}
+ return JNI_TRUE;
}
@@ -141,7 +147,8 @@
int error=0;
struct addrinfo hints, *res, *resNew = NULL;
- initializeInetClasses(env);
+ if (!initializeInetClasses(env))
+ return NULL;
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
@@ -400,7 +407,8 @@
int error = 0;
struct addrinfo hints, *res, *resNew = NULL;
- initializeInetClasses(env);
+ if (!initializeInetClasses(env))
+ return NULL;
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
diff --git a/src/solaris/native/java/net/Inet6AddressImpl.c b/src/solaris/native/java/net/Inet6AddressImpl.c
index d83db70..7ac26c0 100644
--- a/src/solaris/native/java/net/Inet6AddressImpl.c
+++ b/src/solaris/native/java/net/Inet6AddressImpl.c
@@ -124,25 +124,35 @@
static jmethodID ni_ia6ctrID;
static jboolean preferIPv6Address;
-static void initializeInetClasses(JNIEnv *env)
+static jboolean initializeInetClasses(JNIEnv *env)
{
jfieldID ni_preferIPv6AddressID;
static int initialized = 0;
if (!initialized) {
ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
+ CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
+ CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
+ CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
+ CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
+ CHECK_NULL_RETURN(ni_ia6cls, JNI_FALSE);
ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
+ CHECK_NULL_RETURN(ni_ia6cls, JNI_FALSE);
ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
+ CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE);
ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
+ CHECK_NULL_RETURN(ni_ia6ctrID, JNI_FALSE);
ni_preferIPv6AddressID =
(*env)->GetStaticFieldID(env, ni_iacls, "preferIPv6Address", "Z");
+ CHECK_NULL_RETURN(ni_preferIPv6AddressID, JNI_FALSE);
preferIPv6Address =
(*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
initialized = 1;
}
+ return JNI_TRUE;
}
#ifdef MACOSX
@@ -160,7 +170,8 @@
jobject name;
// Make sure static variables we need are set.
- initializeInetClasses(env);
+ if (!initializeInetClasses(env))
+ return NULL;
/* If the requested name matches this host's hostname, return IP addresses
* from all attached interfaces. (#2844683 et al) This prevents undesired
@@ -286,7 +297,8 @@
struct addrinfo hints, *res, *resNew = NULL;
#endif /* AF_INET6 */
- initializeInetClasses(env);
+ if (!initializeInetClasses(env))
+ return NULL;
if (IS_NULL(host)) {
JNU_ThrowNullPointerException(env, "host is null");
diff --git a/src/windows/native/java/net/Inet4AddressImpl.c b/src/windows/native/java/net/Inet4AddressImpl.c
index 97aab6f..f34b5e1 100644
--- a/src/windows/native/java/net/Inet4AddressImpl.c
+++ b/src/windows/native/java/net/Inet4AddressImpl.c
@@ -142,10 +142,15 @@
if (!initialized) {
ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
+ CHECK_NULL_RETURN(ni_iacls, NULL);
ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
+ CHECK_NULL_RETURN(ni_iacls, NULL);
ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
+ CHECK_NULL_RETURN(ni_ia4cls, NULL);
ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
+ CHECK_NULL_RETURN(ni_ia4cls, NULL);
ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
+ CHECK_NULL_RETURN(ni_ia4ctrID, NULL);
initialized = 1;
}
diff --git a/src/windows/native/java/net/Inet6AddressImpl.c b/src/windows/native/java/net/Inet6AddressImpl.c
index 4531402..f77d5ab 100644
--- a/src/windows/native/java/net/Inet6AddressImpl.c
+++ b/src/windows/native/java/net/Inet6AddressImpl.c
@@ -93,13 +93,21 @@
if (!initialized) {
ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
+ CHECK_NULL_RETURN(ni_iacls, NULL);
ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
+ CHECK_NULL_RETURN(ni_iacls, NULL);
ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
+ CHECK_NULL_RETURN(ni_ia4cls, NULL);
ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
+ CHECK_NULL_RETURN(ni_ia4cls, NULL);
ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
+ CHECK_NULL_RETURN(ni_ia6cls, NULL);
ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
+ CHECK_NULL_RETURN(ni_ia6cls, NULL);
ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
+ CHECK_NULL_RETURN(ni_ia4ctrID, NULL);
ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
+ CHECK_NULL_RETURN(ni_ia6ctrID, NULL);
initialized = 1;
}
if (IS_NULL(host)) {