Skip to content

Commit

Permalink
Fix jruby being epically weird
Browse files Browse the repository at this point in the history
Need to submit this as a bug to jruby
  • Loading branch information
albus522 committed Dec 29, 2017
1 parent 5d3374a commit f37ca9e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/delayed/psych_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
case object.tag
when %r{^!ruby/object}
result = super
if defined?(ActiveRecord::Base) && result.is_a?(ActiveRecord::Base)
if jruby_is_seriously_borked && result.is_a?(ActiveRecord::Base)
klass = result.class
id = result[klass.primary_key]
begin
Expand Down Expand Up @@ -78,6 +78,13 @@ def visit_Psych_Nodes_Mapping(object) # rubocop:disable CyclomaticComplexity, Me
end
end

# defined? is triggering something really messed up in
# jruby causing both the if AND else clauses to execute,
# however if the check is run here, everything is fine
def jruby_is_seriously_borked
defined?(ActiveRecord::Base)
end

def resolve_class(klass_name)
return nil if !klass_name || klass_name.empty?
klass_name.constantize
Expand Down

6 comments on commit f37ca9e

@kares
Copy link

@kares kares commented on f37ca9e May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey David, guess you do not recall which JRUBY_VERSION was this about?

@albus522
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- jruby-9.1.15.0

@albus522
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albus522
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My best guess is that there is a weird interaction with raising an error in the if clause that gets rescued by the defined? call triggering the else block after the if block is run

@kares
Copy link

@kares kares commented on f37ca9e May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks David, will look into that and if it persist on JRuby master ... report - since this looks like a weird bug.

@kares
Copy link

@kares kares commented on f37ca9e May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reference (anyone reading here), here's the result: #1031

Please sign in to comment.