Skip to content

Commit

Permalink
[refactor] make setJRubyHome null safe
Browse files Browse the repository at this point in the history
and assure we're not using a null home with ENV['RUBY'] setup
  • Loading branch information
kares committed Oct 12, 2018
1 parent 1f0e600 commit 117d751
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -138,12 +138,12 @@ public RubyInstanceConfig(RubyInstanceConfig parentConfig) {
}

private void initEnvironment() {
environment = new HashMap<String,String>();
environment = new HashMap<>();
try {
environment.putAll(System.getenv());
}
catch (SecurityException se) { /* ignore missing getenv permission */ }
setupEnvironment(getJRubyHome());
setupEnvironment();
}

public RubyInstanceConfig(final InputStream in, final PrintStream out, final PrintStream err) {
Expand Down Expand Up @@ -347,7 +347,7 @@ private static String verifyHome(String home, PrintStream error) {
if ("uri:classloader://META-INF/jruby.home".equals(home) || "uri:classloader:/META-INF/jruby.home".equals(home)) {
return home;
}
if (home.equals(".")) {
if (".".equals(home)) {
home = SafePropertyAccessor.getProperty("user.dir");
}
else if (home.startsWith("cp:")) {
Expand All @@ -357,7 +357,7 @@ else if (home.startsWith("cp:")) {
home.startsWith("classpath:") || home.startsWith("uri:")) {
error.println("Warning: JRuby home with uri like paths may not have full functionality - use at your own risk");
}
// do not normalize on plain jar like pathes coming from jruby-rack
// do not normalize on plain jar like paths coming from jruby-rack
else if (!home.contains(".jar!/") && !home.startsWith("uri:")) {
File file = new File(home);
if (!file.exists()) {
Expand Down Expand Up @@ -488,8 +488,8 @@ public String getJRubyHome() {
}

public void setJRubyHome(String home) {
jrubyHome = verifyHome(home, error);
setupEnvironment(jrubyHome);
jrubyHome = home != null ? verifyHome(home, error) : null;
setupEnvironment();
}

public CompileMode getCompileMode() {
Expand Down Expand Up @@ -660,15 +660,15 @@ public boolean isSiphashEnabled() {
}

public void setEnvironment(Map<String, String> newEnvironment) {
environment = new HashMap<String, String>();
environment = new HashMap<>();
if (newEnvironment != null) {
environment.putAll(newEnvironment);
}
setupEnvironment(getJRubyHome());
setupEnvironment();
}

private void setupEnvironment(String jrubyHome) {
if (RubyFile.PROTOCOL_PATTERN.matcher(jrubyHome).matches() && !environment.containsKey("RUBY")) {
private void setupEnvironment() {
if (!environment.containsKey("RUBY") && RubyFile.PROTOCOL_PATTERN.matcher(getJRubyHome()).matches()) {
// the assumption that if JRubyHome is not a regular file that jruby
// got launched in an embedded fashion
environment.put("RUBY", ClasspathLauncher.jrubyCommand(defaultClassLoader()));
Expand Down

0 comments on commit 117d751

Please sign in to comment.