We try to avoid throwing NullPointerException, but it was possible to trigger one here git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912281 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_4
@@ -90,8 +90,9 @@ public class XSSFChartSheet extends XSSFSheet { | |||
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); | |||
xmlOptions.setSaveSyntheticDocumentElement( | |||
new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet")); | |||
chartsheet.save(out, xmlOptions); | |||
if (chartsheet != null) { | |||
chartsheet.save(out, xmlOptions); | |||
} | |||
} | |||
private static byte[] blankWorksheet(){ |
@@ -351,4 +351,12 @@ public final class TestWorkbookFactory { | |||
return false; | |||
} | |||
} | |||
@Test | |||
void testEncryptionNullPointerException() throws IOException { | |||
assertThrows(IllegalArgumentException.class, | |||
() -> WorkbookFactory.create(POIDataSamples.getSpreadSheetInstance(). | |||
openResourceAsStream( | |||
"crash-9bf3cd4bd6f50a8a9339d363c2c7af14b536865c.xlsx"))); | |||
} | |||
} |
@@ -252,9 +252,15 @@ public final class CryptoFunctions { | |||
if (cipherAlgorithm == CipherAlgorithm.rc4) { | |||
cipher = Cipher.getInstance(cipherAlgorithm.jceId); | |||
} else if (cipherAlgorithm.needsBouncyCastle) { | |||
if (chain == null) { | |||
throw new IllegalArgumentException("Did not have a chain for cipher " + cipherAlgorithm); | |||
} | |||
registerBouncyCastle(); | |||
cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding, "BC"); | |||
} else { | |||
if (chain == null) { | |||
throw new IllegalArgumentException("Did not have a chain for cipher " + cipherAlgorithm); | |||
} | |||
cipher = Cipher.getInstance(cipherAlgorithm.jceId + "/" + chain.jceId + "/" + padding); | |||
} | |||