https://issues.apache.org/bugzilla/show_bug.cgi?id=50552

--- Comment #4 from Christopher Schultz <ch...@christopherschultz.net> 
2011-01-06 16:58:20 EST ---
It looks like this works properly in the sunny-day scenario because
BaseRedirectorHelperTask.handleOutput is typically called, which properly opens
the redirector:

    protected void handleOutput(String output) {
        if (redirectOutput) {
            if (redirectOutPrintStream == null) {
                openRedirector();
            }
            redirectOutPrintStream.println(output);
            if (alwaysLog) {
                log(output, Project.MSG_INFO);
            }

In the error case, AbstractCatalinaTask.execute does this:

            if (isFailOnError()) {
                throw new BuildException(e);
            } else {
                handleErrorOutput(e.getMessage());
            }

The BuildException doesn't get caught by the currently-running exception
handler (for java.lang.Exception) and then the finally block is called, which
attempts to close the redirector, ultimately resulting in this NPE.

I believe this bug might be better solved by modifying
BaseRedirectorHelperTask.closeRedirector in this way:

        try {
-            if (redirectOutput) {
+            if (redirectOutput && redirectOutPrintStream != null) {

                redirector.complete();
            }

This makes BaseRedirectorHelperTask.closeRedirector safer internally and
doesn't rely on the client (AbstractCatalinaTask, in this case) to be extra
careful about state.

Another option would be:

        try {
            if (redirectOutput) {
+              if (redirectOutPrintStream == null) {
+                openRedirector();
+              }

                redirector.complete();
            }

I'm open to suggestions, since I don't really know how all this stuff should
work. I'm in favor of a solution where a class manages it's state as much as
possible rather than relying on client code (even a subclass) to be careful
about such things.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to