]> source.dussan.org Git - poi.git/commitdiff
[bug-64721] NullPointerException occurs when calling getDataSize() of an object creat...
authorPJ Fanning <fanningpj@apache.org>
Wed, 9 Sep 2020 07:05:09 +0000 (07:05 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 9 Sep 2020 07:05:09 +0000 (07:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881582 13f79535-47bb-0310-9956-ffa450edef68

build.gradle
src/java/org/apache/poi/hssf/record/common/ExtRst.java
src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java

index b8628215e324ea2fb7707c5fdb5bad06815aba56..fe6b24eff25192732b1f5b645d0b80192ce393d8 100644 (file)
@@ -127,7 +127,7 @@ subprojects {
         exclude '**/BaseTestCellUtil.class'
         exclude '**/TestUnfixedBugs.class'
         exclude '**/TestOneFile.class'
-
+include '**/TestUnicodeString.class'
         // Exclude Test Suites
         exclude '**/All*Tests.class'
         exclude '**/HSSFTests.class'
@@ -381,4 +381,4 @@ project('scratchpad') {
     }
 
     japicmp.baseline = "org.apache.poi:poi:${japicmpversion}@jar"
-}
\ No newline at end of file
+}
index 87e4887c521454c51f87cdbae7a34a59fdab9281..50f41dedae08932d7fbcce5b806018d6598a283a 100644 (file)
@@ -58,6 +58,7 @@ public class ExtRst implements Comparable<ExtRst>, GenericRecord {
     }
 
     protected ExtRst(ExtRst other) {
+        this();
         reserved = other.reserved;
         formattingFontIndex = other.formattingFontIndex;
         formattingOptions = other.formattingOptions;
index 9837459393b14a0d9bc033ddeb52b5b69be95f35..f1016745bbd351abe6d10921eaebf1896025db1a 100644 (file)
@@ -367,6 +367,60 @@ public final class TestUnicodeString {
         wb.close();
     }
 
+    @Test
+    public void copyExtRst() {
+        ExtRst ext = new ExtRst();
+
+        assertEquals(0, ext.getNumberOfRuns());
+        assertEquals(0, ext.getFormattingFontIndex());
+        assertEquals(0, ext.getFormattingOptions());
+        assertEquals("", ext.getPhoneticText());
+        assertEquals(0, ext.getPhRuns().length);
+        assertEquals(10, ext.getDataSize()); // Excludes 4 byte header
+
+        ExtRst copied = ext.copy();
+
+        assertEquals(0, copied.getNumberOfRuns());
+        assertEquals(0, copied.getFormattingFontIndex());
+        assertEquals(0, copied.getFormattingOptions());
+        assertEquals("", copied.getPhoneticText());
+        assertEquals(0, copied.getPhRuns().length);
+        assertEquals(10, copied.getDataSize());
+    }
+
+    @Test
+    public void copyExtRstFromData() {
+        byte[] data = new byte[]{
+                1, 0, 0x0C, 0,
+                0, 0, 0x37, 0,
+                0, 0,
+                0, 0, 0, 0,
+                0, 0 // Cruft at the end, as found from real files
+        };
+        assertEquals(16, data.length);
+
+        LittleEndianInputStream inp = new LittleEndianInputStream(
+                new ByteArrayInputStream(data)
+        );
+        ExtRst ext = new ExtRst(inp, data.length);
+        assertEquals(0x0c, ext.getDataSize()); // Excludes 4 byte header
+
+        assertEquals(0, ext.getNumberOfRuns());
+        assertEquals(0x37, ext.getFormattingOptions());
+        assertEquals(0, ext.getFormattingFontIndex());
+        assertEquals("", ext.getPhoneticText());
+        assertEquals(0, ext.getPhRuns().length);
+
+        ExtRst copied = ext.copy();
+        assertEquals(10, copied.getDataSize()); // Excludes 4 byte header
+
+        assertEquals(0, copied.getNumberOfRuns());
+        assertEquals(0x37, copied.getFormattingOptions());
+        assertEquals(0, copied.getFormattingFontIndex());
+        assertEquals("", copied.getPhoneticText());
+        assertEquals(0, copied.getPhRuns().length);
+    }
+
     private static UnicodeString makeUnicodeString(String s) {
         UnicodeString st = new UnicodeString(s);
         st.setOptionFlags((byte)0);