I noticed this issue when trying to remove a set of layers I previously added on a multi-page PDF. I noticed it in version 2.0.6, but might be present in others.
Here is a stacktrace snippet:
Caused by: java.lang.ClassCastException: org.apache.pdfbox.cos.COSDictionary cannot be cast to org.apache.pdfbox.cos.COSObject
I looked at the source and saw the toDictionary method that seemed to be used in every other place so I just put in in place and it seems to have solved the issue.
I've uploaded the updated file, the one that I'm using, which you can review and include in your project if it's a valid fix.