-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8275319 java.net.NetworkInterface throws java.lang.Error instead of SocketException #5956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,27 +110,24 @@ int getAdapters (JNIEnv *env, int flags, IP_ADAPTER_ADDRESSES **adapters) { | |
|
||
if (ret != ERROR_SUCCESS) { | ||
free (adapterInfo); | ||
if (ret == ERROR_INSUFFICIENT_BUFFER) { | ||
JNU_ThrowByName(env, "java/lang/Error", | ||
"IP Helper Library GetAdaptersAddresses function failed " | ||
"with ERROR_INSUFFICIENT_BUFFER"); | ||
} else if (ret == ERROR_ADDRESS_NOT_ASSOCIATED ) { | ||
JNU_ThrowByName(env, "java/lang/Error", | ||
"IP Helper Library GetAdaptersAddresses function failed " | ||
"with ERROR_ADDRESS_NOT_ASSOCIATED"); | ||
} else { | ||
char error_msg_buf[100]; | ||
int _sr; | ||
_sr = _snprintf_s(error_msg_buf, sizeof(error_msg_buf), | ||
_TRUNCATE, "IP Helper Library GetAdaptersAddresses " | ||
"function failed with error == %d", ret); | ||
if (_sr != -1) { | ||
JNU_ThrowByName(env, "java/lang/Error", error_msg_buf); | ||
} else { | ||
JNU_ThrowByName(env, "java/lang/Error", | ||
"IP Helper Library GetAdaptersAddresses function failure"); | ||
} | ||
switch (ret) { | ||
case ERROR_INVALID_PARAMETER: | ||
JNU_ThrowInternalError(env, "IP Helper Library GetAdaptersAddresses function failed: invalid parameter"); | ||
break; | ||
case ERROR_NOT_ENOUGH_MEMORY: | ||
JNU_ThrowOutOfMemoryError(env, "IP Helper Library GetAdaptersAddresses function failed: not enough memory"); | ||
break; | ||
case ERROR_NO_DATA: | ||
// not an error | ||
*adapters = NULL; | ||
return ERROR_SUCCESS; | ||
default: | ||
SetLastError(ret); | ||
JNU_ThrowByNameWithMessageAndLastError(env, JNU_JAVANETPKG "SocketException", | ||
"IP Helper Library GetAdaptersAddresses function failed"); | ||
break; | ||
} | ||
|
||
return -1; | ||
} | ||
*adapters = adapterInfo; | ||
|
@@ -179,26 +176,21 @@ IP_ADAPTER_ADDRESSES *getAdapter (JNIEnv *env, jint index) { | |
|
||
if (val != ERROR_SUCCESS) { | ||
free (adapterInfo); | ||
if (val == ERROR_INSUFFICIENT_BUFFER) { | ||
JNU_ThrowByName(env, "java/lang/Error", | ||
"IP Helper Library GetAdaptersAddresses function failed " | ||
"with ERROR_INSUFFICIENT_BUFFER"); | ||
} else if (val == ERROR_ADDRESS_NOT_ASSOCIATED ) { | ||
JNU_ThrowByName(env, "java/lang/Error", | ||
"IP Helper Library GetAdaptersAddresses function failed " | ||
"with ERROR_ADDRESS_NOT_ASSOCIATED"); | ||
} else { | ||
char error_msg_buf[100]; | ||
int _sr; | ||
_sr = _snprintf_s(error_msg_buf, sizeof(error_msg_buf), | ||
_TRUNCATE, "IP Helper Library GetAdaptersAddresses function failed " | ||
"with error == %d", val); | ||
if (_sr != -1) { | ||
JNU_ThrowByName(env, "java/lang/Error", error_msg_buf); | ||
} else { | ||
JNU_ThrowByName(env, "java/lang/Error", | ||
"IP Helper Library GetAdaptersAddresses function failure"); | ||
} | ||
switch (val) { | ||
case ERROR_INVALID_PARAMETER: | ||
JNU_ThrowInternalError(env, "IP Helper Library GetAdaptersAddresses function failed: invalid parameter"); | ||
break; | ||
case ERROR_NOT_ENOUGH_MEMORY: | ||
JNU_ThrowOutOfMemoryError(env, "IP Helper Library GetAdaptersAddresses function failed: not enough memory"); | ||
break; | ||
case ERROR_NO_DATA: | ||
// not an error | ||
break; | ||
default: | ||
SetLastError(val); | ||
JNU_ThrowByNameWithMessageAndLastError(env, JNU_JAVANETPKG "SocketException", | ||
"IP Helper Library GetAdaptersAddresses function failed"); | ||
break; | ||
} | ||
return NULL; | ||
} | ||
|
@@ -237,7 +229,7 @@ static int ipinflen = 2048; | |
*/ | ||
int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP) | ||
{ | ||
DWORD ret, flags; | ||
int ret, flags; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks right but I can't relate this to your comment about the crash. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me try to explain this clang-style:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this, I hadn't spotted the broken code that tests if loopupIPAddrTable fails. |
||
MIB_IPADDRTABLE *tableP; | ||
IP_ADAPTER_ADDRESSES *ptr, *adapters=NULL; | ||
ULONG len=ipinflen, count=0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mapping ERROR_NO_DATA to ERROR_SUCCESS is probably correct here. Could this explain bug reports that seem to be from configurations with no IP addresses plumbed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it could. But in order to get ERROR_NO_DATA here one would need to disable loopback interface. I couldn't find how to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has been one or two reports from configurations that appear to have no interface or no IP addresses. I don't think we've been able to create those configurations to duplicate. In any case, treat NO_DATA as SUCCESS seems correct here.