OpenJDK / jigsaw / jake / jdk
changeset 14299:f0ce7f2beb6e
Specifying class path via -Djava.class.path ignored
author | alanb |
---|---|
date | Sat, 31 Oct 2015 13:21:01 +0000 |
parents | 1ac78e4a10d5 |
children | 39b8dd9a6fca |
files | src/java.base/share/native/libjli/java.c test/tools/launcher/MiscTests.java |
diffstat | 2 files changed, 47 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.base/share/native/libjli/java.c Thu Oct 29 19:55:39 2015 -0700 +++ b/src/java.base/share/native/libjli/java.c Sat Oct 31 13:21:01 2015 +0000 @@ -74,6 +74,7 @@ static const char *_program_name; static const char *_launcher_name; static jboolean _is_java_args = JNI_FALSE; +static jboolean _have_classpath = JNI_FALSE; static const char *_fVersion; static const char *_dVersion; static jboolean _wc_enabled = JNI_FALSE; @@ -279,6 +280,12 @@ if (!AddApplicationOptions(appclassc, appclassv)) { return(1); } + } else { + /* Set default CLASSPATH */ + char* cpath = getenv("CLASSPATH"); + if (cpath != NULL) { + SetClassPath(cpath); + } } /* Parse command line options; if the return value of @@ -857,6 +864,7 @@ AddOption(def, NULL); if (s != orig) JLI_MemFree((char *) s); + _have_classpath = JNI_TRUE; } static void @@ -1280,6 +1288,10 @@ } else if (RemovableOption(arg)) { ; /* Do not pass option to vm. */ } else { + /* java.class.path set on the command line */ + if (JLI_StrCCmp(arg, "-Djava.class.path=") == 0) { + _have_classpath = JNI_TRUE; + } AddOption(arg, NULL); } } @@ -1294,13 +1306,11 @@ *pret = 1; } } else if (mode == LM_UNKNOWN) { - /* default to LM_CLASS if -jar and -cp option are + /* default to LM_CLASS if -m, -jar and -cp options are * not specified */ - char* cpath = getenv("CLASSPATH"); - if (cpath == NULL) { - cpath = "."; + if (!_have_classpath) { + SetClassPath("."); } - SetClassPath(cpath); mode = LM_CLASS; }
--- a/test/tools/launcher/MiscTests.java Thu Oct 29 19:55:39 2015 -0700 +++ b/test/tools/launcher/MiscTests.java Sat Oct 31 13:21:01 2015 +0000 @@ -37,16 +37,42 @@ public class MiscTests extends TestHelper { - private static final String mainClass = "Foo"; - private static final String exportOpts - = "-XaddExports:jdk.crypto.pkcs11/sun.security.pkcs11=ALL-UNNAMED"; + /** + * Test with class path set on the command line via -Djava.class.path + */ + static void testWithClassPathSetViaProperty() throws IOException { + final String mainClass = "Foo"; - // 6856415: Checks to ensure that proper exceptions are thrown by java - static void test6856415() throws IOException { + File source = new File(mainClass + ".java"); List<String> scratch = new ArrayList<>(); scratch.add("public class Foo {"); scratch.add("public static void main(String... args) {"); + scratch.add("}"); + scratch.add("}"); + createFile(source, scratch); + + compile(mainClass + ".java"); + + String dir = new File(mainClass + ".class").getAbsoluteFile().getParent(); + TestResult tr = doExec(javaCmd, "-Djava.class.path=" + dir, mainClass); + for (String s : tr.testOutput) { + System.out.println(s); + } + } + + /** + * 6856415: Checks to ensure that proper exceptions are thrown by java + */ + static void test6856415() throws IOException { + + final String mainClass = "Foo6856415"; + final String exportOpts + = "-XaddExports:jdk.crypto.pkcs11/sun.security.pkcs11=ALL-UNNAMED"; + + List<String> scratch = new ArrayList<>(); + scratch.add("public class Foo6856415 {"); + scratch.add("public static void main(String... args) {"); scratch.add("java.security.Provider p = new sun.security.pkcs11.SunPKCS11();"); scratch.add("java.security.Security.insertProviderAt(p, 1);"); scratch.add("}"); @@ -78,6 +104,7 @@ } public static void main(String... args) throws IOException { + testWithClassPathSetViaProperty(); test6856415(); if (testExitValue != 0) { throw new Error(testExitValue + " tests failed");