Gentle folk -

I believe that I've stumbled across a bug in the PNGRenderer's 'setOutputDirectory' method. If the user has set an output file on the user agent, but the file doesn't include an extension, a StringIndexOutOfBoundsException is thrown when the PNGRenderer attempts to deduce the "file prefix" to be used for the various pages, causing the rendering attempt to fail.

This isn't likely to be an issue under many circumstances, since users will frequently specify the file name using an extension (e.g., "/Volumes/Stuff/ProjectReport.png"), but if the user is accustomed to working on an OS that doesn't mandate file extensions (e.g., OS X), this problem could come up, and it's reasonably easy to resolve.

I've got a patch (see the attached file), but I'm trying to be a "good citizen" and check with the list before I submit it through Bugzilla, as indicated on the FOP web site. (I've already checked for this issue being previously reported, and I've been able to find no matching entries.)

Any comments/ideas?

Thanks!

-mjh
--
Matthew J. Healy
Department of Computer Science, RIT
102 Lomb Memorial Drive, Rochester, NY 14623
mailto:[EMAIL PROTECTED]
http://www.cs.rit.edu/~mjh
Voice: (585) 248-3425
Index: src/java/org/apache/fop/render/bitmap/PNGRenderer.java
===================================================================
--- src/java/org/apache/fop/render/bitmap/PNGRenderer.java      (revision 
451410)
+++ src/java/org/apache/fop/render/bitmap/PNGRenderer.java      (working copy)
@@ -74,7 +74,7 @@
      * command line, or from the directory specified in configuration file. 
Also
      * sets the file name syntax, eg. "page"
      */
-    private void setOutputDirectory() {
+    private void setOutputDirectory() throws IOException {
 
         // the file provided on the command line
         File f = getUserAgent().getOutputFile();
@@ -88,10 +88,19 @@
             // extracting file name syntax
             String s = f.getName();
             int i = s.lastIndexOf(".");
-            if (s.charAt(i - 1) == '1') {
-                i--; // getting rid of the "1"
+            if ( i > 0 ) {
+                if (s.charAt(i - 1) == '1') {
+                    i--; // getting rid of the "1"
+                }
+                filePrefix = s.substring(0, i);
             }
-            filePrefix = s.substring(0, i);
+            else if ( i == -1 ) {
+                // No extension was present on the file name
+                filePrefix = s;
+            }
+            else {
+                throw new IOException( "Invalid file name specified" );
+            }
         }
 
     }

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to