[PATCH] 7006496: Use modern Windows API to retrieve OS DNS servers

Chris Hegarty chris.hegarty at oracle.com
Wed Jan 8 15:27:19 UTC 2020


> On 8 Jan 2020, at 05:12, Anuraag Agrawal <anuraaga at gmail.com> wrote:
> 
> Hi Chris,
> 
> Happy new year - sorry for the long delay. I have made an updated patch fixing the comment (missing comma), bumping MAX_STR_LEN, and tweaking the exception behavior.
> 
> Basically, as you pointed out loadDNSConfig itself does not throw any exception. The getAdapters function will throw a) OutOfMemoryError if native memory allocation failed or b) Error if the Windows SDK function randomly failed. I have gone ahead and added code to check the exception thrown when getAdapters failed and propagate it if it is OOME or clear it otherwise. This should be the same behavior as the old version of loadDNSConfig.


...

> -    if (adapterP) {
> -        free(adapterP);
> +        free(adapters);
> +    } else {
> +        th = (*env)->ExceptionOccurred(env);
> +        if (th != NULL) {
> +            // We only throw errors if not able to allocate memory, otherwise
> +            // ignore ones related to Windows API usage itself.
> +            (*env)->ExceptionClear(env);
> +            if ((*env)->IsInstanceOf(env, th, outOfMemoryErrCl)) {
> +                (*env)->Throw(env, th);
> +                return STS_ERROR;
> +            }
> +        }

I think that it would be preferable to NOT clear the pending exception, and just allow it to propagate up.

-Chris.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20200108/ae5403fd/attachment.htm>


More information about the net-dev mailing list