jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-3253

Lack of default jruby.home in embedded usage causes NPE

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.6
  • Fix Version/s: JRuby 1.2
  • Component/s: Interpreter
  • Labels:
    None

Description

In embedded usage of JRuby 1.1.6, if the embedder does not provide a jruby.home value, the runtime will raise a NPE when shelling out to execute some shell commands.

The immediate offending code is at RbConfigLibrary.java:119. Specifically, the line:

setConfig(configHash, "prefix", normalizedHome);

where normalizedHome is derived from jruby.home and is null, thus causing the NPE.

A proper resolution of this issue will involve either providing a sensible default jruby.home value, or finding other parts of the runtime that depends on jruby.home, even when the runtime is embedded.

As a workaround, System.setProprety("jruby.home", System.getProperty("java.io.tmpdir")) seems to work to avoid the NPE.

A short discussion from the mailing list is quoted below.

> From: Charles.O.Nutter@sun.com Charles.O.Nutter@sun.com On
> Behalf Of Charles Oliver Nutter
> Sent: Wednesday, December 17, 2008 8:37 PM
> To: user@jruby.codehaus.org
> Subject: Re: [jruby-user] Proper jruby.home setting for an embedded
> app? (NPE in 1.1.6)
>
> Peter K Chan wrote:
>> What is the proper value for jruby.home in an embedded runtime?
>>
>> It seems that in 1.1.5, the value defaults at being HOME/.jruby. In
>> 1.1.6, the value ends up being null and causing a NPE.
>>
>> I tried to provide a default value of NOT_AVAILABLE, which works
>> around the NPE, but then I see a new directory called NOT_AVAILABLE
>> created after the run.
>>
>> The proximal cause that needed the jruby.home value is shelling out; i.e.
>> `echo hi` caused NPE in my embedded 1.1.6 runtime, unless I provide a
>> jruby.home value (which then gets created as a directory).
>>
>> What is the proper way to tell the runtime that there is no
>> jruby.home value available and that it shouldn't try to create a jruby.home directory?
>
> That would be a regression; we wanted to boot the .jruby dir, since it
> just caused problems, but I guess we didn't put a reasonable default
> in its place. So...we need a bug for that.
>
> Meanwhile, you could probably set it to any existing dir, maybe a
> dummy location? /tmp? Sorry for the mixup with this one, I guess it
> wasn't caught during the RC. Toss your full description into a bug and
> maybe come up with a patch if you have a chance.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Charles Oliver Nutter added a comment - 17/Feb/09 9:53 PM

I fixed it in r9231 by having it try several options and then eventually failover to tmpdir. This fixes my simple case:

java -jar lib/jruby.jar -e "require 'rbconfig'"

But I couldn't think of a good way to test it (System.setProperty does not allow setting null, so it's not as simple as clearing it and launching another runtime).

I also removed the behavior that creates JRuby home, and instead had it warn (on stderr) if it didn't exist immediately before failing over to tmpdir.

Show
Charles Oliver Nutter added a comment - 17/Feb/09 9:53 PM I fixed it in r9231 by having it try several options and then eventually failover to tmpdir. This fixes my simple case:
java -jar lib/jruby.jar -e "require 'rbconfig'"
But I couldn't think of a good way to test it (System.setProperty does not allow setting null, so it's not as simple as clearing it and launching another runtime). I also removed the behavior that creates JRuby home, and instead had it warn (on stderr) if it didn't exist immediately before failing over to tmpdir.
Hide
Permalink
Peter K Chan added a comment - 18/Feb/09 3:17 PM

Can you use System.clearProperty, available since Java 1.5?

Also, just to confirm, for embedder like myself, I should continue to System.setProperty("jruby.home", System.getProperty("java.io.tmpdir")) before I create the JRuby runtime, right?

Show
Peter K Chan added a comment - 18/Feb/09 3:17 PM Can you use System.clearProperty, available since Java 1.5? Also, just to confirm, for embedder like myself, I should continue to System.setProperty("jruby.home", System.getProperty("java.io.tmpdir")) before I create the JRuby runtime, right?
Hide
Permalink
Charles Oliver Nutter added a comment - 19/Feb/09 4:00 PM

Jeez, I didn't even know about clearProperty. I'll add a test using that.

If you don't set jruby.home yourself, it will default to tmpdir, so you should not need to set it at all. My test using java -jar jruby.jar -e "require 'rbconfig'" works fine. And it will only warn you if the jruby.home you set doesn't exist; it will then use tmpdir and not create the specified dir for you.

Show
Charles Oliver Nutter added a comment - 19/Feb/09 4:00 PM Jeez, I didn't even know about clearProperty. I'll add a test using that. If you don't set jruby.home yourself, it will default to tmpdir, so you should not need to set it at all. My test using java -jar jruby.jar -e "require 'rbconfig'" works fine. And it will only warn you if the jruby.home you set doesn't exist; it will then use tmpdir and not create the specified dir for you.
Hide
Permalink
Charles Oliver Nutter added a comment - 19/Feb/09 4:13 PM

Test added in r9248.

Show
Charles Oliver Nutter added a comment - 19/Feb/09 4:13 PM Test added in r9248.

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    Peter K Chan
Vote (0)
Watch (1)

Dates

  • Created:
    18/Dec/08 6:01 PM
    Updated:
    21/Mar/09 1:14 PM
    Resolved:
    17/Feb/09 9:53 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.