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

[bug] java.lang.UnsupportedClassVersionError: org/cyberneko/dtd/DTDConfiguration #2887

Closed
malcolm-pro opened this issue May 22, 2023 · 12 comments · Fixed by #2890
Closed

[bug] java.lang.UnsupportedClassVersionError: org/cyberneko/dtd/DTDConfiguration #2887

malcolm-pro opened this issue May 22, 2023 · 12 comments · Fixed by #2890

Comments

@malcolm-pro
Copy link

We've been seeing this error under Java 8 starting with v1.14:

java.lang.UnsupportedClassVersionError: org/cyberneko/dtd/DTDConfiguration has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

That's a pretty common error when trying to run libraries compiled for Java 11 under Java 8. It looks like this is due to the newer nekodtd jar. I might have missed something, but I don't see any minimum Java version requirements listed, so I've been assuming Nokogiri is still compatible with Java 8. If this is the case, maybe this jar needs to be recompiled under Java 8? If this is not the case, and Nokogiri 1.14+ needs Java 11:

  1. could that be listed in the main Readme?
  2. is there a way to recompile just this library locally for Java 8 and use that in the gem?
  3. if not, will force_ruby_platform: true in the Gemfile/gemspec avoid loading this JAR?

FWIW, JRuby did mention in the 9.3.0.0 release notes that they're considering dropping Java 8 support, and Java 8 is quite long in the tooth, but afaik Java 8 is still supported (and as of last year was still quite widely used).

@malcolm-pro malcolm-pro added the state/needs-triage Inbox for non-installation-related bug reports or help requests label May 22, 2023
@flavorjones
Copy link
Member

flavorjones commented May 23, 2023

@malcolm-pro Sorry you're having problems!

I will admit to a very low level of knowledge around Java version support in JRuby and in the vendored Java libraries.

That said, the vendored nekodtd.jar was built by the Nokogiri maintainers from https://github.com/sparklemotion/nekodtd (for context see #2437 and sparklemotion/nekodtd#1), so I may be able to build it in such a way that it still supports Java 8. I will probably need help, though!

cc @headius in case you're able to point me in the right direction.

@flavorjones flavorjones added platform/jruby and removed state/needs-triage Inbox for non-installation-related bug reports or help requests labels May 23, 2023
@flavorjones
Copy link
Member

flavorjones commented May 23, 2023

OK, so I rebuilt nekodtd with Java 8 (using thejruby:9.4-jdk8 docker image) and ran into more issues:

ext/java/nokogiri/internals/NokogiriXPathFunction.java:33: error: NokogiriXPathFunction is not abstract and does not override abstract method evaluate(List) in XPathFunction
public class NokogiriXPathFunction implements XPathFunction
       ^
ext/java/nokogiri/internals/NokogiriXPathFunction.java:55: error: name clash: evaluate(List<?>) in NokogiriXPathFunction and evaluate(List) in XPathFunction have the same erasure, yet neither overrides the other
  evaluate(List<?> args) throws XPathFunctionException
  ^
ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java:482: warning: [deprecation] isWhiteSpace(String) in XMLCharacterRecognizer has been deprecated
          suppressNode &= XMLCharacterRecognizer.isWhiteSpace(n.getNodeValue());
                                                ^
2 errors

which again are under the Nokogiri maintainers' control, but I'm not excited about doing this work since I'm not a JRuby user and don't honestly know if this is actually a problem for anyone (you're the first person to ask about Java 8 support).

@headius WDYT about restoring support for Java 8? Is it worth the additional maintenance burden?

@flavorjones flavorjones mentioned this issue May 23, 2023
4 tasks
@headius
Copy link
Contributor

headius commented May 23, 2023

@flavorjones We are planning to drop 8 for JRuby 9.5+ but that is several months away and we'd still support 9.4 at least through next year. It's probably worth it.

I can help if you can give me a workflow that will result in the errors above.

@flavorjones
Copy link
Member

@headius Thanks for the context and the offer.

I have a CI pipeline that I'm trying to get working at #2889.

The above error may be a red herring -- it happens if I compile Nokogiri with Java 8 ... however I think I can still compile with Java 11 and it will run on Java 8. The CI pipeline will tell me if I'm wrong, and in that case I'll need your help.

@malcolm-pro
Copy link
Author

@flavorjones I'd also be happy to work on this if you can give me the build/test steps that you're using; I've been de-facto managing the JVM ecosystem (JRuby/Java/Scala) at our company for several years now and have a little cross-compatibility experience.

@flavorjones
Copy link
Member

New org.nokogiri:nekodtd version cut, v0.1.11.noko2, Information at sparklemotion/nekodtd#2

flavorjones added a commit that referenced this issue May 23, 2023
which is built with Java 8 to address #2887
flavorjones added a commit that referenced this issue May 23, 2023
which is built with Java 8 to address #2887
@flavorjones
Copy link
Member

Presuming #2889 goes green, then #2890 is a backport to v1.14.x and I intend to cut a v1.14.5 release with it.

flavorjones added a commit that referenced this issue May 24, 2023
which is built with Java 8 to address #2887
@flavorjones flavorjones added this to the v1.14.x patch releases milestone May 24, 2023
@flavorjones
Copy link
Member

https://github.com/sparklemotion/nokogiri/releases/tag/v1.14.5 has been released with this fixed. v1.15.2 will ship shortly.

@flavorjones
Copy link
Member

@headius
Copy link
Contributor

headius commented May 24, 2023

Great news, thanks @flavorjones!

@flavorjones
Copy link
Member

@headius You're welcome! It was an easier fix than I'd anticipated 🎉

@malcolm-pro
Copy link
Author

@flavorjones This was a mini-masterclass in efficient & well-covered project management. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants