Xbootclasspath/a adds CWD to boot class path
David Holmes
david.holmes at oracle.com
Tue Sep 26 11:01:16 UTC 2017
Hi Michael,
Moving over to core-libs-dev.
The discussion in 8185540 is a bit confusing to me.
David
On 26/09/2017 8:45 PM, Michael Rasmussen wrote:
> Hi
>
> We have discovered an issue with using -Xbootclasspath/a on Java 9.
> if you add -Xbootclasspath/a as JVM argument, the current working directory
> also gets added to boot class path!
>
> take the following Test.java class:
> import java.util.Collections;
> public class Test {
> public static void main(String[] args) throws Throwable {
> System.out.println(Collections.list(
> ClassLoader.getPlatformClassLoader().getResources("foo.txt")));
> }
> }
>
> $ java -fullversion
> openjdk full version "9+181"
> $ javac Test.java
> $ pwd
> /home/michael/test
> $ touch foo.txt
> $ touch /tmp/foo.txt
> $ java Test
> []
> $ java -Xbootclasspath/a:/tmp Test
> [file:/home/michael/test/foo.txt, file:/tmp/foo.txt]
>
> As the above shows, adding the -Xbootclasspath/a, also added the current
> working directory to the boot class path. Using a new ClassLoader(null){}
> instead of the platform class loader gives the same result.
>
> A bit of digging shows that "jdk.boot.class.path.append" system property
> contains a leading path-separator char, like ":/tmp" (";C:/tmp" on Win),
> meaning in jdk.internal.loader.ClassLoaders.<clinit>, when that string
> is converted to a classpath, the empty first part gets parsed as cwd.
>
> I assume this is not the intended behavior of -Xbootclasspath/a, as the
> same thing doesn't happen on Java 8, also it's not documented as such.
>
> I found some related issues in Jira, such as JDK-8185540, that seems
> to remedy this, but it's still weird that the JVM adds the empty path
> element to begin with.
>
> Kind regards,
> Michael Rasmussen
>
More information about the jdk9-dev
mailing list