8034182: Misc. warnings in java.net code
Reviewed-by: chegar
--- a/jdk/src/share/native/java/net/net_util.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/share/native/java/net/net_util.c Tue Feb 11 16:43:57 2014 +0000
@@ -108,7 +108,7 @@
return (*env)->GetObjectField(env, holder, ia6_scopeifnameID);
}
-int setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) {
+jboolean setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
CHECK_NULL_RETURN(holder, JNI_FALSE);
(*env)->SetObjectField(env, holder, ia6_scopeifnameID, scopeifname);
@@ -127,20 +127,18 @@
return (*env)->GetIntField(env, holder, ia6_scopeidID);
}
-int setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) {
+jboolean setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
CHECK_NULL_RETURN(holder, JNI_FALSE);
(*env)->SetIntField(env, holder, ia6_scopeidID, scopeid);
if (scopeid > 0) {
- (*env)->SetBooleanField(env, holder, ia6_scopeidsetID, JNI_TRUE);
+ (*env)->SetBooleanField(env, holder, ia6_scopeidsetID, JNI_TRUE);
}
return JNI_TRUE;
}
-
-int getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) {
+jboolean getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) {
jobject holder, addr;
- jbyteArray barr;
holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
CHECK_NULL_RETURN(holder, JNI_FALSE);
@@ -150,7 +148,7 @@
return JNI_TRUE;
}
-int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) {
+jboolean setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) {
jobject holder;
jbyteArray addr;
@@ -201,7 +199,6 @@
jobject iaObj;
#ifdef AF_INET6
if (him->sa_family == AF_INET6) {
- jbyteArray ipaddress;
#ifdef WIN32
struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
#else
@@ -217,11 +214,12 @@
setInetAddress_family(env, iaObj, IPv4);
} else {
jint scope;
- int ret;
+ jboolean ret;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
CHECK_NULL_RETURN(iaObj, NULL);
ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
- CHECK_NULL_RETURN(ret, NULL);
+ if (ret == JNI_FALSE)
+ return NULL;
setInetAddress_family(env, iaObj, IPv6);
scope = getScopeID(him);
setInet6Address_scopeid(env, iaObj, scope);
@@ -268,7 +266,6 @@
return JNI_FALSE;
}
} else {
- jbyteArray ipaddress;
jbyte caddrCur[16];
int scope;
--- a/jdk/src/share/native/java/net/net_util.h Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/share/native/java/net/net_util.h Tue Feb 11 16:43:57 2014 +0000
@@ -63,12 +63,12 @@
* get_ methods that return objects return NULL on error.
*/
extern jobject getInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj);
-extern int setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname);
+extern jboolean setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname);
extern int getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj);
extern int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj);
-extern int setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid);
-extern int getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest);
-extern int setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address);
+extern jboolean setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid);
+extern jboolean getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest);
+extern jboolean setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address);
extern void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address);
extern void setInetAddress_family(JNIEnv *env, jobject iaObj, int family);
--- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c Tue Feb 11 16:43:57 2014 +0000
@@ -66,27 +66,27 @@
*/
JNIEXPORT jstring JNICALL
Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
+ int ret;
char hostname[NI_MAXHOST+1];
hostname[0] = '\0';
- if (JVM_GetHostName(hostname, sizeof(hostname))) {
+ ret = JVM_GetHostName(hostname, sizeof(hostname));
+ if (ret) {
/* Something went wrong, maybe networking is not setup? */
strcpy(hostname, "localhost");
} else {
// ensure null-terminated
hostname[NI_MAXHOST] = '\0';
-#if defined(__linux__) || defined(_ALLBSD_SOURCE)
- /* On Linux/FreeBSD gethostname() says "host.domain.sun.com". On
- * Solaris gethostname() says "host", so extra work is needed.
- */
-#else
+ }
+
+#if defined(__solaris__) && defined(AF_INET6)
+ if (ret == 0) {
/* Solaris doesn't want to give us a fully qualified domain name.
* We do a reverse lookup to try and get one. This works
* if DNS occurs before NIS in /etc/resolv.conf, but fails
* if NIS comes first (it still gets only a partial name).
* We use thread-safe system calls.
*/
-#ifdef AF_INET6
struct addrinfo hints, *res;
int error;
@@ -111,9 +111,9 @@
freeaddrinfo(res);
}
-#endif /* AF_INET6 */
-#endif /* __linux__ || _ALLBSD_SOURCE */
}
+#endif
+
return (*env)->NewStringUTF(env, hostname);
}
@@ -402,7 +402,7 @@
}
while (iterator != NULL) {
- int ret1;
+ jboolean ret1;
if (iterator->ai_family == AF_INET) {
jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
if (IS_NULL(iaObj)) {
@@ -422,7 +422,7 @@
goto cleanupAndReturn;
}
ret1 = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr));
- if (!ret1) {
+ if (ret1 == JNI_FALSE) {
ret = NULL;
goto cleanupAndReturn;
}
--- a/jdk/src/solaris/native/java/net/NetworkInterface.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c Tue Feb 11 16:43:57 2014 +0000
@@ -677,7 +677,7 @@
int scope=0;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (iaObj) {
- int ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
+ jboolean ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
if (ret == JNI_FALSE) {
return NULL;
}
--- a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c Tue Feb 11 16:43:57 2014 +0000
@@ -2159,7 +2159,7 @@
caddr[14] = ((address >> 8) & 0xff);
caddr[15] = (address & 0xff);
} else {
- getInet6Address_ipaddress(env, iaObj, caddr);
+ getInet6Address_ipaddress(env, iaObj, (char*)caddr);
}
memcpy((void *)&(mname6.ipv6mr_multiaddr), caddr, sizeof(struct in6_addr));
--- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c Tue Feb 11 16:43:57 2014 +0000
@@ -221,14 +221,14 @@
(*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
inetIndex ++;
} else if (iterator->ai_family == AF_INET6) {
- jint scope = 0, ret1;
+ jint scope = 0;
+ jboolean ret1;
jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (IS_NULL(iaObj)) {
ret = NULL;
goto cleanupAndReturn;
}
ret1 = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr));
-
if (ret1 == JNI_FALSE) {
ret = NULL;
goto cleanupAndReturn;
--- a/jdk/src/windows/native/java/net/NetworkInterface.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/windows/native/java/net/NetworkInterface.c Tue Feb 11 16:43:57 2014 +0000
@@ -614,7 +614,7 @@
int scope;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (iaObj) {
- int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
+ jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
if (ret == JNI_FALSE) {
return NULL;
}
--- a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c Tue Feb 11 16:43:57 2014 +0000
@@ -549,7 +549,7 @@
int scope;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
if (iaObj) {
- int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
+ jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
if (ret == JNI_FALSE) {
return NULL;
}
--- a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Tue Feb 11 16:43:57 2014 +0000
@@ -1646,6 +1646,7 @@
}
static int isAdapterIpv6Enabled(JNIEnv *env, int index) {
+ extern int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP);
netif *ifList, *curr;
int ipv6Enabled = 0;
if (getAllInterfacesAndAddresses (env, &ifList) < 0) {
--- a/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Tue Feb 11 14:48:51 2014 +0100
+++ b/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Tue Feb 11 16:43:57 2014 +0000
@@ -575,7 +575,6 @@
{
/* fields on this */
jint port;
- jint scope;
jint timeout = (*env)->GetIntField(env, this, psi_timeoutID);
jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
@@ -750,7 +749,7 @@
NET_SocketClose(fd);
return;
}
- setInet6Address_ipaddress(env, socketAddressObj, (const char *)&him.him6.sin6_addr);
+ setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.him6.sin6_addr);
setInetAddress_family(env, socketAddressObj, IPv6);
setInet6Address_scopeid(env, socketAddressObj, him.him6.sin6_scope_id);