Skip to content

A bit confusing error: "FrozenError: can't modify frozen NilClass" #8054

@rubyFeedback

Description

@rubyFeedback

I am currently working on my two gems swing_paradise and universal_widgets. The goal is
to fully support jruby + SWING eventually, via some kind of DSL such as:

button {
}

A bit similar to what Andy does via glimmer, but not as sophisticated. I am more interested
to see how I can use traditional OOP build up for GUIs, including commandline stuff (eventually,
e. g. the terminal and so forth) as well as web-related stuff (e. g. HTML/CSS also has button).
One code base to unify them all! One ring to bind them and in the darkness ... eat some ice cream! \o/

Anyway. As I am extending the code right now, I ran into this odd error message:

Warning: not (yet?) supported toolkit: jruby
FrozenError: can't modify frozen NilClass
                  set_font at     /home/Programs/Jruby/9.4.5.0/lib/ruby/3.1/site_ruby/universal_widgets/base_module/base_module.rb:911
  create_the_main_textview at read_and_display_from_a_locally_existing_file_example.rb:165
           create_the_skeleton at read_and_display_from_a_locally_existing_file_example.rb:103
                 run_super at     /home/Programs/Jruby/9.4.5.0/lib/ruby/3.1/site_ruby/universal_widgets/base_module/base_module.rb:980
                       run at read_and_display_from_a_locally_existing_file_example.rb:138
                initialize at read_and_display_from_a_locally_existing_file_example.rb:65
                       new at org/jruby/RubyClass.java:904
                    <main> at read_and_display_from_a_locally_existing_file_example.rb:240

The first line is from my own gem, but the second line is from jruby I believe:

FrozenError: can't modify frozen NilClass

This is a bit weird though. I believe ruby MRI does not have this error.

I believe MRI does not have a frozen nil class ever.

Now, I am totally fine if jruby does things differently. I get that you focus on the java
ecosystem also, so this may not be ruby 1:1. But, even then, I find the idea of a nil
class to ever be frozen a bit awkward, even more so when an error message can happen.

Is that really needed? It may be that I made some user error, but that a nil object
can ever be frozen, is super-odd to me, having used MRI for a long time. Perhaps
I have not seen this in MRI so far, so I can not say for certain, but I find this rather
strange.

Anyway - this is NOT an issue request to change anything in jruby here, actually.
I am more interested in the use case and rationale.

If someone has time, perhaps an answer could be given here, and then this
could be added to the FAQ entry for jruby at:

https://github.com/jruby/jruby/wiki/FAQs

I checked for "frozen" but did not find anything, so perhaps this could be added
to FAQ if anyone has time (and also knows the reason why nil objects can
be frozen in jruby, which confused me. Now that I know about this, I will
probably not be confused, although I am curious how this may arise in
code. I don't think I have ever seen that in MRI so far.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions