Creating Variables in Java Affects Trace Behavior

Hi,

I’ve discovered that defining variables through Java results in
unexpected side effects when tracing using the EventHook. If, after
creating a JRuby runtime, I do this:

Map vars = jRubyContainer.getVarMap();
vars.put("$Applet", applet);

And then I install the EventHook, I notice that it often runs off into
what presumably are internal JRuby methods. For example, if only
intercepting “line” events, the following Ruby code:

1.def foo(x)
2. x
3.end
4.foo(1)
5.

Normally produces this trace sequence:

1, 4, 2, 5

After adding the vars.put() call, it will go from line 1 to line ‘123’,
which appears to be a method named ‘method_add’. ‘foo’ will also be
visible as a variable of type ‘Symbol’ when before, it was not a
variable at all.

Any thoughts on what might be causing this behavior? I’ve looked at
BiVariableMap and I don’t see anything unusual there… I presume the
problem (if it a problem at all and not just a misunderstanding on my
part) is actually deeper in the interpreter logic itself.

Thanks!

EDIT: Upon closer inspection, it appears that what is really happening
is that the event handler is being called for JRuby “core” code. I
notice that jruby-debug explicitly tests for this and skips over it. I
can apply the same fix by testing for file=="" (I do not set a
script name) but it would be interesting to find out why the use of
BiVariableMap.put() triggers this behavior. Is this intentional?