Having a strange situation happening.
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 a NPE.
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
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
* 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);
Anyone have any idea what this error could be? I can't understand how
ProtocolCodecFilter.filterWrite could be throwing a NPE. It's basically
saying that the encoder is null, but I don't see how that could be.
Any help appreciated!
TIA,
DR