aboutsummaryrefslogtreecommitdiffstats
path: root/poi-integration
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-08-07 16:18:46 +0000
committerDominik Stadler <centic@apache.org>2023-08-07 16:18:46 +0000
commit8e40aabb187903a8d8cf60d6bbff23d3023751a6 (patch)
treeb4fdb670de0c2b6d33ce2e44c4308c168393d49f /poi-integration
parent738d533a83669b1335cbd9a069c3491bc05aae1f (diff)
downloadpoi-8e40aabb187903a8d8cf60d6bbff23d3023751a6.tar.gz
poi-8e40aabb187903a8d8cf60d6bbff23d3023751a6.zip
Bug 66425: Avoid a ClassCastException found via oss-fuzz
We try to avoid throwing ClassCastException, but it was possible to trigger one here with a specially crafted input-file Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61259 Also fix handling of NullPointerException git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911517 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-integration')
-rw-r--r--poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
index ed96cde4e8..5171158965 100644
--- a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
+++ b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
@@ -253,13 +253,22 @@ public class TestAllFiles {
Exception e = assertThrows((Class<? extends Exception>)exClass, exec, errPrefix + " expected " + exClass);
String actMsg = pathReplace(e.getMessage());
- // verify that message is either null for both or set for both
- assertTrue(actMsg != null || StringUtils.isBlank(exMessage),
- errPrefix + " for " + exClass + " expected message '" + exMessage + "' but had '" + actMsg + "'");
-
- if (actMsg != null) {
- assertTrue(actMsg.contains(exMessage),
- errPrefix + "Message: " + actMsg + " - didn't contain: " + exMessage);
+ // perform special handling of NullPointerException as
+ // JDK started to add more information in some newer JDK, so
+ // it sometimes has a message and sometimes not!
+ if (NullPointerException.class.isAssignableFrom(exClass)) {
+ if (actMsg != null) {
+ assertTrue(actMsg.contains(exMessage), errPrefix + "Message: "+actMsg+" - didn't contain: "+exMessage);
+ }
+ } else {
+ // verify that message is either null for both or set for both
+ assertTrue(actMsg != null || StringUtils.isBlank(exMessage),
+ errPrefix + " for " + exClass + " expected message '" + exMessage + "' but had '" + actMsg + "'");
+
+ if (actMsg != null) {
+ assertTrue(actMsg.contains(exMessage),
+ errPrefix + "Message: " + actMsg + " - didn't contain: " + exMessage);
+ }
}
} else {
assertDoesNotThrow(exec, errPrefix);