Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e485ef3be2b1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e17321e627f3
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Jun 12, 2018

  1. Copy the full SHA
    f032670 View commit details
  2. Copy the full SHA
    e17321e View commit details
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -281,7 +281,12 @@ private static RubyArray entriesCommon(ThreadContext context, String path) {
private static final String[] NO_FILES = StringSupport.EMPTY_STRING_ARRAY;

private static String[] getEntries(ThreadContext context, FileResource dir, String path) {
if (!dir.isDirectory()) throw context.runtime.newErrnoENOENTError("No such directory: " + path);
if (!dir.isDirectory()) {
if (dir.exists()) {
throw context.runtime.newErrnoENOTDIRError(path);
}
throw context.runtime.newErrnoENOENTError(path);
}
if (!dir.canRead()) throw context.runtime.newErrnoEACCESError(path);

String[] list = dir.list();
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/embed/jsr223/JRubyEngine.java
Original file line number Diff line number Diff line change
@@ -214,7 +214,8 @@ public Object invokeMethod(Object receiver, String method, Object... args)
}
return container.callMethod(receiver, method, args, Object.class);
} catch (Exception e) {
if (e.getCause().getMessage().contains("undefined method")) {
if (e.getCause() != null && e.getCause().getMessage() != null
&& e.getCause().getMessage().contains("undefined method")) {
throw wrapMethodException(e);
}
throw wrapException(e);
@@ -239,7 +240,8 @@ public Object invokeFunction(String method, Object... args)
}
return container.callMethod(container.getProvider().getRuntime().getTopSelf(), method, args, Object.class);
} catch (Exception e) {
if (e.getCause().getMessage().contains("undefined method")) {
if (e.getCause() != null && e.getCause().getMessage() != null
&& e.getCause().getMessage().contains("undefined method")) {
throw wrapMethodException(e);
}
throw wrapException(e);
30 changes: 30 additions & 0 deletions core/src/test/java/org/jruby/embed/jsr223/JRubyEngineTest.java
Original file line number Diff line number Diff line change
@@ -616,6 +616,21 @@ public void testInvokeMethod() throws Exception {
instance.getBindings(ScriptContext.ENGINE_SCOPE).clear();
}

/**
* Test of invokeMethod method throwing an exception with a null message.
*/
@Test
public void testInvokeMethodWithJavaException() throws Exception {
ScriptEngine instance = newScriptEngine();
instance.eval("def trigger_npe\nraise java.lang.NullPointerException.new\nend");
try {
Object result = ((Invocable) instance).invokeMethod(Object.class,"trigger_npe", null);
fail("Expected javax.script.ScriptException");
} catch (javax.script.ScriptException sex) {
// javax.script.ScriptException is expected
}
}

/**
* Test of invokeFunction method, of class Jsr223JRubyEngine.
*/
@@ -642,6 +657,21 @@ public void testInvokeFunction() throws Exception {
instance.getBindings(ScriptContext.ENGINE_SCOPE).clear();
}

/**
* Test of invokeFunction method throwing an exception with a null message.
*/
@Test
public void testInvokeFunctionWithJavaException() throws Exception {
ScriptEngine instance = newScriptEngine();
instance.eval("def trigger_npe\nraise java.lang.NullPointerException.new\nend");
try {
Object result = ((Invocable) instance).invokeFunction("trigger_npe", null);
fail("Expected javax.script.ScriptException");
} catch (javax.script.ScriptException sex) {
// javax.script.ScriptException is expected
}
}

/**
* Test of getInterface method, of class Jsr223JRubyEngine.
*/