From f2e8ba353cdd69944828beca10f8da071df8a909 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 12 Jun 2008 17:25:37 +0100 Subject: [PATCH] 6698625: InetAddress.getLocalHost() failed in returning chinese local host name Remove unnecessary and incorrect NewStringUTF Reviewed-by: michaelm --- jdk/src/solaris/native/java/net/Inet4AddressImpl.c | 9 +-------- jdk/src/solaris/native/java/net/Inet6AddressImpl.c | 10 ++-------- jdk/src/windows/native/java/net/Inet4AddressImpl.c | 7 +------ jdk/src/windows/native/java/net/Inet6AddressImpl.c | 11 ++--------- 4 files changed, 6 insertions(+), 31 deletions(-) diff --git a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c index 7821b0bda33..28b3a8ea897 100644 --- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c +++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c @@ -138,7 +138,6 @@ JNIEXPORT jobjectArray JNICALL Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, jstring host) { const char *hostname; - jobject name; jobjectArray ret = 0; struct hostent res, *hp = 0; char buf[HENT_BUF_SIZE]; @@ -210,12 +209,6 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, addrp++; } - name = (*env)->NewStringUTF(env, hostname); - - if (IS_NULL(name)) { - goto cleanupAndReturn; - } - ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL); if (IS_NULL(ret)) { /* we may have memory to free at the end of this */ @@ -231,7 +224,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } (*env)->SetIntField(env, iaObj, ni_iaaddressID, ntohl((*addrp)->s_addr)); - (*env)->SetObjectField(env, iaObj, ni_iahostID, name); + (*env)->SetObjectField(env, iaObj, ni_iahostID, host); (*env)->SetObjectArrayElement(env, ret, i, iaObj); addrp++; i++; diff --git a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c index 827f00bad5d..672eaad2e70 100644 --- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c @@ -142,7 +142,6 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, jstring host) { const char *hostname; jobjectArray ret = 0; - jobject name; int retLen = 0; jclass byteArrayCls; jboolean preferIPv6Address; @@ -310,11 +309,6 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, inet6Index = inetCount; } - name = (*env)->NewStringUTF(env, hostname); - if (IS_NULL(name)) { - ret = NULL; - goto cleanupAndReturn; - } while (iterator != NULL) { if (iterator->ai_family == AF_INET) { jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); @@ -324,7 +318,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } (*env)->SetIntField(env, iaObj, ni_iaaddressID, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr)); - (*env)->SetObjectField(env, iaObj, ni_iahostID, name); + (*env)->SetObjectField(env, iaObj, ni_iahostID, host); (*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj); inetIndex++; } else if (iterator->ai_family == AF_INET6) { @@ -355,7 +349,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE); } (*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress); - (*env)->SetObjectField(env, iaObj, ni_iahostID, name); + (*env)->SetObjectField(env, iaObj, ni_iahostID, host); (*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj); inet6Index++; } diff --git a/jdk/src/windows/native/java/net/Inet4AddressImpl.c b/jdk/src/windows/native/java/net/Inet4AddressImpl.c index 149827f59c5..53f44770800 100644 --- a/jdk/src/windows/native/java/net/Inet4AddressImpl.c +++ b/jdk/src/windows/native/java/net/Inet4AddressImpl.c @@ -137,7 +137,6 @@ JNIEXPORT jobjectArray JNICALL Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, jstring host) { const char *hostname; - jobject name; struct hostent *hp; unsigned int addr[4]; @@ -229,10 +228,6 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, addrp++; } - name = (*env)->NewStringUTF(env, hostname); - if (IS_NULL(name)) { - goto cleanupAndReturn; - } ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL); if (IS_NULL(ret)) { @@ -249,7 +244,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } (*env)->SetIntField(env, iaObj, ni_iaaddressID, ntohl((*addrp)->s_addr)); - (*env)->SetObjectField(env, iaObj, ni_iahostID, name); + (*env)->SetObjectField(env, iaObj, ni_iahostID, host); (*env)->SetObjectArrayElement(env, ret, i, iaObj); addrp++; i++; diff --git a/jdk/src/windows/native/java/net/Inet6AddressImpl.c b/jdk/src/windows/native/java/net/Inet6AddressImpl.c index 31bd3e68e88..8f34ea92d8a 100644 --- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c +++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c @@ -86,7 +86,6 @@ JNIEXPORT jobjectArray JNICALL Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, jstring host) { const char *hostname; - jobject name; jobjectArray ret = 0; int retLen = 0; jboolean preferIPv6Address; @@ -237,12 +236,6 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, inet6Index = inetCount; } - name = (*env)->NewStringUTF(env, hostname); - if (IS_NULL(name)) { - ret = NULL; - goto cleanupAndReturn; - } - while (iterator != NULL) { if (iterator->ai_family == AF_INET) { jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID); @@ -252,7 +245,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } (*env)->SetIntField(env, iaObj, ni_iaaddressID, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr)); - (*env)->SetObjectField(env, iaObj, ni_iahostID, name); + (*env)->SetObjectField(env, iaObj, ni_iahostID, host); (*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj); inetIndex ++; } else if (iterator->ai_family == AF_INET6) { @@ -276,7 +269,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, (*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE); } (*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress); - (*env)->SetObjectField(env, iaObj, ni_iahostID, name); + (*env)->SetObjectField(env, iaObj, ni_iahostID, host); (*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj); inet6Index ++; }