Precompiled class raises exception, but in interpreted mode - works well.
-------------------------------------------------------------------------

                 Key: JRUBY-6025
                 URL: https://jira.codehaus.org/browse/JRUBY-6025
             Project: JRuby
          Issue Type: Bug
          Components: Compiler
    Affects Versions: JRuby 1.6.4, JRuby 1.6.3, JRuby 1.7
         Environment: Windows 7 SP1 x64, Java 1.6.0_21-b07, JRuby 1.6.3 & JRuby 
1.6.4 & JRuby 1.7.0 snapshot from 26.08.11
            Reporter: Maxim Sokolovsky
         Attachments: Mock.java, test2.rb

I'm trying to use [JMonkeyEngine3|http://jmonkeyengine.org] framework with 
JRuby and stumbled on exceptions, running precompiled code. You can reproduce 
error with files in attachment, no other files needed.
{code:title=Mock.java|borderStyle=solid}
public abstract class Mock {
    public Mock() {
      System.out.println("Mock constructor invoked.");  
    }
    
    public void start() {
      System.out.println("start() method invoked from Mock class.\nInvoking 
callbackMethod() from main class...");
      callbackMethod();
    }
    
    public void callbackMethod() {
      System.out.println("callbackMethod() invoked from Mock object!");
    }
}
{code}
{code:title=test2.rb|borderStyle=solid}
require 'java'
import 'Mock'

class Test2 < Mock
  java_signature 'public static void main(String[])'
  def self.main(args)
    puts "main(args) method from child class started."
    app = Test2.new
    app.start()
  end

  java_signature 'public void callbackMethod()'
  def callbackMethod()
    puts "callbackMethod from child class started."
  end
end

puts "Static code from bottom of child file started."
Test2.main(ARGV)
{code}

Running in interpreted mode works well:
{noformat}
C:\aXe1\dev\ruby\test\jruby>jruby test2.rb
Static code from bottom of child file started.
main(args) method from child class started.
Mock constructor invoked.
start() method invoked from Mock class.
Invoking callbackMethod() from main class...
callbackMethod from child class started.
{noformat}
Then I removed two last lines in 'test2.rb', cause main(String[]) method should 
be invoked automatically, according to [GeneratingJavaClasses wiki 
page|https://github.com/jruby/jruby/wiki/GeneratingJavaClasses]. Running 
precompiled throws an exception:
{noformat}
C:\aXe1\dev\ruby\test\jruby>jrubyc --javac test2.rb

C:\aXe1\dev\ruby\test\jruby>java -cp .;jruby-complete-1.7.0.dev.jar Test2
main(args) method from child class started.
Mock constructor invoked.
Exception in thread "main" java.lang.ClassCastException: Test2 cannot be cast to
 org.jruby.java.proxies.JavaProxy
        at org.jruby.java.proxies.ConcreteJavaProxy$3.needsCreate(ConcreteJavaPr
oxy.java:88)
        at org.jruby.java.proxies.ConcreteJavaProxy$3.call(ConcreteJavaProxy.jav
a:137)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSi
te.java:292)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:
135)
        at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:63)
        at org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123)
        at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
        at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
        at org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.ja
va:75)
        at org.jruby.internal.runtime.methods.InterpretedMethod.call(Interpreted
Method.java:190)
        at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.j
ava:179)
        at org.jruby.RubyClass.finvoke(RubyClass.java:691)
        at org.jruby.javasupport.util.RuntimeHelpers.invoke(RuntimeHelpers.java:
544)
        at Test2.main(Test2.java:80)
{noformat}
If I leave last lines uncommented, then it work one time and then tries to 
start again and throw same exception. So I think trouble is in some runtime 
class bootstraping.
{noformat}
C:\aXe1\dev\ruby\test\jruby>jrubyc --javac test2.rb

C:\aXe1\dev\ruby\test\jruby>java -cp .;jruby-complete-1.7.0.dev.jar Test2
Static code from bottom of child file started.
main(args) method from child class started.
Mock constructor invoked.
start() method invoked from Mock class.
Invoking callbackMethod() from main class...
callbackMethod from child class started.
main(args) method from child class started.
Mock constructor invoked.
Exception in thread "main" java.lang.ClassCastException: Test2 cannot be cast to
 org.jruby.java.proxies.JavaProxy
        at org.jruby.java.proxies.ConcreteJavaProxy$3.needsCreate(ConcreteJavaPr
oxy.java:88)
        at org.jruby.java.proxies.ConcreteJavaProxy$3.call(ConcreteJavaProxy.jav
a:137)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:
133)
        at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:63)
        at org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123)
        at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
        at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
        at org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.ja
va:75)
        at org.jruby.internal.runtime.methods.InterpretedMethod.call(Interpreted
Method.java:190)
        at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.j
ava:179)
        at org.jruby.RubyClass.finvoke(RubyClass.java:691)
        at org.jruby.javasupport.util.RuntimeHelpers.invoke(RuntimeHelpers.java:
544)
        at Test2.main(Test2.java:80)
{noformat}
I think this as a bug of JRuby, cause behavior of interpreted and precompiled 
code differences.
Also this is true both for 1.8 and 1.9 modes.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to