You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Chris Fesler <cf...@fesler.org> on 2003/04/11 02:52:50 UTC

[PATCH] JspC.java (tomcat_4_branch) silently swallowed IOExceptions

In org.apache.jasper.JspC, IOExceptions in the methods initWebXml()
and completeWebXml(), IOExceptions are silently swallowed. This can,
obviously, be problematic--I discoverd this when I wrote an ant
script that neglected to create the directory where the web.xml
fragment was to be created. The ensuing exception was swallowed, and
JspC.java silently carried on, without generating a web.xml fragment.

Annoying.

To remedy the problem, I would've liked to have the two methods simply
throw IOException. Unfortunately, the calling method, execute() deals
explicitly with IOExceptions in between the calls to initWebXml() and
completeWebXml(), which would've left execute with an ugly trio of
try-catch blocks. So I did what seemed most expedient: I did not
change the exception handling in question except to log the
exceptions. At least that way I'd know what went wrong next time I
didn't create a directory, or ran out of disk space, or whatever.

Having decided to simply increase the noise level, I was faced with the
question of what mechanism to use to inform the user of the problem.
I discovered that there seem to be four distinct logging mechanisms in
use in JspC.java.

1) log.println() where log is a static member with package visibility,
set via setLog()

2) System.out.println()

3) System.err.println()

4) org.apache.jasper.Constants.message(), which takes a key and looks
in a ResourceBundle, etc.

I considered using (4), but decided that before I went to the trouble,
I'd check with this list, and simply did (3) instead, which had the
advantage of being darned simple.

If I thought it would be helpful (i.e., if somebody indicates that it
would end up in CVS), I'd happily undertake cleaning up the logging in
this file by adding various error messages to
resources/messages.properties and using Constants.message().
Unfortunately, I can't handle the translation duties :)

Anyway, here's a patch that makes some noise when there's an
IOException when writing the web.xml fragment.

Chris Fesler
cf-lists@fesler.org

patch follows
-------------

Index: JspC.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.12.2.6
diff -u -r1.12.2.6 JspC.java
--- JspC.java   17 Mar 2003 20:53:39 -0000      1.12.2.6
+++ JspC.java   10 Apr 2003 23:35:19 -0000
@@ -713,6 +713,9 @@
                 mapout.write(Constants.getString("jspc.webinc.header"));
             }
         } catch (IOException ioe) {
+            log.println("IOException initializing web.xml fragment: ["
+                    + ioe.getMessage() + "] abandoning effort to write "
+                    + "web.xml fragment and carrying on.");
             mapout = null;
             servletout = null;
             mappingout = null;
@@ -731,7 +734,10 @@
                 }
                 mapout.close();
             } catch (IOException ioe) {
-                // noting to do if it fails since we are done with it
+                // nothing to do if it fails since we are done with it
+                log.println("IOException writing web.xml fragment: ["
+                        + ioe.getMessage() + "]. File may not be valid; "
+                        + "you'll probably want to check.");
             }
         }
     }


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