resolved null pointer exception

Former-commit-id: 3cc97c878a2bcc09c8a2cea3802278974d56b954
This commit is contained in:
Jeremy Long
2014-12-08 05:41:58 -05:00
parent 3e6787fd61
commit 589c761cb0

View File

@@ -291,17 +291,20 @@ public class ReportGenerator {
* @throws Exception is thrown when an exception occurs. * @throws Exception is thrown when an exception occurs.
*/ */
protected void generateReport(String templateName, String outFileName) throws Exception { protected void generateReport(String templateName, String outFileName) throws Exception {
final File outDir = new File(outFileName).getParentFile(); File outFile = new File(outFileName);
if (!outDir.exists()) { if (outFile.getParentFile() == null) {
final boolean created = outDir.mkdirs(); outFile = new File(".", outFileName);
}
if (!outFile.getParentFile().exists()) {
final boolean created = outFile.getParentFile().mkdirs();
if (!created) { if (!created) {
throw new Exception("Unable to create directory '" + outDir.getAbsolutePath() + "'."); throw new Exception("Unable to create directory '" + outFile.getParentFile().getAbsolutePath() + "'.");
} }
} }
OutputStream outputSteam = null; OutputStream outputSteam = null;
try { try {
outputSteam = new FileOutputStream(outFileName); outputSteam = new FileOutputStream(outFile);
generateReport(templateName, outputSteam); generateReport(templateName, outputSteam);
} finally { } finally {
if (outputSteam != null) { if (outputSteam != null) {