You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "David Rosenstrauch (JIRA)" <ji...@apache.org> on 2009/04/08 16:43:13 UTC

[jira] Created: (DIRMINA-684) NullPointerException when opening socket to localhost

NullPointerException when opening socket to localhost
-----------------------------------------------------

                 Key: DIRMINA-684
                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
             Project: MINA
          Issue Type: Bug
    Affects Versions: 2.0.0-M4
         Environment: Linux
            Reporter: David Rosenstrauch
            Priority: Minor


I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.

The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.

This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:

SEVERE: EXCEPTION :
org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
    at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
    at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
    at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
    at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
    ... 9 more

Or sometimes another similar error as well:

SEVERE: Error occurred during message handling
org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
    at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
    at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
    ... 9 more 


Noteworthy aspects of my configuration:

* using the M4 release of MINA

* I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them

* I'm using both a read and a write thread pool

* building my filter chain as follows:
    protocolAcceptor = new NioSocketAcceptor();
    protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
    protocolAcceptor.setReuseAddress(true);
    DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
    filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
    readerThreadPool = new OrderedThreadPoolExecutor();
    filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
    filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
    writerThreadPool = new OrderedThreadPoolExecutor();
    filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
    protocolAcceptor.setHandler(protocolHandler); 



I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12706411#action_12706411 ] 

Emmanuel Lecharny commented on DIRMINA-684:
-------------------------------------------

After having looked at the code, I don't think it's a bug in MINA, more probably something wrong done in the encoder/decoder. Now, the way we report the exception might be improved : if the encoder/decoder generate a NPA, it should be encapsulated in a way we know what is the cause. may be providing a stack trace here could help ... 

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC1
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12709297#action_12709297 ] 

Emmanuel Lecharny commented on DIRMINA-684:
-------------------------------------------

A second look make me thing that the problem is not in the user code, as the NPE might be generated by the encoder being null on line 297 :

encoder.encode(session, message, encoderOut);

This can happen if the encoder has been disposed, ie if the ProtocolCodecFilter has been removed from the chain (unlikely to be the case ...) or, more probably, if the session has been closed.

Some nasty bug has been fixed yesturday in the OrderedThreadPoolExecutor, i'm wondering if this could have fixed the current issue ? This was a problem in the way incoming events were processed (ie, a close event could have been processed *before* a MessgeREeceived event, leading to inconsistencies.

Could you give the very last version of trunk a try ?

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC1
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny closed DIRMINA-684.
-------------------------------------


> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC2
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Steve Ulrich (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12697055#action_12697055 ] 

Steve Ulrich commented on DIRMINA-684:
--------------------------------------

First of all, adding a (reading) thread pool/executor filter before codec filter is a really bad idea!
Second, the exception should not be problematic, since the session is already closed at that time. A "WriteToClosedSessionException" should be more appropriate.

Try moving the reading executor behind the codec and remove the writing one.

The null pointer seems to result from disposed/disposing filter chain while still trying to de-/encode data, maybe ProtocolCodecFactory needs some Locks and/or null checks?.

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M4
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny updated DIRMINA-684:
--------------------------------------

    Affects Version/s:     (was: 2.0.0-M4)
                       2.0.0-M5
        Fix Version/s: 2.0.0-RC1

I guess that the issue still exists in 2.0.0-M5?

In any case, a NPE is not acceptable. We must fix it.

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC1
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny updated DIRMINA-684:
--------------------------------------

    Fix Version/s:     (was: 2.0.0-RC2)
                   2.0.0

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny resolved DIRMINA-684.
---------------------------------------

    Resolution: Duplicate

This issue is a duplicate of the DIRMINA-679. 

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC1
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "David Rosenstrauch (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12697520#action_12697520 ] 

David Rosenstrauch commented on DIRMINA-684:
--------------------------------------------

> First of all, adding a (reading) thread pool/executor filter before codec filter is a really bad idea! 

Not sure I understand.  Why is that a problem?  My intention is to have a pool of threads reading messages and then feeding them to the codec filter for processing.  Similarly, I have a pool of threads handling writes back out to the socket.  Why is this setup "a really bad idea"?


> Try moving the reading executor behind the codec and remove the writing one.

Again, 1) why should the read executor be behind the codec?, and 2) why should I remove the writing thread pool?


AFA the bug I posted about:

> Second, the exception should not be problematic, since the session is already closed at that time. A "WriteToClosedSessionException" should be more appropriate.

> The null pointer seems to result from disposed/disposing filter chain while still trying to de-/encode data, maybe ProtocolCodecFactory needs some Locks and/or null checks?.

No idea what the problem is that's throwing NPE's, but I would think that MINA shouldn't be doing it.

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M4
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "David Rosenstrauch (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12709411#action_12709411 ] 

David Rosenstrauch edited comment on DIRMINA-684 at 5/14/09 7:27 AM:
---------------------------------------------------------------------

> A second look make me thing that the problem is not in the user code, as the NPE might be generated by the encoder being null on line 297 :
>
> encoder.encode(session, message, encoderOut); 

Problem's clearly not in user code - just look at the stack trace:  none of my code is in the stack.  But also because the NPE is clearly occurring in MINA framework code objects.

In any case, I don't think I'm going to be able to retest this after the fix, as my code has since changed and no longer triggers the error condition.  (Which was intermittent anyway.)

Hopefully the OrderedThreadPoolExecutor fix will clear up the problem.

Thanks for looking into this though.

      was (Author: darose):
    A second look make me thing that the problem is not in the user code, as the NPE might be generated by the encoder being null on line 297 :

encoder.encode(session, message, encoderOut);> A second look make me thing that the problem is not in the user code, as the NPE might be generated by the encoder being null on line 297 :
>
> encoder.encode(session, message, encoderOut); 

Problem's clearly not in user code - just look at the stack trace:  none of my code is in the stack.  But also because the NPE is clearly occurring in MINA framework code objects.

In any case, I don't think I'm going to be able to retest this after the fix, as my code has since changed and no longer triggers the error condition.  (Which was intermittent anyway.)

Hopefully the OrderedThreadPoolExecutor fix will clear up the problem.

Thanks for looking into this though.
  
> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC1
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "Julien Vermillard (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Vermillard updated DIRMINA-684:
--------------------------------------

    Fix Version/s:     (was: 2.0.0-RC1)
                   2.0.0-RC2

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC2
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-684) NullPointerException when opening socket to localhost

Posted by "David Rosenstrauch (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12709411#action_12709411 ] 

David Rosenstrauch commented on DIRMINA-684:
--------------------------------------------

A second look make me thing that the problem is not in the user code, as the NPE might be generated by the encoder being null on line 297 :

encoder.encode(session, message, encoderOut);> A second look make me thing that the problem is not in the user code, as the NPE might be generated by the encoder being null on line 297 :
>
> encoder.encode(session, message, encoderOut); 

Problem's clearly not in user code - just look at the stack trace:  none of my code is in the stack.  But also because the NPE is clearly occurring in MINA framework code objects.

In any case, I don't think I'm going to be able to retest this after the fix, as my code has since changed and no longer triggers the error condition.  (Which was intermittent anyway.)

Hopefully the OrderedThreadPoolExecutor fix will clear up the problem.

Thanks for looking into this though.

> NullPointerException when opening socket to localhost
> -----------------------------------------------------
>
>                 Key: DIRMINA-684
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-684
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M5
>         Environment: Linux
>            Reporter: David Rosenstrauch
>            Priority: Minor
>             Fix For: 2.0.0-RC1
>
>
> I have a MINA-based server I've written that's up and running and works fine.  I recently added a new bit of functionality to it, however, and it's now throwing NullPointerExceptions intermittently.
> The server uses a text-based protocol (using TextLineCodecFactory). I've added the capability to give the server a command line parm which is the name of a text file, containing startup commands that the server should execute after it starts up.  I'm doing this by having the server open a java socket to the server's port on localhost, read the text file and write (and flush) each command out to the socket.
> This is generally working, and the server is receiving and processing each command (not always in the order sent, but I'm guessing that's an outgrowth of my using a thread pool, and that's not a problem anyway). But from time to time, the server is spitting out this error:
> SEVERE: EXCEPTION :
> org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:312)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:506)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:814)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:65)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:297)
>     ... 9 more
> Or sometimes another similar error as well:
> SEVERE: Error occurred during message handling
> org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.NullPointerException (Hexdump: 68 65 6C 70 0A 73 74 61 74 73 0A 71 75 65 72 79 20 31 32 33 34 0A)
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:48)
>     at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:802)
>     at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:59)
>     at org.apache.mina.core.session.IoEvent.run(IoEvent.java:64)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:552)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:544)
>     at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:488)
>     at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>     at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:224)
>     ... 9 more 
> Noteworthy aspects of my configuration:
> * using the M4 release of MINA
> * I'm not pausing between sending commands; i.e., I'm write and flushing them down the socket as quickly as Java can send them
> * I'm using both a read and a write thread pool
> * building my filter chain as follows:
>     protocolAcceptor = new NioSocketAcceptor();
>     protocolAcceptor.setDefaultLocalAddress(new InetSocketAddress(protocolPort));
>     protocolAcceptor.setReuseAddress(true);
>     DefaultIoFilterChainBuilder filterChainBuilder = protocolAcceptor.getFilterChain();
>     filterChainBuilder.addLast("logger", new LoggingFilter(ProfileCacheServer.class));
>     readerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("readExecutor", new ExecutorFilter(readerThreadPool, IoEventType.MESSAGE_RECEIVED));
>     filterChainBuilder.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(ParseConstants.UTF8_CHARSET)));
>     writerThreadPool = new OrderedThreadPoolExecutor();
>     filterChainBuilder.addLast("writeExecutor", new ExecutorFilter(writerThreadPool, IoEventType.WRITE));
>     protocolAcceptor.setHandler(protocolHandler); 
> I actually did find a way to "fix" this problem but someone on the mailing list suggested that MINA shouldn't be throwing NPE's regardless.  Fix is as follows:   I was originally just dropping the connection on the client side when I was finished.  But after changing my code to issue a proper "close connection" command to the server before disconnecting, it looks like the NPE's go away. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.