Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance workaround for WeakMap with jruby >= 9.4.6.0 #2360

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iaddict
Copy link

@iaddict iaddict commented Feb 21, 2024

Since jruby 9.4.6.0 the missing methods on ObjectSpace::WeakMap have been implemented.

See: jruby/jruby#6683

Without this fix the gem does not work on jruby 9.4.6.0.

Since jruby 9.4.6.0 the missing methods on ObjectSpace::WeakMap have been implemented.

See: jruby/jruby#6683
…ound

Enhance workaround for WeakMap with jruby >= 9.4.6.0
@laumacirule
Copy link

While pending on a new version, for the activerecord-oracle_enhanced-adapter 6.1.6 that we are currently using, we implemented a temporary workaround to rescue the NameError in lib/active_record/connection_adapters/oracle_enhanced_adapter.rb

begin
  load File.expand_path("active_record/connection_adapters/oracle_enhanced_adapter.rb", $:.grep(/oracle_enhanced/).first)
rescue NameError => e
  raise e unless e.message =~ /undefined field 'map'/
end

@rammpeter
Copy link
Contributor

rammpeter commented Jun 18, 2024

Another workaround to patch the gem each time after fresh install like in CI pipelines:
add this snippet as last step in RAILS_ROOT/config/boot.rb

# Workaround to avoid the error: undefined field 'map' for class 'Java::OrgJruby::RubyObjectSpace::WeakMap'
# with oracle-enhanced-adapter 6.1.6 and JRuby 9.4.6.0 and following versions
# Prevent execution of the code block in the if statement by comparing RUBY_ENGINE with a not existing value
# This patches the gem each time it is installed again
# Peter Ramm, 2024-06-18

gem_path = Gem::Specification.find_by_name('activerecord-oracle_enhanced-adapter').gem_dir
file_path = File.join(gem_path, 'lib', 'active_record', 'connection_adapters', 'oracle_enhanced_adapter.rb')
content = File.read(file_path)
new_content = content.gsub("if RUBY_ENGINE == \"jruby\"", "if RUBY_ENGINE == \"xjruby\"")
File.open(file_path, 'w') { |file| file.write(new_content) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants