findbugs fix

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1767473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-11-01 10:29:02 +00:00
parent e620194a20
commit af2d473d00
2 changed files with 48 additions and 74 deletions

View File

@ -17,27 +17,19 @@
package org.apache.poi.ss.excelant;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Locale;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
/**
* Ant task class for testing Excel workbook cells.
*
* @author Jon Svede ( jon [at] loquatic [dot] com )
* @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
*
*/
public class ExcelAntTask extends Task {
@ -99,19 +91,14 @@ public class ExcelAntTask extends Task {
log( "Using input file: " + excelFileName, Project.MSG_INFO ) ;
Workbook targetWorkbook = loadWorkbook() ;
if( targetWorkbook == null ) {
log( "Unable to load " + excelFileName +
". Verify the file exists and can be read.",
Project.MSG_ERR ) ;
return ;
}
if( tests.size() > 0 ) {
workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
for (ExcelAntTest test : tests) {
log("executing test: " + test.getName(), Project.MSG_DEBUG);
if (workbookUtil == null) {
workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
}
for (ExcelAntUserDefinedFunction eaUdf : functions) {
try {
@ -140,26 +127,11 @@ public class ExcelAntTask extends Task {
workbookUtil = null;
}
log( successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO ) ;
workbookUtil = null ;
}
}
private Workbook loadWorkbook() {
if (excelFileName == null) {
throw new BuildException("fileName attribute must be set!",
getLocation());
}
File workbookFile = new File( excelFileName ) ;
try {
FileInputStream fis = new FileInputStream( workbookFile ) ;
return WorkbookFactory.create( fis ) ;
} catch (Exception e) {
throw new BuildException("Cannot load file " + excelFileName
+ ". Make sure the path and file permissions are correct.", e, getLocation());
if( !tests.isEmpty() ) {
log( successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO );
}
workbookUtil = null;
}

View File

@ -91,10 +91,12 @@ public class ExcelAntWorkbookUtil extends Typedef {
* @throws BuildException If the workbook cannot be loaded.
*/
private Workbook loadWorkbook() {
if (excelFileName == null) {
throw new BuildException("fileName attribute must be set!", getLocation());
}
File workbookFile = new File(excelFileName);
try {
FileInputStream fis = new FileInputStream(workbookFile);
FileInputStream fis = new FileInputStream(excelFileName);
try {
workbook = WorkbookFactory.create(fis);
} finally {