From b257c944e15c5be46a69143603426c7ce137e6a3 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Tue, 15 Sep 2009 19:37:54 -0700 Subject: [PATCH] Report the cause of name lookup failures to Java land. The Java code already uses the exception thrown by getallbyname() as a chained exception. Change-Id: Ifc0d34102412ce0bf34715c9852bf751b420fb40 --- libcore/luni/src/main/native/java_net_InetAddress.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libcore/luni/src/main/native/java_net_InetAddress.cpp b/libcore/luni/src/main/native/java_net_InetAddress.cpp index 90a88ee85..d7b493171 100644 --- a/libcore/luni/src/main/native/java_net_InetAddress.cpp +++ b/libcore/luni/src/main/native/java_net_InetAddress.cpp @@ -100,7 +100,10 @@ static jobjectArray getAllByNameUsingAdb(JNIEnv* env, const char* name) env->SetByteArrayRegion(byteArray, 0, 4, (jbyte*) &outaddr.s_addr); env->SetObjectArrayElement(addressArray, 1, byteArray); } + } else { + jniThrowException(env, "java/net/UnknownHostException", "adb error"); } + return addressArray; } @@ -189,8 +192,8 @@ static jobjectArray getAllByNameUsingDns(JNIEnv* env, const char* name, env, "java/lang/SecurityException", "Permission denied (maybe missing INTERNET permission)"); } else { - // Do nothing. Return value will be null and the caller will throw an - // UnknownHostExeption. + jniThrowException(env, "java/net/UnknownHostException", + gai_strerror(result)); } if (addressList) { @@ -227,12 +230,6 @@ jobjectArray InetAddress_getallbyname(JNIEnv* env, jobject obj, out = getAllByNameUsingDns(env, name, preferIPv4Stack); } - if (!out) { -#if LOG_DNS - LOGI("Unknown host %s, throwing UnknownHostException", name); -#endif - jniThrowException(env, "java/net/UnknownHostException", name); - } env->ReleaseStringUTFChars(javaName, name); return out; } -- 2.11.0