]> source.dussan.org Git - poi.git/commitdiff
replace exception with warning
authorSergey Vladimirov <sergey@apache.org>
Sat, 29 Oct 2011 22:00:42 +0000 (22:00 +0000)
committerSergey Vladimirov <sergey@apache.org>
Sat, 29 Oct 2011 22:00:42 +0000 (22:00 +0000)
update test case

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195053 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hpsf/ClipboardData.java
src/testcases/org/apache/poi/hpsf/basic/TestWrite.java

index cf04733efa9a5a6ce4d31ee2a2e7364abcfabec5..42ce724a94591bd5169da5b3aba5dca9c621cc02 100644 (file)
@@ -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;
index 9fe4d202f4a8e164057810ec4abcf1414b5dc782..f651a4df32629c3aec734199b05f33a38761341f 100644 (file)
@@ -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;
 
 /**
  * <p>Tests HPSF's writing functionality.</p>
@@ -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);