In the example below, a NullPointerException is thrown within Cactus before the endNoContentMethod is reached. However, the 'SomeContent' test passes without incident.
Testcase: testNoContent took 0.301 sec
[cactus] Caused an ERROR
[cactus] null
[cactus] java.lang.NullPointerException
[cactus] at org.apache.cactus.internal.client.connector.http.AutoReadHttpURLConnection.copy(AutoReadHttpURLConnection.java:187)
public class CactusTest extends ServletTestCase
{
public void testNoContent()
{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
public void endNoContent(WebResponse webResponse)
{
assertEquals(webResponse.getStatusCode(), 204);
}
public void testSomeContent() throws IOException
{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
response.getWriter().println();
}
public void endSomeContent(WebResponse webResponse)
{
assertEquals(webResponse.getStatusCode(), 204);
}
}
Description
In the example below, a NullPointerException is thrown within Cactus before the endNoContentMethod is reached. However, the 'SomeContent' test passes without incident.
Testcase: testNoContent took 0.301 sec
[cactus] Caused an ERROR
[cactus] null
[cactus] java.lang.NullPointerException
[cactus] at org.apache.cactus.internal.client.connector.http.AutoReadHttpURLConnection.copy(AutoReadHttpURLConnection.java:187)
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
import org.apache.cactus.ServletTestCase;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CactusTest extends ServletTestCase
{
public void testNoContent()
{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
public void endNoContent(WebResponse webResponse)
{
assertEquals(webResponse.getStatusCode(), 204);
}
public void testSomeContent() throws IOException
{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
response.getWriter().println();
}
public void endSomeContent(WebResponse webResponse)
{
assertEquals(webResponse.getStatusCode(), 204);
}
}
Maxwell Grender-Jones added a comment - 17/Jun/04 10:53 AM This fixes the problem (it's a simple !=null check ;))
If this is sufficient to get me added to contributors, pse can you do so :)
Thanks
<action dev="VMA" type="fix" issue="CACTUS-123" due-to="Maxwell Grender-Jones">
Cactus was failing with a <code>NullPointerException</code> if the
response was not returning any output stream (which happens if
<code>response.setStatus(HttpServletResponse.SC_NO_CONTENT)</code> is
called for example).
</action>
If this is sufficient to get me added to contributors, pse can you do so :)
Thanks