You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-users@mina.apache.org by Alex Parvulescu <al...@gmail.com> on 2009/11/19 10:29:38 UTC
Spring enabled FTP Server NPE on start/stop/start
Hello guys,
I wanted to use FTPServer with Spring, but I have some unit tests
failing. I am using it to unit test a FTP Client connector that I'm
working on.
You only need to start and stop the server a couple of times. Always
the second test fails with a NPE.
This is the unit test file (it is very very basic):
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/ftpContextTest.xml" })
public class FTPServerSpringTest {
@Autowired
private FtpServer ftpServer;
@Before
public void before() throws FtpException {
ftpServer.start();
}
@Test
public void test1() {
System.out.println("nothing");
}
@Test
public void test2() {
System.out.println("nothing");
}
@After
public void after() {
ftpServer.stop();
}
}
This is the spring config file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ftpserver="http://mina.apache.org/ftpserver/spring/v1"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://mina.apache.org/ftpserver/spring/v1
http://mina.apache.org/ftpserver/ftpserver-1.0.xsd">
<ftpserver:server id="ftpServer" anon-enabled="true">
<ftpserver:listeners>
<ftpserver:nio-listener name="default" port="3333"
local-address="localhost" />
</ftpserver:listeners>
</ftpserver:server>
</beans>
The stack trace:
java.lang.NullPointerException
at org.apache.ftpserver.impl.DefaultFtpServer.start(DefaultFtpServer.java:74)
at com.pfalabs.ftpserver.FTPServerSpringTest.before(FTPServerSpringTest.java:22)
Digging into this deeper it seems this code will get you the NPE really fast:
ftpServer.start();
ftpServer.stop();
ftpServer.start();
--> java.lang.NullPointerException
at org.apache.ftpserver.impl.DefaultFtpServer.start(DefaultFtpServer.java:74)
at com.pfalabs.ftpserver.FTPServerTest.test1(FTPServerTest.java:40)
Looking at the code I'm not sure I am supposed to be doing that:
start/stop/start, but this is the way I have my unit tests.
One workaround would be to have a static method to initialize the
FTPServer Component, but that would be ignoring spring altogether.
Or maybe forcing spring to NOT return a singleton each time it will
try to inject the bean can fix this.
This is not a blocking issue for me, Its something I've seen while
trying to take FTPServer for a spin.
thanks,
alex
Re: Spring enabled FTP Server NPE on start/stop/start
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Thu, Nov 19, 2009 at 10:29 AM, Alex Parvulescu
<al...@gmail.com> wrote:
> You only need to start and stop the server a couple of times. Always
> the second test fails with a NPE.
Right, calling stop() is the same thing as destroying the server and
thus, you can not restart a stopped server. That being said, I think
we should make two improvements:
* This fact should be documented in Javadoc for stop()
* We should not throw an NPE, instead we should throw a more
descriptive exception.
So, I opened a JIRA issue for this and have committed fixes to trunk
and the 1.0.x branch so it should be included in the next release.
Thanks for reminding us that this needed fixing!
/niklas