summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2016-05-20 22:05:00 +0000
committerAndreas Beeker <kiwiwings@apache.org>2016-05-20 22:05:00 +0000
commit65ebd480fe7d5b48e53207dee646bac11578bbe8 (patch)
tree6680dcb5838552f4eba0566f7558501ef83043cc /src
parent1ccc643be20dcfef5bdeb4d399a32e4da77f8915 (diff)
downloadpoi-65ebd480fe7d5b48e53207dee646bac11578bbe8.tar.gz
poi-65ebd480fe7d5b48e53207dee646bac11578bbe8.zip
findbugs fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1744802 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java30
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java56
3 files changed, 32 insertions, 58 deletions
diff --git a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
index a42815a07e..b936a54760 100644
--- a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
+++ b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
@@ -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 {
@@ -69,15 +67,9 @@ 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();
+ String[] sheetNames = new String[_sharedSheetsByName.size()];
+ _sharedSheetsByName.keySet().toArray(sheetNames);
+ 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;
- }
- }
}
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
index 5c8b9b9697..0e710a159e 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
@@ -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);
}
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java b/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
index 505ea127b7..fc945c7ff5 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/forked/TestForkedEvaluator.java
@@ -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;
-
-/**
- * @author Josh Micich
- */
-public final class TestForkedEvaluator extends TestCase {
+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();
+
/**
* 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 {
- 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;
- }
+ 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));
+ } finally {
+ wb.close();
}
}
}