From a3b1385736b868178b6be1ad5d1c3ad2ea2cf567 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sat, 29 Oct 2011 22:00:42 +0000 Subject: [PATCH] replace exception with warning update test case git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195053 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hpsf/ClipboardData.java | 19 +++++++++++++++---- .../org/apache/poi/hpsf/basic/TestWrite.java | 13 +++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/ClipboardData.java b/src/java/org/apache/poi/hpsf/ClipboardData.java index cf04733efa..42ce724a94 100644 --- a/src/java/org/apache/poi/hpsf/ClipboardData.java +++ b/src/java/org/apache/poi/hpsf/ClipboardData.java @@ -21,10 +21,15 @@ import java.io.OutputStream; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; @Internal class ClipboardData { + private static final POILogger logger = POILogFactory + .getLogger( ClipboardData.class ); + private int _format; private byte[] _value; @@ -33,9 +38,16 @@ class ClipboardData int size = LittleEndian.getInt( data, offset ); if ( size < 4 ) - throw new IllegalPropertySetDataException( - "ClipboardData size less than 4 bytes " - + "(doesn't even have format field!)" ); + { + logger.log( POILogger.WARN, "ClipboardData at offset ", + Integer.valueOf( offset ), " size less than 4 bytes " + + "(doesn't even have format field!). " + + "Setting to format == 0 and hope for the best" ); + _format = 0; + _value = new byte[0]; + return; + } + _format = LittleEndian.getInt( data, offset + LittleEndian.INT_SIZE ); _value = LittleEndian.getByteArray( data, offset + LittleEndian.INT_SIZE * 2, size - LittleEndian.INT_SIZE ); @@ -57,7 +69,6 @@ class ClipboardData LittleEndian.putInt( result, 0 * LittleEndian.INT_SIZE, LittleEndian.INT_SIZE + _value.length ); LittleEndian.putInt( result, 1 * LittleEndian.INT_SIZE, _format ); - LittleEndian.putInt( result, 2 * LittleEndian.INT_SIZE, _value.length ); System.arraycopy( _value, 0, result, LittleEndian.INT_SIZE + LittleEndian.INT_SIZE, _value.length ); return result; diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java index 9fe4d202f4..f651a4df32 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java @@ -36,7 +36,7 @@ import java.util.Map; import junit.framework.Assert; import junit.framework.TestCase; - +import org.apache.poi.POIDataSamples; import org.apache.poi.hpsf.ClassID; import org.apache.poi.hpsf.Constants; import org.apache.poi.hpsf.HPSFRuntimeException; @@ -63,7 +63,6 @@ import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.TempFile; -import org.apache.poi.POIDataSamples; /** *

Tests HPSF's writing functionality.

@@ -377,14 +376,8 @@ public class TestWrite extends TestCase check(Variant.VT_EMPTY, null, codepage); check(Variant.VT_BOOL, Boolean.TRUE, codepage); check(Variant.VT_BOOL, Boolean.FALSE, codepage); - check(Variant.VT_CF, new byte[]{0}, codepage); - check(Variant.VT_CF, new byte[]{0, 1}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2, 3}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage); - check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage); + check( Variant.VT_CF, new byte[] { 8, 0, 0, 0, 1, 0, 0, 0, 1, 2, 3, + 4 }, codepage ); check(Variant.VT_I4, Integer.valueOf(27), codepage); check(Variant.VT_I8, Long.valueOf(28), codepage); check(Variant.VT_R8, new Double(29.0), codepage);