jruby
jruby copied to clipboard
Object.const_defined? not respecting namespace check.
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.
Funnily enough, the same happens in truffleruby.
Nice find!
This also happens in JRuby 9.4 and I suspect earlier versions.
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")