Skip to content

Commit

Permalink
[fix] infinite loop calling Java super from Ruby (jruby#7991)
Browse files Browse the repository at this point in the history
back-port of jruby#7990
  • Loading branch information
kares authored Oct 30, 2023
1 parent 3d0e806 commit 56eec66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ private static boolean isClassOrIncludedPrependedModule(final RubyModule methodS
RubyClass candidate = klass.getSuperClass();
while (candidate != null && (candidate.isIncluded() || candidate.isPrepended())) { // up till 'real' superclass
if (candidate == klass) return true;
candidate = candidate.getSuperClass();
}

return false;
Expand Down
20 changes: 20 additions & 0 deletions core/src/test/java/org/jruby/javasupport/TestJava.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.javasupport;

import java.lang.reflect.Method;
import java.text.SimpleDateFormat;

import org.jruby.*;
import org.jruby.exceptions.RaiseException;
Expand Down Expand Up @@ -140,4 +141,23 @@ public void testJavaConstructorExceptionHandling() throws Exception {
}
}

@Test
public void testOverrideNewOnConcreteJavaProxySubClassRegression() {
String script =
"class FormatImpl < java.text.SimpleDateFormat\n" +
" include Enumerable\n" +
" public_class_method :new\n" +
" class << self\n" +
" def new(thread_provider: true)\n" +
" super()\n" +
" end\n" +
" end\n" +
"end\n";

final Ruby runtime = Ruby.newInstance();
runtime.evalScriptlet(script);

assertNotNull(runtime.evalScriptlet("FormatImpl.new")); // used to cause an infinite loop
assertTrue(runtime.evalScriptlet("FormatImpl.new").toJava(Object.class) instanceof SimpleDateFormat);
}
}

0 comments on commit 56eec66

Please sign in to comment.