Author: tilman Date: Fri Jun 14 08:27:44 2024 New Revision: 1918311 URL: http://svn.apache.org/viewvc?rev=1918311&view=rev Log: PDFBOX-5839: avoid ClassCastException and NPE
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java?rev=1918311&r1=1918310&r2=1918311&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java Fri Jun 14 08:27:44 2024 @@ -154,6 +154,10 @@ public class PDOptionalContentProperties for (COSBase o : ocgs) { COSDictionary ocg = toDictionary(o); + if (ocg == null) + { + continue; + } String groupName = ocg.getString(COSName.NAME); if (groupName.equals(name)) { @@ -273,6 +277,10 @@ public class PDOptionalContentProperties for (COSBase o : ocgs) { COSDictionary ocg = toDictionary(o); + if (ocg == null) + { + continue; + } String name = ocg.getString(COSName.NAME); if (groupName.equals(name) && isGroupEnabled(new PDOptionalContentGroup(ocg))) { @@ -333,14 +341,20 @@ public class PDOptionalContentProperties private COSDictionary toDictionary(COSBase o) { + COSBase base; if (o instanceof COSObject) { - return (COSDictionary)((COSObject)o).getObject(); + base = ((COSObject) o).getObject(); } else { - return (COSDictionary)o; + base = o; } + if (base instanceof COSDictionary) + { + return (COSDictionary) base; + } + return null; } /** @@ -358,6 +372,10 @@ public class PDOptionalContentProperties for (COSBase o : ocgs) { COSDictionary ocg = toDictionary(o); + if (ocg == null) + { + continue; + } String name = ocg.getString(COSName.NAME); if (groupName.equals(name) && setGroupEnabled(new PDOptionalContentGroup(ocg), enable)) {