Skip to content

Commit 0e71076

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 a5606a6 commit 0e71076

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 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.
@@ -80,7 +80,7 @@ public static Object createJRubyObject(String scriptSource, Class<?>[] interface
8080
Ruby ruby = initializeRuntime();
8181

8282
Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
83-
// keep using the deprecated runNormally variant for JRuby 1.1/1.2 compatibility...
83+
// Keep using the deprecated runNormally variant for JRuby 1.1/1.2 compatibility...
8484
IRubyObject rubyObject = ruby.runNormally(scriptRootNode, false);
8585

8686
if (rubyObject instanceof RubyNil) {
@@ -118,10 +118,12 @@ private static String findClassName(Node rootNode) {
118118

119119
/**
120120
* Find the first {@link ClassNode} under the supplied {@link Node}.
121-
* @return the found {@code ClassNode}, or {@code null}
122-
* if no {@link ClassNode} is found
121+
* @return the corresponding {@code ClassNode}, or {@code null} if none found
123122
*/
124123
private static ClassNode findClassNode(Node node) {
124+
if (node == null) {
125+
return null;
126+
}
125127
if (node instanceof ClassNode) {
126128
return (ClassNode) node;
127129
}
@@ -230,8 +232,8 @@ private Object convertFromRubyArray(IRubyObject[] rubyArray, Class<?> returnType
230232
/**
231233
* Exception thrown in response to a JRuby {@link RaiseException}
232234
* being thrown from a JRuby method invocation.
233-
* <p>Introduced because the {@code RaiseException} class does not
234-
* have useful {@link Object#toString()}, {@link Throwable#getMessage()},
235+
* <p>Introduced because early versions of the {@code RaiseException} class did
236+
* not have useful {@link Object#toString()}, {@link Throwable#getMessage()},
235237
* and {@link Throwable#printStackTrace} implementations.
236238
*/
237239
@SuppressWarnings("serial")
@@ -248,7 +250,7 @@ public JRubyExecutionException(RaiseException ex) {
248250

249251
private static String buildMessage(RaiseException ex) {
250252
RubyException rubyEx = ex.getException();
251-
return (rubyEx != null && rubyEx.message != null) ? rubyEx.message.toString() : "Unexpected JRuby error";
253+
return (rubyEx != null && rubyEx.message != null ? rubyEx.message.toString() : "Unexpected JRuby error");
252254
}
253255
}
254256

0 commit comments

Comments
 (0)