# HG changeset patch # User Rik # Date 1438640672 25200 # Node ID 4262598620ae6879382db30bb7b277bd27f26ccf # Parent 6dc15d4cc17e58647989fe5814727c53e8318e21 Don't add duplicates to javaclasspath when run in home directory (bug #45683). * ov-java.cc (initial_class_path): Get current working directory (cwd) and home directory (home_dir). Don't read in javaclasspath.txt from home directory or java install directory if either of these is the same as cwd. diff --git a/libinterp/octave-value/ov-java.cc b/libinterp/octave-value/ov-java.cc --- a/libinterp/octave-value/ov-java.cc +++ b/libinterp/octave-value/ov-java.cc @@ -350,6 +350,9 @@ // 2) User's home directory // 3) Octave installation directory where octave.jar resides + std::string cwd = octave_env::get_current_directory (); + std::string home_dir = octave_env::get_home_directory (); + // The filename is "javaclasspath.txt", but historically // has been "classpath.txt" so both are supported. std::string cp_list[] = {"javaclasspath.txt", "classpath.txt"}; @@ -372,25 +375,31 @@ // Try to find classpath file in the user's home directory. - cp_file = "~" + sep + filename; - cp_file = file_ops::tilde_expand (cp_file); - cp_exists = file_stat (cp_file); - if (cp_exists) + if (cwd != home_dir) { - // File found. Add its contents to the static classpath. - std::string classpath = read_classpath_txt (cp_file); - retval.append (classpath); + cp_file = "~" + sep + filename; + cp_file = file_ops::tilde_expand (cp_file); + cp_exists = file_stat (cp_file); + if (cp_exists) + { + // File found. Add its contents to the static classpath. + std::string classpath = read_classpath_txt (cp_file); + retval.append (classpath); + } } // Try to find classpath file in the Octave install directory. - cp_file = java_dir + sep + filename; - cp_exists = file_stat (cp_file); - if (cp_exists) + if (cwd != java_dir) { - // File found. Add its contents to the static classpath. - std::string classpath = read_classpath_txt (cp_file); - retval.append (classpath); + cp_file = java_dir + sep + filename; + cp_exists = file_stat (cp_file); + if (cp_exists) + { + // File found. Add its contents to the static classpath. + std::string classpath = read_classpath_txt (cp_file); + retval.append (classpath); + } } } }