jruby icon indicating copy to clipboard operation
jruby copied to clipboard

Object.const_defined? not respecting namespace check.

Open HoneyryderChuck opened this issue 6 months ago • 2 comments

Environment Information

  • JRuby version: "jruby 10.0.0.1 (3.4.2) 2025-05-07 79cf1e4aec OpenJDK 64-Bit Server VM 24.0.1+9-30 on 24.0.1+9-30 +indy +jit [x86_64-darwin]"
  • Operating system and platform: Darwin MacBook-Pro.local 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:26 PDT 2025; root:xnu-11417.121.6~2/RELEASE_X86_64 x86_64

Expected Behavior

Given the following snippet, I'd expect the const not to be defined:

Object.const_set :Bang, Module.new
Object.const_defined?("Bang::Struct") #=>should be false

Actual Behavior

The snippet above returns true in jruby 10.0.0.1, false in cruby.

HoneyryderChuck avatar Jun 11 '25 23:06 HoneyryderChuck

Funnily enough, the same happens in truffleruby.

HoneyryderChuck avatar Jun 11 '25 23:06 HoneyryderChuck

Nice find!

headius avatar Jun 14 '25 14:06 headius

This also happens in JRuby 9.4 and I suspect earlier versions.

enebo avatar Jun 26 '25 17:06 enebo

So the gist of what is wrong is that this sets search Object internally so it finds things defined on Object:

Object.const_set :Bang, Module.new; p Object.const_defined?("Bang::String")

enebo avatar Jun 26 '25 18:06 enebo