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

Some object from each_object can't be "p"ed #4462

Closed
headius opened this issue Jan 27, 2017 · 1 comment
Closed

Some object from each_object can't be "p"ed #4462

headius opened this issue Jan 27, 2017 · 1 comment

Comments

@headius
Copy link
Member

headius commented Jan 27, 2017

While fixing #4461, I found that there's some object returned by ObjectSpace.each_object that produces an argument arity error when passed to p:

/projects/jruby $ jruby -X+O -e "ObjectSpace.each_object {|x| p x}"
...
"jruby/kernel/proc.rb"
"jruby/kernel/proc.rb"
#<Proc:0xfdefd3f@uri:classloader:/jruby/kernel/proc.rb:26>
ArgumentError: wrong number of arguments (0 for 2)
            p at org/jruby/RubyKernel.java:477
  block in -e at -e:1
  each_object at org/jruby/RubyObjectSpace.java:181
       <main> at -e:1

Obviously, p is never called with zero args...and even if it were, that's a valid call. So this is pretty weird.

@enebo
Copy link
Member

enebo commented Mar 14, 2017

I do not think this is a bug. What is croaking is p calling inspect:

jruby -d -Xbacktrace.style=raw -X+O -e "ObjectSpace.each_object {|x| p x}" > output
ArgumentError: wrong number of arguments (0 for 2)
             getStackTrace at java/lang/Thread.java:1556
          getBacktraceData at org/jruby/runtime/backtrace/TraceType.java:246
              getBacktrace at org/jruby/runtime/backtrace/TraceType.java:47
          prepareBacktrace at org/jruby/RubyException.java:235
                  preRaise at org/jruby/exceptions/RaiseException.java:216
                  preRaise at org/jruby/exceptions/RaiseException.java:183
                    <init> at org/jruby/exceptions/RaiseException.java:111
         newRaiseException at org/jruby/Ruby.java:4113
          newArgumentError at org/jruby/Ruby.java:3496
        checkCallableArity at org/jruby/java/invokers/RubyToJavaInvoker.java:609
     findCallableArityZero at org/jruby/java/invokers/RubyToJavaInvoker.java:415
                      call at org/jruby/java/invokers/StaticMethodInvoker.java:38
              cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:318
                      call at org/jruby/runtime/callsite/CachingCallSite.java:131
                 rbInspect at org/jruby/RubyBasicObject.java:1138
                         p at org/jruby/RubyKernel.java:477
                      call at org/jruby/RubyKernel$INVOKER$s$0$0$p.gen:-1
                      call at org/jruby/internal/runtime/methods/JavaMethod.java:720
                      call at org/jruby/internal/runtime/methods/DynamicMethod.java:200
                      call at org/jruby/runtime/callsite/CachingCallSite.java:161
            invokeOther0:p at -e:1
               block in -e at -e:1
               yieldDirect at org/jruby/runtime/CompiledIRBlockBody.java:156
                     yield at org/jruby/runtime/BlockBody.java:109
                     yield at org/jruby/runtime/Block.java:167
       each_objectInternal at org/jruby/RubyObjectSpace.java:174
               each_object at org/jruby/RubyObjectSpace.java:181
                      call at org/jruby/RubyObjectSpace$INVOKER$s$0$1$each_object.gen:-1
                      call at org/jruby/internal/runtime/methods/DynamicMethod.java:196
              cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:328
                 callBlock at org/jruby/runtime/callsite/CachingCallSite.java:141
                      call at org/jruby/runtime/callsite/CachingCallSite.java:145
  invokeOther2:each_object at -e:1
                    <main> at -e:1
       invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                      load at org/jruby/ir/Compiler.java:95
                 runScript at org/jruby/Ruby.java:827
               runNormally at org/jruby/Ruby.java:746
               runNormally at org/jruby/Ruby.java:764
               runFromMain at org/jruby/Ruby.java:577
             doRunFromMain at org/jruby/Main.java:417
               internalRun at org/jruby/Main.java:305
                       run at org/jruby/Main.java:232
                      main at org/jruby/Main.java:204

Since p calls inspect it is pretty easy to make MRI fail this as well:

p = BasicObject.new

class << p
  def inspect(a, b)
    "HEH"
  end
end

p p

ObjectSpace.each_object {|x| p x }

I did figure what is causing this for us and it is 'JRuby.ref' returning our implementations of classes like RubyNil which not surprisingly does have two JI accessiable inspect()s which are our implementations of inspect. Had this been some JI type I thought maybe we could fix that case but in this case I do not think we want to start masking instances on refs. We could fix all of these by providing no-arg inspect() methods but it feels weird to me.

@enebo enebo closed this as completed May 16, 2017
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