Details
Description
Dear Apache FTPServer developers
java.nio.charset.CharsetEncoder is a mutable-class.
It change the "state" of the instance-variable every time you encode.
FtpResponseEncoder is not thread-safe because it defines CharsetEncoder as a class-variable.
Could you patch the FtpResponseEncoder to make it thread-safe?
For example…
Change “ENCODER” of FtpResponseEncoder from a class-variable to an instance-variable.
And, instantiate the ProtocolEncoder of FtpServerProtocolCodecFactory#getEncoder each time.
Alternatively, change "ENCODER" of FtpResponseEncoder from a class-variable to a local-variable and generate an instance each time.
Stack trace when a problem occurs
org.apache.mina.filter.codec.ProtocolEncoderException: java.lang.IllegalStateException: Current state = RESET, new state = CODING_END
at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:355) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:509) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:808) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:85) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.filter.logging.MdcInjectionFilter.filter(MdcInjectionFilter.java:136) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.filter.util.CommonEventFilter.filterWrite(CommonEventFilter.java:80) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:509) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:808) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.IoFilterAdapter.filterWrite(IoFilterAdapter.java:135) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:509) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1400(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:808) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.filterWrite(DefaultIoFilterChain.java:734) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:509) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireFilterWrite(DefaultIoFilterChain.java:501) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.session.AbstractIoSession.write(AbstractIoSession.java:490) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.session.AbstractIoSession.write(AbstractIoSession.java:435) ~[mina-core-2.0.4.jar:na]
at org.apache.ftpserver.impl.FtpIoSession.write(FtpIoSession.java:527) ~[ftpserver-core-1.0.6.jar:1.0.6]
at org.apache.ftpserver.command.impl.USER.execute(USER.java:197) ~[ftpserver-core-1.0.6.jar:1.0.6]
at org.apache.ftpserver.impl.DefaultFtpHandler.messageReceived(DefaultFtpHandler.java:210) ~[ftpserver-core-1.0.6.jar:1.0.6]
at org.apache.ftpserver.listener.nio.FtpHandlerAdapter.messageReceived(FtpHandlerAdapter.java:61) ~[ftpserver-core-1.0.6.jar:1.0.6]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:716) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:796) ~[mina-core-2.0.4.jar:na]
at org.apache.ftpserver.listener.nio.FtpLoggingFilter.messageReceived(FtpLoggingFilter.java:85) ~[ftpserver-core-1.0.6.jar:1.0.6]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:796) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:75) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.filter.logging.MdcInjectionFilter.filter(MdcInjectionFilter.java:136) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.filter.util.CommonEventFilter.messageReceived(CommonEventFilter.java:70) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:796) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolDecoderOutputImpl.flush(ProtocolCodecFilter.java:427) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:245) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:434) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:46) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:796) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:75) ~[mina-core-2.0.4.jar:na]
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63) [mina-core-2.0.4.jar:na]
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:780) [mina-core-2.0.4.jar:na]
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:772) [mina-core-2.0.4.jar:na]
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:714) [mina-core-2.0.4.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: java.lang.IllegalStateException: Current state = RESET, new state = CODING_END
at java.nio.charset.CharsetEncoder.throwIllegalStateException(CharsetEncoder.java:992) ~[na:1.8.0_65]
at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:572) ~[na:1.8.0_65]
at org.apache.mina.core.buffer.AbstractIoBuffer.putString(AbstractIoBuffer.java:1803) ~[mina-core-2.0.4.jar:na]
at org.apache.ftpserver.listener.nio.FtpResponseEncoder.encode(FtpResponseEncoder.java:49) ~[ftpserver-core-1.0.6.jar:1.0.6]
at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:322) ~[mina-core-2.0.4.jar:na]
... 47 common frames omitted
Attachments
Issue Links
- is cloned by
-
FTPSERVER-478 java.nio.charset.CoderMalfunctionError: java.nio.BufferUnderflowException
- Open