Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.6
-
Fix Version/s: JRuby 1.2
-
Component/s: Interpreter
-
Labels:None
-
Number of attachments :
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
| Field | Original Value | New Value |
|---|---|---|
| Assignee | Charles Oliver Nutter [ headius ] | |
| Resolution | Fixed [ 1 ] | |
| Fix Version/s | JRuby 1.2 [ 14757 ] | |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Status | Resolved [ 5 ] | Closed [ 6 ] |
I fixed it in r9231 by having it try several options and then eventually failover to tmpdir. This fixes my simple case:
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.