<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">28231 - For apparently truncated files, which are somehow still valid, now issue a truncation warning but carry on, rather than giving an exception as before</action>
<action dev="POI-DEVELOPERS" type="fix">44504 - Added initial support for recognising external functions like YEARFRAC and ISEVEN (using NameXPtg), via LinkTable support</action>
<action dev="POI-DEVELOPERS" type="fix">44504 - Improvements to FormulaParser - operators, precedence, error literals, quotes in string literals, range checking on IntPtg, formulas with extra un-parsed stuff at the end, improved parse error handling</action>
<action dev="POI-DEVELOPERS" type="fix">44504 - Fixed number conversion inconsistencies in many functions, and improved RefEval</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">44504 - Added initial support for recognising external functions like YEARFRAC and ISEVEN (using NameXPtg), via LinkTable support</action>
+ <action dev="POI-DEVELOPERS" type="fix">44504 - Improvements to FormulaParser - operators, precedence, error literals, quotes in string literals, range checking on IntPtg, formulas with extra un-parsed stuff at the end, improved parse error handling</action>
+ <action dev="POI-DEVELOPERS" type="fix">44504 - Fixed number conversion inconsistencies in many functions, and improved RefEval</action>
<action dev="POI-DEVELOPERS" type="fix">44504 - Added initial support for recognising external functions like YEARFRAC and ISEVEN (using NameXPtg), via LinkTable support</action>
<action dev="POI-DEVELOPERS" type="fix">44504 - Improvements to FormulaParser - operators, precedence, error literals, quotes in string literals, range checking on IntPtg, formulas with extra un-parsed stuff at the end, improved parse error handling</action>
<action dev="POI-DEVELOPERS" type="fix">44504 - Fixed number conversion inconsistencies in many functions, and improved RefEval</action>
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import java.io.*;
{
private byte[] _data;
private boolean _eof;
+ private static POILogger log = POILogFactory.getLogger(RawDataBlock.class);
/**
* Constructor RawDataBlock
String type = " byte" + ((count == 1) ? ("")
: ("s"));
- throw new IOException("Unable to read entire block; " + count
- + type + " read before EOF; expected "
- + blockSize + " bytes");
+ log.log(POILogger.ERROR,
+ "Unable to read entire block; " + count
+ + type + " read before EOF; expected "
+ + blockSize + " bytes. Your document"
+ + " has probably been truncated!"
+ );
}
else {
_eof = false;
import java.io.*;
import java.util.Random;
+import org.apache.poi.util.DummyPOILogger;
+import org.apache.poi.util.POILogFactory;
+
import junit.framework.*;
/**
public TestRawDataBlock(String name)
{
super(name);
+
+ // We always want to use our own
+ // logger
+ System.setProperty(
+ "org.apache.poi.util.POILogger",
+ "org.apache.poi.util.DummyPOILogger"
+ );
}
/**
/**
* Test creating a short RawDataBlock
+ * Will trigger a warning, but no longer an IOException,
+ * as people seem to have "valid" truncated files
*/
-
- public void testShortConstructor()
+ public void testShortConstructor() throws Exception
{
- for (int k = 1; k < 512; k++)
+ // Get the logger to be used
+ DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
+ RawDataBlock.class
+ );
+ assertEquals(0, logger.logged.size());
+
+ // Test for various data sizes
+ for (int k = 1; k <= 512; k++)
{
byte[] data = new byte[ k ];
data[ j ] = ( byte ) j;
}
RawDataBlock block = null;
-
- try
- {
- block = new RawDataBlock(new ByteArrayInputStream(data));
- fail("Should have thrown IOException creating short block");
- }
- catch (IOException ignored)
- {
-
- // as expected
+
+ logger.reset();
+ assertEquals(0, logger.logged.size());
+
+ // Have it created
+ block = new RawDataBlock(new ByteArrayInputStream(data));
+ assertNotNull(block);
+
+ // Check for the warning is there for <512
+ if(k < 512) {
+ assertEquals(
+ "Warning on " + k + " byte short block",
+ 1, logger.logged.size()
+ );
+
+ // Build the expected warning message, and check
+ String bts = k + " byte";
+ if(k > 1) {
+ bts += "s";
+ }
+
+ assertEquals(
+ "7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document has probably been truncated!",
+ (String)(logger.logged.get(0))
+ );
+ } else {
+ assertEquals(0, logger.logged.size());
}
}
}
* incorrectly think that there's not enough data
*/
public void testSlowInputStream() throws Exception {
+ // Get the logger to be used
+ DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
+ RawDataBlock.class
+ );
+ assertEquals(0, logger.logged.size());
+
+ // Test for various ok data sizes
for (int k = 1; k < 512; k++) {
byte[] data = new byte[ 512 ];
for (int j = 0; j < data.length; j++) {
data[j] = (byte) j;
}
- // Shouldn't complain, as there is enough data
- try {
- RawDataBlock block =
- new RawDataBlock(new SlowInputStream(data, k));
- fail();
- } catch(IOException e) {
- // as expected
- }
+ logger.reset();
+ assertEquals(0, logger.logged.size());
+
+ // Should complain, as there isn't enough data
+ RawDataBlock block =
+ new RawDataBlock(new SlowInputStream(data, k));
+ assertNotNull(block);
+ assertEquals(
+ "Warning on " + k + " byte short block",
+ 1, logger.logged.size()
+ );
}
}
import java.io.*;
+import org.apache.poi.util.DummyPOILogger;
+import org.apache.poi.util.POILogFactory;
+
import junit.framework.*;
/**
public TestRawDataBlockList(String name)
{
super(name);
+
+ // We always want to use our own
+ // logger
+ System.setProperty(
+ "org.apache.poi.util.POILogger",
+ "org.apache.poi.util.DummyPOILogger"
+ );
}
/**
* Test creating a short RawDataBlockList
*/
- public void testShortConstructor()
+ public void testShortConstructor() throws Exception
{
+ // Get the logger to be used
+ DummyPOILogger logger = (DummyPOILogger)POILogFactory.getLogger(
+ RawDataBlock.class
+ );
+ assertEquals(0, logger.logged.size());
+
+ // Test for various short sizes
for (int k = 2049; k < 2560; k++)
{
byte[] data = new byte[ k ];
{
data[ j ] = ( byte ) j;
}
- try
- {
- new RawDataBlockList(new ByteArrayInputStream(data));
- fail("Should have thrown IOException creating short block");
- }
- catch (IOException ignored)
- {
- // as expected
- }
+ // Check we logged the error
+ logger.reset();
+ new RawDataBlockList(new ByteArrayInputStream(data));
+ assertEquals(1, logger.logged.size());
}
}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * POILogger which logs into an ArrayList, so that
+ * tests can see what got logged
+ */
+public class DummyPOILogger extends POILogger {
+ public List logged = new ArrayList();
+
+ public void reset() {
+ logged = new ArrayList();
+ }
+
+ public boolean check(int level) {
+ return true;
+ }
+
+ public void initialize(String cat) {}
+
+ public void log(int level, Object obj1) {
+ logged.add(new String(level + " - " + obj1));
+ }
+
+ public void log(int level, Object obj1, Throwable exception) {
+ logged.add(new String(level + " - " + obj1 + " - " + exception));
+ }
+}