Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing XML DTD/Entity file resource causes ClassCastException #700

Open
carlwilson opened this issue Jan 6, 2022 · 3 comments · May be fixed by #701
Open

Missing XML DTD/Entity file resource causes ClassCastException #700

carlwilson opened this issue Jan 6, 2022 · 3 comments · May be fixed by #701
Assignees
Labels
bug A product defect that needs fixing P1 High priority issues to be scheduled in the upcoming release

Comments

@carlwilson
Copy link
Member

carlwilson commented Jan 6, 2022

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 carlwilson added bug A product defect that needs fixing P1 High priority issues to be scheduled in the upcoming release labels Jan 6, 2022
@carlwilson carlwilson self-assigned this Jan 6, 2022
@carlwilson carlwilson linked a pull request Jan 6, 2022 that will close this issue
@david-russo
Copy link
Member

david-russo commented Jan 9, 2022

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.

@carlwilson
Copy link
Member Author

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.

@samalloing
Copy link
Collaborator

Thanks Carl, this solves our problem

@carlwilson carlwilson modified the milestone: JHOVE 1.26 Apr 6, 2022
@carlwilson carlwilson added this to the JHOVE 1.28 milestone Jun 16, 2022
@carlwilson carlwilson modified the milestones: JHOVE 1.28, OPF Hackathon 2023 Tasks Jun 21, 2023
@carlwilson carlwilson removed this from the OPF Hackathon 2023 Tasks milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A product defect that needs fixing P1 High priority issues to be scheduled in the upcoming release
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants