changeset 4645:a301b69dfdc3

7125722: [macosx] 7u4 b200 crash i.e. in Tonga Reviewed-by: alanb, dcubed
author michaelm
date Tue, 03 Jan 2012 13:43:05 -0800
parents ab26116ef4fc
children 15b5f3ec1c55
files src/solaris/native/java/net/net_util_md.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/net/net_util_md.c	Sat Dec 31 14:00:08 2011 +0800
+++ b/src/solaris/native/java/net/net_util_md.c	Tue Jan 03 13:43:05 2012 -0800
@@ -85,12 +85,20 @@
 #define UDP_EXCLBIND            0x0101
 #endif
 
-extern jclass ni_class;
-extern jfieldID ni_defaultIndexID;
-
 void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
 {
 #ifdef MACOSX
+    static jclass ni_class = NULL;
+    static jfieldID ni_defaultIndexID;
+    if (ni_class == NULL) {
+        jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+        CHECK_NULL(c);
+        c = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(c);
+        ni_defaultIndexID = (*env)->GetStaticFieldID(
+            env, c, "defaultIndex", "I");
+        ni_class = c;
+    }
     int defaultIndex;
     struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)him;
     if (sin6->sin6_family == AF_INET6 && (sin6->sin6_scope_id == 0)) {