summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorCharles Oliver Nutter <headius@headius.com>2020-01-08 15:59:02 -0600
committerCharles Oliver Nutter <headius@headius.com>2020-01-08 16:05:48 -0600
commit2221131dcf4df4953fe24d0052d0cc973e106881 (patch)
tree84d0d4492ed625ed5c2a01fe98a95319150886e2 /ext
parent1d49959958c7aa72e8152571372f911a2b821073 (diff)
downloadpsych-2221131dcf4df4953fe24d0052d0cc973e106881.tar.gz
Check for SnakeYAML version to confirm it's 1.21+
Fixes #428
Diffstat (limited to 'ext')
-rw-r--r--ext/java/org/jruby/ext/psych/PsychLibrary.java26
1 files changed, 25 insertions, 1 deletions
diff --git a/ext/java/org/jruby/ext/psych/PsychLibrary.java b/ext/java/org/jruby/ext/psych/PsychLibrary.java
index 9e53ce9..44f9415 100644
--- a/ext/java/org/jruby/ext/psych/PsychLibrary.java
+++ b/ext/java/org/jruby/ext/psych/PsychLibrary.java
@@ -44,8 +44,11 @@ import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;
+import org.yaml.snakeyaml.error.Mark;
public class PsychLibrary implements Library {
+ private static final String DUMMY_VERSION = "0.0";
+
public void load(final Ruby runtime, boolean wrap) {
RubyModule psych = runtime.defineModule("Psych");
@@ -57,12 +60,33 @@ public class PsychLibrary implements Library {
catch( IOException e ) {
// ignored
}
- String snakeyamlVersion = props.getProperty("version", "0.0");
+ String snakeyamlVersion = props.getProperty("version", DUMMY_VERSION);
if (snakeyamlVersion.endsWith("-SNAPSHOT")) {
snakeyamlVersion = snakeyamlVersion.substring(0, snakeyamlVersion.length() - "-SNAPSHOT".length());
}
+ // Try to determine if we have a new enough SnakeYAML.
+ // Versions before 1.21 removed a Mark constructor that JRuby uses.
+ // See https://github.com/bundler/bundler/issues/6878
+ if (snakeyamlVersion.equals(DUMMY_VERSION)) {
+ try {
+ // Use reflection to try to confirm we have a new enough version
+ Mark.class.getConstructor(String.class, int.class, int.class, int.class, int[].class, int.class);
+ } catch (NoSuchMethodException nsme) {
+ throw runtime.newLoadError("bad SnakeYAML version, required 1.21 or higher; check your CLASSPATH for a conflicting jar");
+ }
+ } else {
+ // Parse version string to check for 1.21+
+ String[] majorMinor = snakeyamlVersion.split("\\.");
+
+ if (majorMinor.length < 2 || Integer.parseInt(majorMinor[0]) < 1 || Integer.parseInt(majorMinor[1]) < 21) {
+ throw runtime.newLoadError(
+ "bad SnakeYAML version " + snakeyamlVersion +
+ ", required 1.21 or higher; check your CLASSPATH for a conflicting jar");
+ }
+ }
+
RubyString version = runtime.newString(snakeyamlVersion + ".0");
version.setFrozen(true);
psych.setConstant("SNAKEYAML_VERSION", version);