Skip to content

Commit 93b0f0b

Browse files
committed
JRubyScriptUtils defensively handles null Nodes in findClassNode (fails against JRuby 1.7.12 otherwise)
Issue: SPR-11747 (cherry picked from commit adb616b)
1 parent 27b2ed1 commit 93b0f0b

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

spring-context/src/main/java/org/springframework/scripting/jruby/JRubyScriptUtils.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525

2626
import org.jruby.Ruby;
2727
import org.jruby.RubyArray;
28-
import org.jruby.RubyException;
2928
import org.jruby.RubyNil;
3029
import org.jruby.ast.ClassNode;
3130
import org.jruby.ast.Colon2Node;
@@ -116,10 +115,12 @@ private static String findClassName(Node rootNode) {
116115

117116
/**
118117
* Find the first {@link ClassNode} under the supplied {@link Node}.
119-
* @return the found {@code ClassNode}, or {@code null}
120-
* if no {@link ClassNode} is found
118+
* @return the corresponding {@code ClassNode}, or {@code null} if none found
121119
*/
122120
private static ClassNode findClassNode(Node node) {
121+
if (node == null) {
122+
return null;
123+
}
123124
if (node instanceof ClassNode) {
124125
return (ClassNode) node;
125126
}
@@ -229,9 +230,6 @@ private Object convertFromRubyArray(IRubyObject[] rubyArray, Class<?> returnType
229230
/**
230231
* Exception thrown in response to a JRuby {@link RaiseException}
231232
* being thrown from a JRuby method invocation.
232-
* <p>Introduced because the {@code RaiseException} class does not
233-
* have useful {@link Object#toString()}, {@link Throwable#getMessage()},
234-
* and {@link Throwable#printStackTrace} implementations.
235233
*/
236234
@SuppressWarnings("serial")
237235
public static class JRubyExecutionException extends NestedRuntimeException {
@@ -242,12 +240,7 @@ public static class JRubyExecutionException extends NestedRuntimeException {
242240
* @param ex the cause (must not be {@code null})
243241
*/
244242
public JRubyExecutionException(RaiseException ex) {
245-
super(buildMessage(ex), ex);
246-
}
247-
248-
private static String buildMessage(RaiseException ex) {
249-
RubyException rubyEx = ex.getException();
250-
return (rubyEx != null && rubyEx.message != null) ? rubyEx.message.toString() : "Unexpected JRuby error";
243+
super(ex.getMessage(), ex);
251244
}
252245
}
253246

0 commit comments

Comments
 (0)