Xbootclasspath/a adds CWD to boot class path
David Holmes
david.holmes at oracle.com
Tue Sep 26 11:18:46 UTC 2017
Hi Michael,
On 26/09/2017 9:01 PM, David Holmes wrote:
> Hi Michael,
>
> Moving over to core-libs-dev.
>
> The discussion in 8185540 is a bit confusing to me.
I've re-read the discussion and related bugs. As I understand it what
you see now is expected and reflects what happens in 7 and 8. What
should see is that the empty path elements causes CWD to be included for
resource lookup, but not for class lookup. That inconsistency was
flagged for fixing in 7, deferred to 9, rectified early on, but then
reverted when the module system was integrated - with the eventual fix
re-appearing in JDK 10.
Cheers,
David
> 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 core-libs-dev
mailing list