-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Milestone
Description
Environment Information
Jruby version: jruby 9.2.17.0 (2.5.8) 2021-03-29 84d363d OpenJDK 64-Bit Server VM 25.282-b08 on 1.8.0_282-b08 +jit [linux-x86_64]
Operating system: Linux 9738431d2f6d 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64 GNU/Linux
Expected Behavior
The skeleton code is:
class TEST_CLASS
# Class method
def self.run
threads = []
some_array.each do |input|
threads << Thread.new do
obj = TEST_CLASS.new(input)
obj.process do |line|
yield line
end
end
end
end
# Instance methods
def initialize(input)
@input = input
end
# Prints a line unless the block returns false
def process
open(input).each do |line|
next unless yield line
puts line
end
end
end
TEST_CLASS.run do |line|
raw_date=line.split(/\s+/)[5..6].join(' ')
Date.parse(raw_date) <= Date.parse('2021-01-01')
end
When running that code under jruby, I expect the code to finish without exceptions
Actual Behavior
When running the above code under jruby, I get the following exception:
java.lang.ClassCastException: org.jruby.RubyNil cannot be cast to org.jruby.RubyMatchData
There are two things that fix the problem:
- Removing the call to
split - Moving the block inside TEST_CLASS like so:
...
def self.run
threads = []
some_array.each do |input|
threads << Thread.new do
obj = TEST_CLASS.new(input)
obj.process do |line|
raw_date=line.split(/\s+/)[5..6].join(' ')
Date.parse(raw_date) <= Date.parse('2021-01-01')
end
end
threads.each(&:join)
end
end
...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels