Skip to content

Commit

Permalink
[ji] allow for initialize() to be a valid Java method (been deprecate…
Browse files Browse the repository at this point in the history
…d all way back to 1.7)

fixes #1408
  • Loading branch information
kares committed Apr 19, 2016
1 parent 61212e8 commit 00ef1b8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Expand Up @@ -2951,11 +2951,6 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound

// Deprecated methods below this line

@Deprecated
public IRubyObject initialize() {
return getRuntime().getNil();
}

@Deprecated
protected RubyBasicObject(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted) {
this(runtime, metaClass, useObjectSpace);
Expand Down
28 changes: 28 additions & 0 deletions spec/jrubyc/java/constructor_spec.rb
Expand Up @@ -117,4 +117,32 @@ def generate(script)
end

end

describe "with an initialize() Java method override" do
it "generates correct method despite initialize name" do
# java.beans.beancontext.BeanContextSupport
cls = generate("class BeanContext < RubyObject; def initialize(); end;" +
" java_signature 'void initialize()'; def init(); end; end").classes[0]

init = cls.methods[0]

expect( init.name ).to eql 'initialize'
expect( init.constructor? ).to be true
expect( init.args.length ).to eql 0

init = cls.methods[1]

expect( init.name ).to eql 'init'
expect( init.constructor? ).to be false
expect( init.args.length ).to eql 0

java = init.to_s
expect( java.index('public void initialize()') ).to_not be nil

puts cls.to_s if $VERBOSE

javac_status = javac_compile_contents(cls.to_s, 'BeanContext.java')
raise 'javac failed (see above output)' unless javac_status
end
end
end
16 changes: 15 additions & 1 deletion spec/jrubyc/spec_helper.rb
@@ -1,4 +1,18 @@
require_relative '../java_integration/spec_helper'

require 'jruby'
require 'jruby/compiler'
require 'jruby/compiler'

def javac_compile_contents(string, filename)
require 'tmpdir' ; Dir.mktmpdir('jrubyc') do |tmpdir|
file_path = File.join(tmpdir, filename)
File.open(file_path, 'w') { |f| f << string }

compiler = javax.tools.ToolProvider.getSystemJavaCompiler
fmanager = compiler.getStandardFileManager(nil, nil, nil)
diagnostics = nil
units = fmanager.getJavaFileObjectsFromStrings( [ file_path ] )
compilation_task = compiler.getTask(nil, fmanager, diagnostics, nil, nil, units)
compilation_task.call # returns boolean
end
end

0 comments on commit 00ef1b8

Please sign in to comment.