aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2020-09-09 07:05:09 +0000
committerPJ Fanning <fanningpj@apache.org>2020-09-09 07:05:09 +0000
commit6c7bf59087e720a663fc5aec7ec5b2d502d7accd (patch)
treecd12ee2991b5c56d674f0d3a19e78a95029326fc /src/testcases/org
parentcced1751114e089ed23e0932ffea6c1cdac12bb3 (diff)
downloadpoi-6c7bf59087e720a663fc5aec7ec5b2d502d7accd.tar.gz
poi-6c7bf59087e720a663fc5aec7ec5b2d502d7accd.zip
[bug-64721] NullPointerException occurs when calling getDataSize() of an object created with ExtRst.copy(). Thanks to Kwon Ohyoung
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881582 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
index 9837459393..f1016745bb 100644
--- a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
+++ b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
@@ -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);