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: f3c8d37b5cd2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9cca7536ce0a
Choose a head ref
  • 7 commits
  • 8 files changed
  • 1 contributor

Commits on Mar 30, 2016

  1. Copy the full SHA
    028d16b View commit details
  2. Copy the full SHA
    83f8aad View commit details
  3. Copy the full SHA
    1124ec5 View commit details
  4. Copy the full SHA
    6a603ee View commit details
  5. Copy the full SHA
    9a9d590 View commit details
  6. Copy the full SHA
    e316a9a View commit details
  7. Copy the full SHA
    9cca753 View commit details
15 changes: 15 additions & 0 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -383,6 +383,21 @@ private static void fill(IRubyObject[]arr, int from, int to, IRubyObject with) {
}
}

/**
* Increases the capacity of this <tt>Array</tt>, if necessary.
* @param minCapacity the desired minimum capacity of the internal array
*/
public void ensureCapacity(int minCapacity) {
if ( isShared || (values.length - begin) < minCapacity ) {
final int len = this.realLength;
int newCapacity = minCapacity > len ? minCapacity : len;
IRubyObject[] values = new IRubyObject[newCapacity];
System.arraycopy(this.values, begin, values, 0, len);
this.values = values;
this.begin = 0;
}
}

private static final void checkLength(Ruby runtime, long length) {
if (length < 0) {
throw runtime.newArgumentError("negative array size (or size too big)");
29 changes: 15 additions & 14 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
@@ -152,26 +152,27 @@ public IRubyObject message(ThreadContext context) {
*@return A RubyString containing the debug information.
*/
@JRubyMethod(name = "inspect")
public IRubyObject inspect(ThreadContext context) {
public RubyString inspect(ThreadContext context) {
// rb_class_name skips intermediate classes (JRUBY-6786)
RubyModule rubyClass = getMetaClass().getRealClass();
String rubyClass = getMetaClass().getRealClass().getName();
RubyString exception = RubyString.objAsString(context, this);

if (exception.isEmpty()) return getRuntime().newString(rubyClass.getName());
StringBuilder sb = new StringBuilder("#<");
sb.append(rubyClass.getName()).append(": ").append(exception.getByteList()).append('>');
return getRuntime().newString(sb.toString());
if (exception.isEmpty()) return context.runtime.newString(rubyClass);

return RubyString.newString(context.runtime, new StringBuilder(2 + rubyClass.length() + 2 + exception.size() + 1).
append("#<").append(rubyClass).append(": ").append(exception.getByteList()).append('>')
);
}

@JRubyMethod(name = "==")
@Override
public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
@JRubyMethod(name = "==")
public RubyBoolean op_equal(ThreadContext context, IRubyObject other) {
if (this == other) return context.runtime.getTrue();

boolean equal = context.runtime.getException().isInstance(other) &&
getMetaClass().getRealClass() == other.getMetaClass().getRealClass() &&
callMethod(context, "message").equals(other.callMethod(context, "message")) &&
callMethod(context, "backtrace").equals(other.callMethod(context, "backtrace")) &&
getMetaClass().getRealClass() == other.getMetaClass().getRealClass();
callMethod(context, "backtrace").equals(other.callMethod(context, "backtrace"));
return context.runtime.newBoolean(equal);
}

@@ -307,16 +308,16 @@ public void printBacktrace(PrintStream errorStream, int skip) {
}

private void printStackTraceLine(PrintStream errorStream, IRubyObject stackTraceLine) {
errorStream.print("\tfrom " + stackTraceLine + '\n');
errorStream.print("\tfrom " + stackTraceLine + '\n');
}

private boolean isArrayOfStrings(IRubyObject backtrace) {
if (!(backtrace instanceof RubyArray)) return false;

IRubyObject[] elements = ((RubyArray) backtrace).toJavaArray();
final RubyArray rTrace = ((RubyArray) backtrace);

for (int i = 0 ; i < elements.length ; i++) {
if (!(elements[i] instanceof RubyString)) return false;
for (int i = 0 ; i < rTrace.getLength() ; i++) {
if (!(rTrace.eltInternal(i) instanceof RubyString)) return false;
}

return true;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/javasupport/JavaConstructor.java
Original file line number Diff line number Diff line change
@@ -140,8 +140,8 @@ public RubyString inspect() {
str.append("#<");
str.append( getType().toString() );
inspectParameterTypes(str, this);
str.append(">");
return getRuntime().newString( str.toString() );
str.append('>');
return RubyString.newString(getRuntime(), str);
}

//@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/javasupport/JavaMethod.java
Original file line number Diff line number Diff line change
@@ -567,8 +567,8 @@ public RubyString inspect() {
str.append("#<");
str.append( getType().toString() ).append('/').append(method.getName());
inspectParameterTypes(str, this);
str.append(">");
return getRuntime().newString( str.toString() );
str.append('>');
return RubyString.newString(getRuntime(), str);
}

@JRubyMethod(name = "static?")
Original file line number Diff line number Diff line change
@@ -367,8 +367,8 @@ public RubyString inspect() {
str.append("#<");
str.append( getDeclaringClass().nameOnInspection() ).append('/').append( getName() );
inspectParameterTypes(str, this);
str.append(">");
return getRuntime().newString( str.toString() );
str.append('>');
return RubyString.newString(getRuntime(), str);
}

@JRubyMethod(name = "invoke", rest = true)
Original file line number Diff line number Diff line change
@@ -144,8 +144,8 @@ public RubyString inspect() {
str.append("#<");
str.append( getDeclaringClass().nameOnInspection() );
inspectParameterTypes(str, this);
str.append(">");
return getRuntime().newString( str.toString() );
str.append('>');
return RubyString.newString(getRuntime(), str);
}

@Override
52 changes: 51 additions & 1 deletion core/src/test/java/org/jruby/javasupport/TestJava.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.jruby.javasupport;

import java.lang.reflect.Method;

import org.jruby.RubyModule;
import org.jruby.RubyString;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.builtin.IRubyObject;
import org.junit.Test;

import org.jruby.Ruby;
@@ -9,7 +14,15 @@ class A {
public static class C extends B {}
}

class B extends A {}
class B extends A {
public B() {}

B(int param) {
if (param == -1) {
throw new IllegalStateException("param == -1");
}
}
}

public class TestJava extends junit.framework.TestCase {

@@ -73,4 +86,41 @@ private static interface FxRunnable2 extends Runnable { /* inherited run() */ }

private static interface NonFxRunnable extends Runnable { public void doRun() ; }

@Test
public void test_get_java_class() {
final Ruby runtime = Ruby.newInstance();
final RubyModule self = runtime.getJavaSupport().getJavaModule();
RubyString name;

name = runtime.newString("java.lang.Integer");
assert Java.get_java_class(self, name) != null;

try {
name = runtime.newString("java.lang.BOGUS22");
Java.get_java_class(self, name);
assert false;
}
catch (RaiseException ex) {
// assertNotNull(ex.getCause());
}
}

@Test
public void testJavaConstructorExceptionHandling() throws Exception {
final Ruby runtime = Ruby.newInstance();
JavaConstructor constructor = JavaConstructor.create(runtime, B.class.getDeclaredConstructor(int.class));
assert constructor.new_instance(new IRubyObject[] { runtime.newFixnum(0) }) != null;

assert constructor.new_instance(new Object[] { 1 }) != null;

try {
constructor.new_instance(new Object[0]);
assert false;
}
catch (RaiseException ex) {
assertEquals("(ArgumentError) wrong number of arguments (0 for 1)", ex.getMessage());
assertNull(ex.getCause());
}
}

}
9 changes: 7 additions & 2 deletions test/jruby/test_timeout.rb
Original file line number Diff line number Diff line change
@@ -3,8 +3,11 @@
require 'socket'
require 'net/http'

class TestTimeout < Test::Unit::TestCase
require 'test/jruby/test_helper'

class TestTimeout < Test::Unit::TestCase
include TestHelper

def test_timeout_for_loop
n = 10000000
assert_raises(Timeout::Error) do
@@ -81,7 +84,9 @@ def test_net_http_timeout

def test_timeout_raises_anon_class_to_unroll
begin
timeout(0.1) { foo }
quiet do
timeout(0.1) { foo }
end
rescue Timeout::Error
ok = true
end