aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2009-03-25 17:22:06 +0000
committerNick Burch <nick@apache.org>2009-03-25 17:22:06 +0000
commit34bd8dd94da8df50284d569fc31848992a3154c3 (patch)
tree2754ebe9640daac17e7b4d532e81388ce2ab2d6d
parent5e947a3a6a44c4769c388a8e31b40a1fbd13bf10 (diff)
downloadpoi-34bd8dd94da8df50284d569fc31848992a3154c3.tar.gz
poi-34bd8dd94da8df50284d569fc31848992a3154c3.zip
Fix the block allocation test, but still leave the recent blocks hssf bug fixed
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@758353 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java14
-rw-r--r--src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java2
2 files changed, 11 insertions, 5 deletions
diff --git a/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java b/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java
index 19873c08fd..60ce199ee5 100644
--- a/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java
+++ b/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java
@@ -186,6 +186,7 @@ public class BlockAllocationTableReader
List blocks = new ArrayList();
int currentBlock = startBlock;
boolean firstPass = true;
+ ListManagedBlock dataBlock = null;
// Process the chain from the start to the end
// Normally we have header, data, end
@@ -193,16 +194,21 @@ public class BlockAllocationTableReader
// For those cases, stop at the header, not the end
while (currentBlock != POIFSConstants.END_OF_CHAIN) {
try {
- blocks.add(blockList.remove(currentBlock));
+ // Grab the data at the current block offset
+ dataBlock = blockList.remove(currentBlock);
+ blocks.add(dataBlock);
+ // Now figure out which block we go to next
currentBlock = _entries.get(currentBlock);
+ firstPass = false;
} catch(IOException e) {
if(currentBlock == headerPropertiesStartBlock) {
// Special case where things are in the wrong order
System.err.println("Warning, header block comes after data blocks in POIFS block listing");
currentBlock = POIFSConstants.END_OF_CHAIN;
- } else if(currentBlock == 0) {
+ } else if(currentBlock == 0 && firstPass) {
// Special case where the termination isn't done right
- System.err.println("Warning, incorrectly terminated data blocks in POIFS block listing (should end at -2, ended at 0)");
+ // on an empty set
+ System.err.println("Warning, incorrectly terminated empty data blocks in POIFS block listing (should end at -2, ended at 0)");
currentBlock = POIFSConstants.END_OF_CHAIN;
} else {
// Ripple up
@@ -212,7 +218,7 @@ public class BlockAllocationTableReader
}
return ( ListManagedBlock [] ) blocks
- .toArray(new ListManagedBlock[ 0 ]);
+ .toArray(new ListManagedBlock[ blocks.size() ]);
}
// methods for debugging reader
diff --git a/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java b/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java
index d688ce1459..b2042319ce 100644
--- a/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java
+++ b/src/testcases/org/apache/poi/poifs/storage/TestBlockAllocationTableReader.java
@@ -1329,7 +1329,7 @@ public class TestBlockAllocationTableReader
if (expected_length[ j ] == -1)
{
- fail("document " + j + " should have failed");
+ fail("document " + j + " should have failed, but found a length of " + dataBlocks.length);
}
else
{