[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
This commit is contained in:
PJ Fanning 2020-09-09 07:05:09 +00:00
parent cced175111
commit 6c7bf59087
3 changed files with 57 additions and 2 deletions

View 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'

View 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;

View 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);