jhove icon indicating copy to clipboard operation
jhove copied to clipboard

Missing XML DTD/Entity file resource causes ClassCastException

Open carlwilson opened this issue 3 years ago • 3 comments

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

carlwilson avatar Jan 06 '22 23:01 carlwilson

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.

david-russo avatar Jan 09 '22 11:01 david-russo

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.

carlwilson avatar Jan 10 '22 10:01 carlwilson

Thanks Carl, this solves our problem

samalloing avatar Jan 14 '22 13:01 samalloing