<AWT Dev> RFR(XS): 8042416: X11GraphicsEnvironment.isDisplayLocal() throws NoSuchElementException if DISPLAY host has more IP addresses than a local interface
Volker Simonis
volker.simonis at gmail.com
Thu May 8 07:33:47 UTC 2014
Hi Alexander,
thanks for the review.
You're right - the webrev and the patch differ.
I realized that I haven't done a "hg qrefresh" before I created the
webrev and it seems that webrev.ksh includes the current local changes
into the webrev while it only uses the queued change set for the patch
(which seems strange to me).
I'll push the right version (without the cast) of course.
Regards,
Volker
On Wed, May 7, 2014 at 2:28 PM, Alexander Zvegintsev
<alexander.zvegintsev at oracle.com> wrote:
> Hi Volker,
>
> the fix looks fine to me.
>
> P.S. I noticed that there is no cast in the webrev itself, but the patch[1]
> under jdk.changeset link
> has it.
>
> [1] http://cr.openjdk.java.net/~simonis/webrevs/8042416/jdk.changeset
>
>
> Thanks,
>
> Alexander.
>
> On 05/05/2014 10:07 PM, Volker Simonis wrote:
>>
>> Hi,
>>
>> could you please review this tiny fix:
>>
>> http://cr.openjdk.java.net/~simonis/webrevs/8042416/
>> https://bugs.openjdk.java.net/browse/JDK-8042416
>>
>> X11GraphicsEnvironment.isDisplayLocal() calls
>> X11GraphicsEnvironment._isDisplayLocal() whihc in turn iterates over
>> all IP addressees of the DISPLAY host and checks if one of them
>> corresponds to the IP address of a local network interface:
>>
>> for (; interfaces.hasMoreElements();) {
>> locals = interfaces.nextElement().getInetAddresses();
>> for (; locals.hasMoreElements();) {
>> for (int i = 0; i < remAddr.length; i++) {
>> if (locals.nextElement().equals(remAddr[i])) {
>> return Boolean.TRUE;
>> }
>> }
>> }
>> }
>>
>> However it calls locals.nextElement() for each IP address of the
>> DISPLAY host so if the DISPLAY host has more IP addresses than one of
>> the local network interfaces, the check will unexpectedly throw a
>> NoSuchElementException.
>>
>> The solution is simple - just compare every IP-Address of the DISPLAY
>> host against each IP-address of every network interface like so:
>>
>> for (; interfaces.hasMoreElements();) {
>> locals = interfaces.nextElement().getInetAddresses();
>> for (; locals.hasMoreElements();) {
>> final InetAddress localAddr = locals.nextElement();
>> for (int i = 0; i < remAddr.length; i++) {
>> if (localsAddr.equals(remAddr[i])) {
>> return Boolean.TRUE;
>> }
>> }
>> }
>> }
>>
>> Thank you and best regards,
>> Volker
>>
>>
>> PS: Notice that if we ever want to downport this to jdk8 we need an
>> additional cast like so:
>>
>> final InetAddress localAddr = (InetAddress)locals.nextElement();
>>
>> unless we also downport "8039642: Fix raw and unchecked warnings in
>> sun.awt.*" before this change.
>
>
More information about the awt-dev
mailing list