On Mon, 12 Feb 2024 10:58:45 GMT, Darragh Clarke <dcla...@openjdk.org> wrote:

>> test/jdk/java/net/URLClassLoader/getresourceasstream/TestDriver.java line 63:
>> 
>>> 61:                 ),
>>> 62:                 ProcessTools.createTestJavaProcessBuilder(
>>> 63:                         "-cp", ".",
>> 
>> If I'm not mistaken, this will result in the `-cp` option being passed 
>> twice, with different values, to the `java` sub process. I believe that 
>> `ProcessTools.createTestJavaProcessBuilder` will end up passing "-cp 
>> <java.class.path>" to the subprocess, unless -Dtest.noclasspath=false is 
>> defined in the parent process.
>> Tough I could not find what would happen if -cp is passed twice in `man 
>> java` - it appears that the long standing behaviour is that the last one 
>> wins - so I guess that's OK, as I doubt this behaviour (last one wins) could 
>> be changed...
>> 
>> An alternative could be to create a new method in ProcessTools that would 
>> allow to pass a flag to prevent the addition of -cp <java.class.path> when 
>> that's not desiravle, and call that here - and in all other places where -cp 
>> is passed to `ProcessTools.createTestJavaProcessBuilder`.
>
> Would it be possible to change the `createJavaProcessBuilder` method in 
> ProcessTools to include something to check if -cp is already an argument 
> being passed?
> 
> maybe something like this?
> 
> 
> if (!noCP && !args.contains("-cp")) {
>             args.add("-cp");
>             args.add(System.getProperty("java.class.path"));
>         }

That's not a bad idea. What I would recommend in that case would be to not do 
anything here - but rather log another issue against 
`ProcessTools.createTestJavaProcessBuilder`. 
Then proceed with this PR without changing anything...

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17787#discussion_r1486141211

Reply via email to