Bug 40655 - [PATCH] Failure in PNGRenderer when output file name is missing an extension
Summary: [PATCH] Failure in PNGRenderer when output file name is missing an extension
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: general (show other bugs)
Version: trunk
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-02 08:37 UTC by Matt Healy
Modified: 2012-04-01 06:39 UTC (History)
0 users



Attachments
Patch for PNGRenderer, adding handling of files without extensions (2.89 KB, patch)
2006-10-02 08:38 UTC, Matt Healy
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Healy 2006-10-02 08:37:38 UTC
Overview Description: 
If the user has set an output file on a 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 unexpectedly.

The attached patch will allow a file name missing an extension to be used in its
entirety as the prefix for pages being rendered.


Steps to Reproduce: 

1) Create a FOPFactory object.
     FopFactory fopFactory = FopFactory.newInstance();

2) Create an FOUserAgent object.
     org.apache.fop.apps.FOUserAgent agent = fopFactory.newFOUserAgent();

3) Set the "output file" for the agent, making sure that the file name does not
include an extension.
     agent.setOutputFile( new java.io.File( "/var/tmp/ProjectSummaryReport" ) );

4) Create a Fop object, using the configured agent, and targeting PNG as the
output format.
     Fop fop = fopFactory.newFop( org.apache.fop.apps.MimeConstants.MIME_PNG, out );

5) Use the Fop object to try to render an FO document.

Actual Results: 

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 unexpectedly.

Expected Results:

Either the renderer should accept the file name (e.g., "ProjectSummaryReport")
as the full prefix, or else it should throw an exception (probably IOException,
given the context) to indicate that an inappropriate output file has been
specified.  


Build Date & Platform: 

Subversion repository version 451762, on Mac OS X 10.4.7.  (29Sep06)

Additional Builds and Platforms: 

Issue also occurs under Solaris and Windows, and should presumably arise
anywhere this is attempted.


Additional information:

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 place as high a premium on file extensions (e.g., OS X) and
is using an existing file as the basis for the output being generated by the
renderer, this problem could come up. 

During discussion on the mailing list, Andreas Delmelle suggested that the
renderer should probably not accept alternate extensions (i.e., other than
".png").  This changes is also included in the attached patch.
Comment 1 Matt Healy 2006-10-02 08:38:48 UTC
Created attachment 18951 [details]
Patch for PNGRenderer, adding handling of files without extensions
Comment 2 Simon Pepping 2006-10-09 03:34:56 UTC
Patch applied in revision 454331. Thanks.
Comment 3 Glenn Adams 2012-04-01 06:39:22 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed