JRuby File Ops

File operations that work in my simple JRuby program do not work in my
Swing GUI based program. The attached file “filetest.rb” reads in a text
file (itself) and sends it to the console with a “puts”.

That code was copied into the other attachment “gui_filetest.rb”, which
should do the same thing when triggered by my popup menu selection.

The line that causes the error follows:

read_from_disk # This causes an error

The error message is at the very bottom of the file,
between =begin and =end.

I found the problem, so don’t bother with this.
Thanks,
Gary

Sorry nobody got back to you. What was the problem?

  • Charlie

Ok, it sounds like you may have gotten a Java error. Can you show me?
If it’s a Java error/exception, that’s almost always a bug; we should
be re-throwing a Ruby exception with an appropriate message. If it is
a Ruby exception but has a bad Java-related error message, that’s
something we’d want to fix too.

  • Charlie

Charlie,
Here is the error msg:
Exception in thread “AWT-EventQueue-0”
org.jruby.exceptions.RaiseException: (TypeError) can’t convert nil into
String
at org.jruby.RubyFileTest.exist?(org/jruby/RubyFileTest.java:129)
at TextStatus.read_from_disk(./gui_filetest.rb:30)
at TextStatus.create_popup(./gui_filetest.rb:47)
at org.jruby.RubyProc.call(org/jruby/RubyProc.java:268)
at org.jruby.RubyProc.call(org/jruby/RubyProc.java:232)

When I looked at the error, I saw the “.java” in the error msg and
thought that perhaps Java had something to do with it. However, the
error was that my filename variable was not readable within the scope of
the class. Once I corrected that, it all worked. So Java had nothing to
do with it.
Regards,
Gary

Ahh I see…so the issue here is that we’re raising an appropriate
Ruby error, but it is eventually handled by the Java logic in the AWT
event thread. The .java files in the trace are to show the core class
methods, which are mostly implemented in Java in JRuby.

In any case, I believe this is being handled correctly by JRuby, and
it’s just an interaction issue with AWT that presented it in an odd
way.

Thank you!

  • Charlie

Hi Charles,
The problem was a simple Ruby mistake that I made. However, the error
message mentioned something relative to Java, so I thought that somehow
my Ruby file-related commands were somehow clashing with Java. After a
while, I stopped looking for Java-related issues, and then finally saw
that it was just a simple Ruby variable-scope issue.

I had been so focused on the new aspects of Java and Swing, that I got
sloppy with Ruby.

Regards,
Gary

How to get full file path when trying to upload csv file.

Regards,
Shobha