jhove
jhove copied to clipboard
Missing XML DTD/Entity file resource causes ClassCastException
An XML file starting with a DTD declaration such as
<!DOCTYPE art SYSTEM "article.dtd">
causes the XML-hul
module to fail
and report a "Not well-formed" status:
Status: Not well-formed
ErrorMessage: SaxParseException: java.lang.ClassCastException: class sun.net.www.protocol.file.FileURLConnection cannot be cast to class java.net.HttpURLConnection(sun.net.www.protocol.file.FileURLConnection and java.net.HttpURLConnection are in module java.base of loader 'bootstrap'): SAXException cause: java.lang.ClassCastException
ID: XML-HUL-3
This is caused by a failure in the XMLModuleHandler.resolveEntity
method which fails to detect that the URL is a file type and then trys to cast the obj
variable, a FileURLConnection
instance, to HttpURLConnection
causing the exception.
This branch has the beginings of a fix. This takes a simpler approach, rather than casting the URL
instance it uses the URL.openStream
method. It also catches any IOException
and returns null
, to "require default behaviour".
Reported by @samalloing
Just as a heads up to help with any future merging, I think there is also a possibly less elegant fix for this in my XML module review PR.
Thanks @david-russo, we have a second pair of hands here at OPF towers and less on our plate. We will be working through the PRs here some this month.
Thanks Carl, this solves our problem