Hi again,
finally I found the problem. Here's a complete reproducer-sample:
----
import java.net.InetSocketAddress;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
public class MinaExceptionTest {
public static void main(String[] args) {
IoConnector connector = new NioSocketConnector();
connector.setHandler(new IoHandler(){
@Override
public void exceptionCaught(IoSession session,
Throwable cause)
throws Exception {
System.out.println("exceptionCaught:
session="+session+"
cause="+cause);
}
@Override
public void messageReceived(IoSession session, Object
message)
throws Exception {
System.out.println("messageReceived:
session="+session+"
message="+message);
}
@Override
public void messageSent(IoSession session, Object
message)
throws Exception {
System.out.println("messageSent:
session="+session+"
message="+message);
}
@Override
public void sessionClosed(IoSession session) throws
Exception {
System.out.println("sessionClosed:
session="+session);
}
@Override
public void sessionCreated(IoSession session) throws
Exception {
System.out.println("sessionCreated:
session="+session);
}
@Override
public void sessionIdle(IoSession session, IdleStatus
status)
throws Exception {
System.out.println("sessionIdle:
session="+session+
"status="+status);
}
@Override
public void sessionOpened(IoSession session) throws
Exception {
System.out.println("sessionOpened:
session="+session);
}
});
System.out.println("Connecting ...");
ConnectFuture future = connector.connect(new
InetSocketAddress("my.notexisting.domain.com", 80));
System.out.println("connect() returned");
future.awaitUninterruptibly();
System.out.println("connected! Now trying to get session ...");
future.getSession();
System.out.println("Got session");
System.exit(0);
}
}
----
Try running this sample with disabled network-devices in Windows. You will
get the following output:
----
Connecting ...
connect() returned
connected! Now trying to get session ...
Exception in thread "main" java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at
org.apache.mina.transport.socket.nio.NioSocketConnector.connect(NioSocketConnector.java:188)
at
org.apache.mina.transport.socket.nio.NioSocketConnector.connect(NioSocketConnector.java:46)
at
org.apache.mina.core.polling.AbstractPollingIoConnector.connect0(AbstractPollingIoConnector.java:324)
at
org.apache.mina.core.service.AbstractIoConnector.connect(AbstractIoConnector.java:256)
at
org.apache.mina.core.service.AbstractIoConnector.connect(AbstractIoConnector.java:173)
at MinaExceptionTest.main(MinaExceptionTest.java:60)
----
The problem now is: the await... line returns also in case of errors. And
that was my problem. I thought this would give exceptions or things like
that. So I continued with getting the session. And THIS brought up the
exception with the really weird stack trace that seems to point to the
wrong line.
Maybe getSession() should internally check the status (connected or not)
and return an exception or so. It seems that this is right now implemented,
but as you can see, the wrong stacktrace is printed ...
For now I will use "future.isConnected()" right before getting the session.
This will help identifiyng the issue better. Other possibility: Use a
try/catch block around the getSession line that checks for "Exception", or
to be more precise, check for java.nio.channels.UnresolvedAddressException.
But checking the status (connected or not) would be better.
br,
Alex
On Thu, 28 May 2009 17:18:54 +0200, Emmanuel Lecharny
<[email protected]>
wrote:
>>
>> > I
>> > see no way for java to not get through the catch( Exception e )...
>>
>> Me too. That's really a strange behaviour.
>
>
> Even if the UnresolvedAddressException is a RuntimeException, it should
be
> caught by the catch( Exception e). There is something weird...
>
>
>>
>> > Can you
>> > add a System.out.println() in the catch part of your code ?
>>
>> I will try. But as the stack-trace says that this IS comming from the
>> connect-method I'm not sure if an sysout is telling something different.
>
>
> Just keep me updated.