Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8076486

[TESTBUG] javax/security/auth/Subject/doAs/NestedActions.java fails if extra VM options are given

    Details

      Backports

        Description

        javax/security/auth/Subject/doAs/NestedActions.java fails if run with extra VM flags:

        ----------System.out:(5/618)*----------
        Command line: [C:\\local\\aurora\\CommonData\\jdk\\bin\\java -classpath NestedActionsACE.jar;WriteToFileNegativeAction.jar;ReadFromFileNegativeAction.jar;ReadPropertyNegativeAction.jar; -Xcomp -Xcomp -client -XX:+UseG1GC -XX:+CreateMinidumpOnCrash -Djava.security.manager -Djava.security.policy=C:\\local\\aurora\\CommonData\\j2se_jdk\\jdk\\test\\javax\\security\\auth\\Subject\\doAs\\policy.expect.ace NestedActionsACE]
        Error: Could not create the Java Virtual Machine.
        Error: A fatal exception has occurred. Program will exit.
        Unrecognized option: -Xcomp -Xcomp -client -XX:+UseG1GC -XX:+CreateMinidumpOnCrash

        ----------System.err:(28/1376)----------
         stdout: [];
         stderr: [Error: Could not create the Java Virtual Machine.
        Error: A fatal exception has occurred. Program will exit.
        Unrecognized option: -Xcomp -Xcomp -client -XX:+UseG1GC -XX:+CreateMinidumpOnCrash
        ]
         exitValue = 1

        java.lang.RuntimeException: java.lang.RuntimeException: Expected to get exit value of [0]

        at NestedActions.runJava(NestedActions.java:156)
        at NestedActions.main(NestedActions.java:111)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:502)
        at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:92)
        at java.lang.Thread.run(Thread.java:745)
        Caused by: java.lang.RuntimeException: Expected to get exit value of [0]

        at jdk.testlibrary.OutputAnalyzer.shouldHaveExitValue(OutputAnalyzer.java:353)
        at NestedActions.runJava(NestedActions.java:154)
        ... 7 more

        JavaTest Message: Test threw exception: java.lang.RuntimeException: java.lang.RuntimeException: Expected to get exit value of [0]

        JavaTest Message: shutting down test

        STATUS:Failed.`main' threw exception: java.lang.RuntimeException: java.lang.RuntimeException: Expected to get exit value of [0]

          Issue Links

            Activity

            Hide
            asmotrak Artem Smotrakov added a comment -
            The test runs java in a separate process using jdk.testlibrary.ProcessTools. If java options present, then they are added to a list of parameters:

            http://hg.openjdk.java.net/jdk9/dev/jdk/file/9ee8794f584f/test/javax/security/auth/Subject/doAs/NestedActions.java

            ...
                    if (JAVA_OPTS != null && !JAVA_OPTS.isEmpty()) {
                        cmds.add(JAVA_OPTS);
                    }
                    cmds.add("-Djava.security.manager");
                    cmds.add("-Djava.security.policy=" + TEST_SOURCES + FS + args[1]);
                    cmds.add(args[0]);
                    try {
                        ProcessTools.executeCommand(cmds.toArray(new String[cmds.size()]))
                                .shouldHaveExitValue(0);
            ...

            But it doesn't work if there are more than one java option passed because ProcessTools.executeCommand() method requires each parameter to be put in to a separate array item (actually that's what ProcessBuilder expects). If multiple java options are added as a single parameter, ProcessBuilder considers it as a single option, and as a result, it fails with "Unrecognized option" error.

            This may be fixed by the following:

            diff -r 9ee8794f584f test/javax/security/auth/Subject/doAs/NestedActions.java
            --- a/test/javax/security/auth/Subject/doAs/NestedActions.java Tue Apr 28 09:28:24 2015 -0400
            +++ b/test/javax/security/auth/Subject/doAs/NestedActions.java Tue Apr 28 18:30:10 2015 +0300
            @@ -144,7 +144,9 @@
                     }
                     cmds.add(sb.toString());
                     if (JAVA_OPTS != null && !JAVA_OPTS.isEmpty()) {
            - cmds.add(JAVA_OPTS);
            + Arrays.stream(JAVA_OPTS.split(" "))
            + .filter(str -> !str.trim().isEmpty())
            + .forEach(opt -> cmds.add(opt));
                     }
                     cmds.add("-Djava.security.manager");
                     cmds.add("-Djava.security.policy=" + TEST_SOURCES + FS + args[1]);
            Show
            asmotrak Artem Smotrakov added a comment - The test runs java in a separate process using jdk.testlibrary.ProcessTools. If java options present, then they are added to a list of parameters: http://hg.openjdk.java.net/jdk9/dev/jdk/file/9ee8794f584f/test/javax/security/auth/Subject/doAs/NestedActions.java ...         if (JAVA_OPTS != null && !JAVA_OPTS.isEmpty()) {             cmds.add(JAVA_OPTS);         }         cmds.add("-Djava.security.manager");         cmds.add("-Djava.security.policy=" + TEST_SOURCES + FS + args[1]);         cmds.add(args[0]);         try {             ProcessTools.executeCommand(cmds.toArray(new String[cmds.size()]))                     .shouldHaveExitValue(0); ... But it doesn't work if there are more than one java option passed because ProcessTools.executeCommand() method requires each parameter to be put in to a separate array item (actually that's what ProcessBuilder expects). If multiple java options are added as a single parameter, ProcessBuilder considers it as a single option, and as a result, it fails with "Unrecognized option" error. This may be fixed by the following: diff -r 9ee8794f584f test/javax/security/auth/Subject/doAs/NestedActions.java --- a/test/javax/security/auth/Subject/doAs/NestedActions.java Tue Apr 28 09:28:24 2015 -0400 +++ b/test/javax/security/auth/Subject/doAs/NestedActions.java Tue Apr 28 18:30:10 2015 +0300 @@ -144,7 +144,9 @@          }          cmds.add(sb.toString());          if (JAVA_OPTS != null && !JAVA_OPTS.isEmpty()) { - cmds.add(JAVA_OPTS); + Arrays.stream(JAVA_OPTS.split(" ")) + .filter(str -> !str.trim().isEmpty()) + .forEach(opt -> cmds.add(opt));          }          cmds.add("-Djava.security.manager");          cmds.add("-Djava.security.policy=" + TEST_SOURCES + FS + args[1]);
            Show
            asmotrak Artem Smotrakov added a comment - Code review: http://mail.openjdk.java.net/pipermail/security-dev/2015-April/012071.html
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/fff8ab918557
            User: weijun
            Date: 2015-05-06 01:22:57 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/fff8ab918557 User: weijun Date: 2015-05-06 01:22:57 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/fff8ab918557
            User: lana
            Date: 2015-05-13 21:19:45 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/fff8ab918557 User: lana Date: 2015-05-13 21:19:45 +0000

              People

              • Assignee:
                asmotrak Artem Smotrakov
                Reporter:
                dfazunen Dmitry Fazunenko (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: