Description
We have the following code for setting up listeners before starting the FTP server:
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(controlPort);
listenerFactory.setDataConnectionConfiguration(dataConnectionConfig);
listenerFactory.setSessionFilter(new SessionFilter() {
@Override
public boolean accept(IoSession ioSession) {
InetAddress address = ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress();
boolean accept = !enableIpSecurity || allowedIpAddresses.contains(address.getHostAddress());
if (accept)
else
{ log.warn("Login attempt from " + address.getHostAddress() + " failed"); } return accept;
}
});
Listener listener = listenerFactory.createListener();
When SessionFilter.accept() returns false everything works fine from the user standpoint, however we get the following stack trace in the logs:
[WARN ] 2016-11-02 10:35:39 [DefaultFtpHandler-pool-29-thread-1] - Data connection threw an exception on disconnect
java.lang.NullPointerException
at org.apache.ftpserver.impl.IODataConnectionFactory.<init>(IODataConnectionFactory.java:80)
at org.apache.ftpserver.impl.FtpIoSession.getDataConnection(FtpIoSession.java:554)
at org.apache.ftpserver.impl.DefaultFtpHandler.sessionClosed(DefaultFtpHandler.java:106)
at org.apache.ftpserver.listener.nio.FtpHandlerAdapter.sessionClosed(FtpHandlerAdapter.java:72)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.sessionClosed(DefaultIoFilterChain.java:797)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionClosed(DefaultIoFilterChain.java:504)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$900(DefaultIoFilterChain.java:48)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionClosed(DefaultIoFilterChain.java:927)
at org.apache.mina.filter.logging.LoggingFilter.sessionClosed(LoggingFilter.java:238)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionClosed(DefaultIoFilterChain.java:504)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$900(DefaultIoFilterChain.java:48)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionClosed(DefaultIoFilterChain.java:927)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:109)
at org.apache.mina.filter.logging.MdcInjectionFilter.filter(MdcInjectionFilter.java:135)
at org.apache.mina.filter.util.CommonEventFilter.sessionClosed(CommonEventFilter.java:55)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionClosed(DefaultIoFilterChain.java:504)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$900(DefaultIoFilterChain.java:48)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionClosed(DefaultIoFilterChain.java:927)
at org.apache.mina.filter.codec.ProtocolCodecFilter.sessionClosed(ProtocolCodecFilter.java:360)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextSessionClosed(DefaultIoFilterChain.java:504)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$900(DefaultIoFilterChain.java:48)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.sessionClosed(DefaultIoFilterChain.java:927)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:109)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:770)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:762)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:704)
at java.lang.Thread.run(Thread.java:745)
What seems to be happening is that the constructor for IODataConnectionFactory is expecting the session parameter to be non-null however since SessionFilter.accept() returns false, then this is not the case:
if (session.getListener().getDataConnectionConfiguration().isImplicitSsl())
{ secure = true; }Thus we get a NullPointerException. This snippet should probably be changed to:
if (session != null && session.getListener().getDataConnectionConfiguration().isImplicitSsl()) { secure = true; }