Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.6
-
Fix Version/s: JRuby 1.2
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:OSX 10.5.6, Rails 1.2.3, Rails 2.2.2, MRI 1.8.5
-
Testcase included:yes
Description
In an attempt to port a Rails 1.2.3 application to JRuby I encountered this message when the session was unmarshalled:
ArgumentError: dump format error()
Here's a simple test case that produces the same result, though with a different error thrown:
rails_flash = ActionController::Flash::FlashHash.new
test_hash = {:flash =>rails_flash, :date => Date.today}
dump_test = Marshal.dump(test_hash)
loaded = Marshal.load(dump_test)
As opposed to a normal Hash which executes as expected:
normal_hash = Hash.new
test_hash = {:normal => normal_hash, :date => Date.today}
dump_test = Marshal.dump(test_hash)
loaded = Marshal.load(dump_test)
I've executed in Rails 1.2.3 and Rails 2.2.2 via the console, they both fail. However, these work flawlessly when invoked with MRI 1.8.5. See attached test case.
UnmarshalStream Findings
Here's the marshalled string:
"\004\b{\a:\nflashIC:'ActionController::Flash::FlashHash{\000\006:\n@used{\000:\tdateu:\tDate=\004\b[\bo:\rRational\a:\021@denominatori\a:\017@numeratori\003k?Ji\000i\003\031\025#"
I downloaded the JRuby source and think I have identified the problem in UnmarshalStream. I've stepped through the JRuby code multiple times now and have a grasp on the cause of the failure, but I don't have a patch. When the ActionController::Flash::FlashHash instance is being unmarshalled in unmarshalObjectDirectly, isvarsWaiting is set to true (due to the I from the marshalled FlashHash) and, as far as these tests go, is never reset to false. In the session unmarshalling case, when the Date object is parsed and the \031 character is read, it fails the switch case and the ArgumentError is raised. In the provided test case,
I've created a non-Rails test case that more fully illustrates the ArgumentError: dump format error(). I'll attach the new test case (jruby_hash_subclass_test.rb). This file clearly shows the marshalling bug occurs when when a subclassed Hash has instance variables.