You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Mark Gertsvolf <ma...@nortel.com> on 2008/10/30 16:41:07 UTC

[testing] Exception java.nio.channels.IllegalSelectorException thrown in dnsjava

Hi,

I am running Harmony JVM 5.0 on CentOS 5, x86 and I am using dnsjava
library. The following simple A lookup works as expected with IBM JVM
5.0 and results in exception with Harmony.

try {
	org.xbill.DNS.Record[] records = new
org.xbill.DNS.Lookup("magma.ca").run();
} catch (Throwable ex) {
	ex.printStackTrace();
}

Exception:
java.nio.channels.IllegalSelectorException
        at
java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSelecta
bleChannel.java:137)
        at
java.nio.channels.SelectableChannel.register(SelectableChannel.java:115)
        at org.xbill.DNS.Client.<init>(Client.java:22)
        at org.xbill.DNS.UDPClient.<init>(UDPClient.java:14)
        at org.xbill.DNS.UDPClient.sendrecv(UDPClient.java:64)
        at org.xbill.DNS.SimpleResolver.send(SimpleResolver.java:256)
        at org.xbill.DNS.ResolveThread.run(ResolveThread.java:37)

I studied dnsjava code and I do not see any reason for
IllegalSelectorException to be thrown. 
http://dnsjava.cvs.sourceforge.net/viewvc/dnsjava/dnsjava/org/xbill/DNS/
Client.java?revision=1.5&view=markup
http://dnsjava.cvs.sourceforge.net/viewvc/dnsjava/dnsjava/org/xbill/DNS/
UDPClient.java?revision=1.4&view=markup


How does one troubleshoot this type of problem?
Any help will be appreciated.

Thanks,
Mark.

Re: RE: [testing] Exception java.nio.channels.IllegalSelectorException thrown in dnsjava

Posted by Tim Ellison <t....@gmail.com>.

Good.  Unless I hear any objections I'll commit that patch in the next 
couple of days.

Regards,
Tim
 
On 3 Nov 2008, 2:33 AM, "Mark Gertsvolf" <ma...@nortel.com> wrote:

On October 31, 2008 6:11 AM Tim Ellison wrote: > > > in the meantime you can 
try continuing your a...
Hi Tim,

Thank you for your response. With the patch I am now able to run my
application and it passes basic sanity tests.

Cheers,
Mark.


RE: [testing] Exception java.nio.channels.IllegalSelectorException thrown in dnsjava

Posted by Mark Gertsvolf <ma...@nortel.com>.
On October 31, 2008 6:11 AM Tim Ellison wrote:
> 
> 
> in the meantime you can try continuing your application 
> testing with the patch below applied.
> 

Hi Tim,

Thank you for your response. With the patch I am now able to run my
application and it passes basic sanity tests.

Cheers,
Mark.

Re: [testing] Exception java.nio.channels.IllegalSelectorException thrown in dnsjava

Posted by Tim Ellison <t....@gmail.com>.
Mark Gertsvolf wrote:
> I am sorry I did not realize Harmony delivers both JVM and java
> classlib, so it did not occur to me to look for java.nio package in
> Harmony source and use Java debugger.

No problem.  Harmony is implementing the VM (including interpreter,
memory manager, and JIT compiler), class libraries, and developer tools.

> Perhaps a more general question then - I am trying to put Java onto a
> Linux distro, which is old  - Kernel 2.4.22 and glibc 2.3.2 on PowerPC.
> I could not use off-the-shelf binary distributions of JVM from Sun or
> IBM as I need to build the JVM from source using my toolchain. I am
> trying to find out whether Harmony is a good choice.
> So, I first ran my application with Harmony JVM and hit this first issue
> with dnsjava.
> My application uses other 3rd party libraries including jain-sip, etc. 

Sounds like you already made good progress, to get as far as running the
application code.  Seriously, there is lots of code that is run as the
runtime environment starts up that it shows things are not fundamentally
broken in your environment.

> Is it fair to say that there is some risk involved in trying to use
> Harmony with my application? Sounds like my application and libraries
> may not run well with Harmony classlib/JVM? 

It depends on your definition of "risk" ?

> Also, what is the policy of
> this community in cases like dnsjava? Is the argument that "dnsjava
> works" with other JVMs strong enough to convince the community to make
> modifications in classlib to make dnsjava work? Or would you be prepared
> to sometimes say: we are not fixing and the library has to change.

Any case for things, like this, that work on the reference
implementation and not with Harmony are a good candidate for raising a
bug.  As a general case, we will follow the Java specifications _and_
try to be compatible with other implementations.  We would only decide
not to fix it if there was a good argument why the existing Harmony
behavior makes better sense.

In this case, I would consider it a bug in Harmony code.

> Apologies if my questions sound silly. I am new to the space.

Not silly at all.  Good questions, and thank you for reporting your
findings.  While we have a good test suite, and run popular applications
frequently, there will always be bugs and issues to deal with, and you
will get best feedback by posting here just like you did!

