8077822: javac does not recognize '*.java' as file if '-J' option is specified
authorrobm
Wed, 20 May 2015 18:03:56 +0100
changeset 30684 ac2a15333983
parent 30683 a69fe0acc0ab
child 30685 5806d3adbd6b
8077822: javac does not recognize '*.java' as file if '-J' option is specified Reviewed-by: ksrini
jdk/src/java.base/windows/native/libjli/java_md.c
jdk/test/tools/launcher/Arrrghs.java
--- a/jdk/src/java.base/windows/native/libjli/java_md.c	Wed May 20 11:17:09 2015 -0400
+++ b/jdk/src/java.base/windows/native/libjli/java_md.c	Wed May 20 18:03:56 2015 +0100
@@ -990,6 +990,26 @@
     return JNI_FALSE;
 }
 
+int
+filterArgs(StdArg *stdargs, const int nargc, StdArg **pargv) {
+    StdArg* argv = NULL;
+    int nargs = 0;
+    int i;
+
+    /* Copy the non-vm args */
+    for (i = 0; i < nargc ; i++) {
+        const char *arg = stdargs[i].arg;
+        if (arg[0] == '-' && arg[1] == 'J')
+            continue;
+        argv = (StdArg*) JLI_MemRealloc(argv, (nargs+1) * sizeof(StdArg));
+        argv[nargs].arg = JLI_StringDup(arg);
+        argv[nargs].has_wildcard = stdargs[i].has_wildcard;
+        nargs++;
+    }
+    *pargv = argv;
+    return nargs;
+}
+
 /*
  * At this point we have the arguments to the application, and we need to
  * check with original stdargs in order to compare which of these truly
@@ -1005,8 +1025,9 @@
     char *ostart, *astart, **nargv;
     jboolean needs_expansion = JNI_FALSE;
     jmethodID mid;
-    int stdargc;
+    int filteredargc, stdargc;
     StdArg *stdargs;
+    StdArg *filteredargs;
     jclass cls = GetLauncherHelperClass(env);
     NULL_CHECK0(cls);
 
@@ -1017,6 +1038,8 @@
     stdargs = JLI_GetStdArgs();
     stdargc = JLI_GetStdArgc();
 
+    filteredargc = filterArgs(stdargs, stdargc, &filteredargs);
+
     // sanity check, this should never happen
     if (argc > stdargc) {
         JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);
@@ -1025,8 +1048,8 @@
     }
 
     // sanity check, match the args we have, to the holy grail
-    idx = stdargc - argc;
-    ostart = stdargs[idx].arg;
+    idx = filteredargc - argc;
+    ostart = filteredargs[idx].arg;
     astart = strv[0];
     // sanity check, ensure that the first argument of the arrays are the same
     if (JLI_StrCmp(ostart, astart) != 0) {
@@ -1039,8 +1062,8 @@
     // make a copy of the args which will be expanded in java if required.
     nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));
     for (i = 0, j = idx; i < argc; i++, j++) {
-        jboolean arg_expand = (JLI_StrCmp(stdargs[j].arg, strv[i]) == 0)
-                                ? stdargs[j].has_wildcard
+        jboolean arg_expand = (JLI_StrCmp(filteredargs[j].arg, strv[i]) == 0)
+                                ? filteredargs[j].has_wildcard
                                 : JNI_FALSE;
         if (needs_expansion == JNI_FALSE)
             needs_expansion = arg_expand;
@@ -1077,5 +1100,6 @@
         JLI_MemFree(nargv[i]);
     }
     JLI_MemFree(nargv);
+    JLI_MemFree(filteredargs);
     return outArray;
 }
--- a/jdk/test/tools/launcher/Arrrghs.java	Wed May 20 11:17:09 2015 -0400
+++ b/jdk/test/tools/launcher/Arrrghs.java	Wed May 20 18:03:56 2015 +0100
@@ -24,7 +24,7 @@
 /**
  * @test
  * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
- *      6894719 6968053 7151434 7146424 8007333
+ *      6894719 6968053 7151434 7146424 8007333 8077822
  * @summary Argument parsing validation.
  * @compile -XDignore.symbol.file Arrrghs.java
  * @run main/othervm Arrrghs
@@ -304,6 +304,16 @@
             throw new RuntimeException("Error: compiling java wildcards");
         }
 
+        // test if javac (the command) can compile *.java with a vmoption
+        tr = doExec(javacCmd, "-cp", ".",
+                    "-J-showversion", "-J-Dsomeproperty=foo",
+                    libDir.getName() + File.separator + "*.java");
+        if (!tr.isOK()) {
+            System.out.println(tr);
+            throw new RuntimeException("Error: compiling java wildcards with vmoptions");
+        }
+
+
         // use the jar cmd to create jars using the ? wildcard
         File jarFoo = new File(libDir, "Foo.jar");
         tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class");