]> source.dussan.org Git - poi.git/commitdiff
Fix for bug 46385 (by patch 46362 from Matsuyama Tomohiro) fixed serialization of...
authorJosh Micich <josh@apache.org>
Tue, 16 Dec 2008 05:44:32 +0000 (05:44 +0000)
committerJosh Micich <josh@apache.org>
Tue, 16 Dec 2008 05:44:32 +0000 (05:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@726969 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/StandardRecord.java
src/java/org/apache/poi/hssf/record/StyleRecord.java
src/testcases/org/apache/poi/hssf/record/TestStyleRecord.java

index 8af6deb5a8d48fbf26babd619386525a4ea0f666..b1e0956750dc6000799b9e80c5bb75723d2ab442 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46385 - (also patch 46362) fix serialization of StyleRecord with unicode name</action>
            <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
            <action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
            <action dev="POI-DEVELOPERS" type="fix">Fixed XSSFCell to properly handle cell references with column numbers up to XFD</action>
index d939d90113401750c8982482caab805659b84c8f..cc08e74ee14365095a39280bf9e479d4361f38c5 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46385 - (also patch 46362) fix serialization of StyleRecord with unicode name</action>
            <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
            <action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
            <action dev="POI-DEVELOPERS" type="fix">Fixed XSSFCell to properly handle cell references with column numbers up to XFD</action>
index b94c3f8164cdd4abe7a4478462c5885aa2012539..d26f11a10b903d9348e805dcb8fbdf2ef88b20a8 100644 (file)
@@ -40,7 +40,8 @@ public abstract class StandardRecord extends Record {
                out.writeShort(dataSize);\r
                serialize(out);\r
                if (out.getWriteIndex() - offset != recSize) {\r
-                       throw new IllegalStateException("Incorrect number of bytes written - expected " \r
+                       throw new IllegalStateException("Error in serialization of (" + getClass().getName() + "): "\r
+                                       + "Incorrect number of bytes written - expected " \r
                                        + recSize + " but got " + (out.getWriteIndex() - offset));\r
                }\r
                return recSize;\r
index f9541d59393d0f5b9364fae206f19951ad48f581..ef2f703617f95d663e9a1580045a95d7a689f6cd 100644 (file)
@@ -173,7 +173,11 @@ public final class StyleRecord extends StandardRecord {
                } else {
                        out.writeShort(field_4_name.length());
                        out.writeByte(field_3_stringHasMultibyte ? 0x01 : 0x00);
-                       StringUtil.putCompressedUnicode(getName(), out);
+                       if (field_3_stringHasMultibyte) {
+                               StringUtil.putUnicodeLE(getName(), out);
+                       } else {
+                               StringUtil.putCompressedUnicode(getName(), out);
+                       }
                }
        }
 
index bfe11dd3a8b00f06cc1af31788ed07f782118bc7..cce5dab0a8ada7116b55495d3f1989375410733d 100644 (file)
 \r
 package org.apache.poi.hssf.record;\r
 \r
+import junit.framework.AssertionFailedError;\r
 import junit.framework.TestCase;\r
+\r
+import org.apache.poi.util.HexRead;\r
+\r
 /**\r
- * \r
+ * Tests for {@link StyleRecord}\r
  */\r
 public final class TestStyleRecord extends TestCase {\r
-    public void testUnicodeReadName() {\r
-       byte[] data = {\r
-                       17, 0, 9, 0, 1, 56, 94, -60, -119, 95, 0, 83, 0, 104, 0, 101, 0, 101, 0, 116, 0, 49, 0, 92, 40, //92, 36                        \r
-       };\r
-       RecordInputStream in = TestcaseRecordInputStream.create(StyleRecord.sid, data);\r
-       StyleRecord sr = new StyleRecord(in);\r
-       assertEquals("\u5E38\u89C4_Sheet1", sr.getName()); // "<Conventional>_Sheet1"\r
-    }\r
+       public void testUnicodeReadName() {\r
+               byte[] data = HexRead.readFromString(\r
+                               "11 00 09 00 01 38 5E C4 89 5F 00 53 00 68 00 65 00 65 00 74 00 31 00");\r
+               RecordInputStream in = TestcaseRecordInputStream.create(StyleRecord.sid, data);\r
+               StyleRecord sr = new StyleRecord(in);\r
+               assertEquals("\u5E38\u89C4_Sheet1", sr.getName()); // "<Conventional>_Sheet1"\r
+               byte[] ser;\r
+               try {\r
+                       ser = sr.serialize();\r
+               } catch (IllegalStateException e) {\r
+                       if (e.getMessage().equals("Incorrect number of bytes written - expected 27 but got 18")) {\r
+                               throw new AssertionFailedError("Identified bug 46385");\r
+                       }\r
+                       throw e;\r
+               }\r
+               TestcaseRecordInputStream.confirmRecordEncoding(StyleRecord.sid, data, ser);\r
+       }\r
 }\r