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

Loading marshalled Java enums with anonymous classes does not work #3526

Closed
jmiettinen opened this issue Dec 9, 2015 · 4 comments
Closed

Comments

@jmiettinen
Copy link
Contributor

If we have a class

public enum SimpleCase {
    FIZZ,
    BUZZ {
        @Override
        public boolean foo() {
            return true;
        }
    };
    public boolean foo() { return false; }
}

Then, running CLASSPATH="." ruby -e 'Java::SimpleCase.values.each { |e| Marshal.load(Marshal.dump(e)) }' fails for BUZZ with error

ArgumentError: undefined class/module Java::Default::SimpleCase::1
    load at org/jruby/RubyMarshal.java:148
  (root) at -e:1
    each at org/jruby/java/proxies/ArrayJavaProxy.java:154
  (root) at -e:1

I am not sure if this should work, but it did in 1.7.19 and no longer works in 1.7.20 and later ones.

@kares
Copy link
Member

kares commented Dec 10, 2015

yes this should work just fine - we'll be looking at it, thanks for the report!

@kares
Copy link
Member

kares commented Jan 18, 2016

here's the deal - anonymous Java classes used to look a bit weird on the Ruby end e.g. Java::JavaUtilConcurrent::TimeUnit:: which was changed at 2c50057 so they look e.g. Java::JavaUtilConcurrent::TimeUnit::1 since. marshalling failed somehow correctly for older 1.7.x :

jruby-1.7.4 :015 > secs = Marshal.load Marshal.dump [ java.util.concurrent.TimeUnit::SECONDS ]
ArgumentError: Java::JavaUtilConcurrent:: does not refer class
    from org/jruby/RubyMarshal.java:148:in `load'
    from (irb):15:in `evaluate'
    from org/jruby/RubyKernel.java:1093:in `eval'
    from org/jruby/RubyKernel.java:1489:in `loop'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from /opt/local/rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'

yet for some reason marshalling works these works on 1.7.19 but does not serialize the "correct" class :

jruby-1.7.19 :008 > java.util.concurrent.TimeUnit::SECONDS.class
 => Java::JavaUtilConcurrent::TimeUnit:: 
jruby-1.7.19 :005 > secs = Marshal.load Marshal.dump java.util.concurrent.TimeUnit::SECONDS
 => #<Java::JavaUtilConcurrent::TimeUnit:0x704c6d5c> 
jruby-1.7.19 :006 > secs.class
 => Java::JavaUtilConcurrent::TimeUnit 
jruby-1.7.19 :007 > secs.class == java.util.concurrent.TimeUnit::SECONDS.class
 => false 

this would be easily fixed if the RubyClass meta-class was not abused with Java integration and we had a JavaClass sub-class used for Java classes (a big rewrite I am planning for a while but could not get to :)

... really hesitant to revert this as the previous behaviour is not correct and might lead to ugly bugs ;(

@jmiettinen
Copy link
Contributor Author

Ah yeah, the earlier version did not work correctly either. I never noticed that because we were just accidentally marshalling and unmarshalling enums and that started to fail.

So the wrong result was never used.

kares added a commit to kares/jruby that referenced this issue Jan 19, 2016
…us classes

local and anonymous classes had empty names <= 1.7.19 and the change (for anonymous classes) was not spec-ed properly, but with features such as Java proxy marshalling (jruby#3526) this gained importance.
kares added a commit that referenced this issue Jan 19, 2016
…us classes

local and anonymous classes had empty names <= 1.7.19 and the change (for anonymous classes) was not spec-ed properly, but with features such as Java proxy marshalling (#3526) this gained importance.
kares added a commit that referenced this issue Jan 20, 2016
* jruby-1_7: (27 commits)
  Update jnr-posix to finally fix 32 bit JVM crasher on windows stat
  pend marshaling behavior - not working for Java non-member classes (GH-3526)
  local (non-member) classes should have correct name just like anonymous classes
  DRY out getClassFromPath usage in UnmarshalStream (all delegating to one method)
  review runtime's getClassFromPath
  hide unmarshalObject methods that use private inner type as a parameter
  Update for newer jnr-posix for windows 32 bit JVM stat workaround
  Remove remaining `should` uses from compiler specs.
  Don't deoptimize while loops just because of a block arg.
  Always assign masgn destructured args in block as block-local.
  Move parser scripts to tool.
  Add case for breakage fixed in b93fbb6e431.
  Check for empty identifiers and treat them as false.
  Same fix for AOT as for interp for #3180.
  Also use the anonymous wrap class for pushRubyClass, for defs.
  More robust, less breaky fix to omit bad class/package elements.
  Revert "Use methods instead of procs for converters."
  Fixes #3550. Warning "io/console not supported; tty will not be manipulated" occurs again on 1.7.23
  updating to jcodings messes with this obscure char no longer being considered a space.
  Update to latest jcodings
  ...
@kares
Copy link
Member

kares commented Jan 22, 2016

working fine on 9K - calling it a wont-fix for jruby 1.7.x as its better to fail than de-serialize improperly.

@kares kares closed this as completed Jan 22, 2016
@kares kares added this to the Won't Fix milestone Jan 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants