findbugs fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1744802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-05-20 22:05:00 +00:00
parent e5393711b7
commit e58f6f3fb0
3 changed files with 31 additions and 57 deletions

View File

@ -34,8 +34,6 @@ import org.apache.poi.ss.usermodel.Workbook;
* Represents a workbook being used for forked evaluation. Most operations are delegated to the
* shared master workbook, except those that potentially involve cell values that may have been
* updated after a call to {@link #getOrCreateUpdatableCell(String, int, int)}.
*
* @author Josh Micich
*/
final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
@ -71,13 +69,7 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
public void copyUpdatedCells(Workbook workbook) {
String[] sheetNames = new String[_sharedSheetsByName.size()];
_sharedSheetsByName.keySet().toArray(sheetNames);
OrderedSheet[] oss = new OrderedSheet[sheetNames.length];
for (int i = 0; i < sheetNames.length; i++) {
String sheetName = sheetNames[i];
oss[i] = new OrderedSheet(sheetName, _masterBook.getSheetIndex(sheetName));
}
for (int i = 0; i < oss.length; i++) {
String sheetName = oss[i].getSheetName();
for (String sheetName : sheetNames) {
ForkedEvaluationSheet sheet = _sharedSheetsByName.get(sheetName);
sheet.copyUpdatedCells(workbook.getSheet(sheetName));
}
@ -144,20 +136,4 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
public UDFFinder getUDFFinder(){
return _masterBook.getUDFFinder();
}
private static final class OrderedSheet implements Comparable<OrderedSheet> {
private final String _sheetName;
private final int _index;
public OrderedSheet(String sheetName, int index) {
_sheetName = sheetName;
_index = index;
}
public String getSheetName() {
return _sheetName;
}
public int compareTo(OrderedSheet o) {
return _index - o._index;
}
}
}

View File

@ -96,8 +96,8 @@ public final class ListLevel
setStartAt( startAt );
_lvlf.setNfc( (byte) numberFormatCode );
_lvlf.setJc( (byte) alignment );
_grpprlChpx = numberProperties;
_grpprlPapx = entryProperties;
_grpprlChpx = numberProperties.clone();
_grpprlPapx = entryProperties.clone();
_xst = new Xst(numberText);
}

View File

@ -17,19 +17,24 @@
package org.apache.poi.ss.formula.eval.forked;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public final class TestForkedEvaluator {
@Rule
public ExpectedException expectedEx = ExpectedException.none();
/**
* @author Josh Micich
*/
public final class TestForkedEvaluator extends TestCase {
/**
* set up a calculation workbook with input cells nicely segregated on a
* sheet called "Inputs"
@ -53,7 +58,8 @@ public final class TestForkedEvaluator extends TestCase {
/**
* Shows a basic use-case for {@link ForkedEvaluator}
*/
public void testBasic() {
@Test
public void testBasic() throws IOException {
HSSFWorkbook wb = createWorkbook();
// The stability classifier is useful to reduce memory consumption of caching logic
@ -78,6 +84,8 @@ public final class TestForkedEvaluator extends TestCase {
assertEquals(4.0, ((NumberEval) fe2.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
fe1.updateCell("Inputs", 0, 0, new NumberEval(3.0));
assertEquals(13.9, ((NumberEval) fe1.evaluate("Calculations", 0, 0)).getNumberValue(), 0.0);
wb.close();
}
/**
@ -90,29 +98,19 @@ public final class TestForkedEvaluator extends TestCase {
* was considered less desirable because so far, the underlying 'master' workbook is strictly
* <i>read-only</i> with respect to the ForkedEvaluator.
*/
public void testMissingInputCell() {
@Test
public void testMissingInputCell() throws IOException {
expectedEx.expect(UnsupportedOperationException.class);
expectedEx.expectMessage("Underlying cell 'A2' is missing in master sheet.");
HSSFWorkbook wb = createWorkbook();
ForkedEvaluator fe = ForkedEvaluator.create(wb, null, null);
// attempt update input at cell A2 (which is missing)
try {
ForkedEvaluator fe = ForkedEvaluator.create(wb, null, null);
// attempt update input at cell A2 (which is missing)
fe.updateCell("Inputs", 1, 0, new NumberEval(4.0));
throw new AssertionFailedError(
"Expected exception to be thrown due to missing input cell");
} catch (NullPointerException e) {
StackTraceElement[] stes = e.getStackTrace();
if (stes[0].getMethodName().equals("getIdentityKey")) {
throw new AssertionFailedError("Identified bug with update of missing input cell");
}
throw e;
} catch (UnsupportedOperationException e) {
if (e.getMessage().equals(
"Underlying cell 'A2' is missing in master sheet.")) {
// expected during successful test
} else {
throw e;
}
} finally {
wb.close();
}
}
}