JRubyScriptUtils defensively handles null Nodes in findClassNode (fails against JRuby 1.7.12 otherwise)

Issue: SPR-11747
master
Juergen Hoeller 11 years ago
parent c124d3b6c6
commit adb616b67b
  1. 19
      spring-context/src/main/java/org/springframework/scripting/jruby/JRubyScriptUtils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,6 @@ import java.util.List;
import org.jruby.Ruby; import org.jruby.Ruby;
import org.jruby.RubyArray; import org.jruby.RubyArray;
import org.jruby.RubyException;
import org.jruby.RubyNil; import org.jruby.RubyNil;
import org.jruby.ast.ClassNode; import org.jruby.ast.ClassNode;
import org.jruby.ast.Colon2Node; import org.jruby.ast.Colon2Node;
@ -116,10 +115,12 @@ public abstract class JRubyScriptUtils {
/** /**
* Find the first {@link ClassNode} under the supplied {@link Node}. * Find the first {@link ClassNode} under the supplied {@link Node}.
* @return the found {@code ClassNode}, or {@code null} * @return the corresponding {@code ClassNode}, or {@code null} if none found
* if no {@link ClassNode} is found
*/ */
private static ClassNode findClassNode(Node node) { private static ClassNode findClassNode(Node node) {
if (node == null) {
return null;
}
if (node instanceof ClassNode) { if (node instanceof ClassNode) {
return (ClassNode) node; return (ClassNode) node;
} }
@ -229,9 +230,6 @@ public abstract class JRubyScriptUtils {
/** /**
* Exception thrown in response to a JRuby {@link RaiseException} * Exception thrown in response to a JRuby {@link RaiseException}
* being thrown from a JRuby method invocation. * being thrown from a JRuby method invocation.
* <p>Introduced because the {@code RaiseException} class does not
* have useful {@link Object#toString()}, {@link Throwable#getMessage()},
* and {@link Throwable#printStackTrace} implementations.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public static class JRubyExecutionException extends NestedRuntimeException { public static class JRubyExecutionException extends NestedRuntimeException {
@ -242,12 +240,7 @@ public abstract class JRubyScriptUtils {
* @param ex the cause (must not be {@code null}) * @param ex the cause (must not be {@code null})
*/ */
public JRubyExecutionException(RaiseException ex) { public JRubyExecutionException(RaiseException ex) {
super(buildMessage(ex), ex); super(ex.getMessage(), ex);
}
private static String buildMessage(RaiseException ex) {
RubyException rubyEx = ex.getException();
return (rubyEx != null && rubyEx.message != null) ? rubyEx.message.toString() : "Unexpected JRuby error";
} }
} }

Loading…
Cancel
Save