The only reason I have not fixed this directly in the code already is
that there is an explicit comment and test in the code that throws the
exception you saw.  I'll give people a moment to defend that check
before removing it.

in the meantime you can try continuing your application testing with the
patch below applied.

Regards,
Tim

Index:
modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java
===================================================================
---
modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java
(revision 707373)
+++
modules/nio/src/main/java/common/java/nio/channels/spi/AbstractSelectableChannel.java
(working copy)
@@ -132,10 +132,10 @@
                 // throw NPE exactly to keep consistency
                 throw new NullPointerException();
             }
-            if (0 == interestSet) {
-                // throw ISE exactly to keep consistency
-                throw new IllegalSelectorException();
-            }
+//            if (0 == interestSet) {
+//                // throw ISE exactly to keep consistency
+//                throw new IllegalSelectorException();
+//            }
             SelectionKey key = keyFor(selector);
             if (null == key) {
                 key = ((AbstractSelector) selector).register(this,
interestSet,

RE: [testing] Exception java.nio.channels.IllegalSelectorException thrown in dnsjava

Posted by Mark Gertsvolf <ma...@nortel.com>.
On October 30, 2008 1:03 PM Tim Ellison wrote
> At the risk of sounding patronizing, "in a debugger" ;-)
> 
> In this case it would be possible to catch the 
> IllegalSelectorException and go in to look at how the program 
> got there and the values of the variables at the time.
> 

Hi Tim,

I am sorry I did not realize Harmony delivers both JVM and java
classlib, so it did not occur to me to look for java.nio package in
Harmony source and use Java debugger.

Perhaps a more general question then - I am trying to put Java onto a
Linux distro, which is old  - Kernel 2.4.22 and glibc 2.3.2 on PowerPC.
I could not use off-the-shelf binary distributions of JVM from Sun or
IBM as I need to build the JVM from source using my toolchain. I am
trying to find out whether Harmony is a good choice.
So, I first ran my application with Harmony JVM and hit this first issue
with dnsjava.
My application uses other 3rd party libraries including jain-sip, etc. 

Is it fair to say that there is some risk involved in trying to use
Harmony with my application? Sounds like my application and libraries
may not run well with Harmony classlib/JVM? Also, what is the policy of
this community in cases like dnsjava? Is the argument that "dnsjava
works" with other JVMs strong enough to convince the community to make
modifications in classlib to make dnsjava work? Or would you be prepared
to sometimes say: we are not fixing and the library has to change.

Apologies if my questions sound silly. I am new to the space.

Thank you in advance,
Mark.



Re: [testing] Exception java.nio.channels.IllegalSelectorException thrown in dnsjava

Posted by Tim Ellison <t....@gmail.com>.
Mark Gertsvolf wrote:
> I am running Harmony JVM 5.0 on CentOS 5, x86 and I am using dnsjava
> library. The following simple A lookup works as expected with IBM JVM
> 5.0 and results in exception with Harmony.
> 
> try {
> 	org.xbill.DNS.Record[] records = new
> org.xbill.DNS.Lookup("magma.ca").run();
> } catch (Throwable ex) {
> 	ex.printStackTrace();
> }
> 
> Exception:
> java.nio.channels.IllegalSelectorException
>         at
> java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSelecta
> bleChannel.java:137)
>         at
> java.nio.channels.SelectableChannel.register(SelectableChannel.java:115)
>         at org.xbill.DNS.Client.<init>(Client.java:22)
>         at org.xbill.DNS.UDPClient.<init>(UDPClient.java:14)
>         at org.xbill.DNS.UDPClient.sendrecv(UDPClient.java:64)
>         at org.xbill.DNS.SimpleResolver.send(SimpleResolver.java:256)
>         at org.xbill.DNS.ResolveThread.run(ResolveThread.java:37)
> 
> I studied dnsjava code and I do not see any reason for
> IllegalSelectorException to be thrown. 
> http://dnsjava.cvs.sourceforge.net/viewvc/dnsjava/dnsjava/org/xbill/DNS/
> Client.java?revision=1.5&view=markup
> http://dnsjava.cvs.sourceforge.net/viewvc/dnsjava/dnsjava/org/xbill/DNS/
> UDPClient.java?revision=1.4&view=markup
> 
> 
> How does one troubleshoot this type of problem?
> Any help will be appreciated.

At the risk of sounding patronizing, "in a debugger" ;-)

In this case it would be possible to catch the IllegalSelectorException
and go in to look at how the program got there and the values of the
variables at the time.

I see that Client.java:23 is explicitly registering a selector with a
channel and giving an empty set of operations it is interested in, and
AbstractSelectableChannel.java:135 is throwing the exception if the set
is empty.

Here's a simple reproducer

    public static void main(String[] args) throws IOException {
        SocketChannel channel = SocketChannel.open();
        channel.configureBlocking(false);
        Selector selector = Selector.open();

        channel.register(selector, 0);
    }


I don't know why we forbid an empty set of interested operations?
If I remove the check my simple test above works...

Regards,
Tim