Skip to content

Commit 4b554b5

Browse files
author
Brian Burkhalter
committed
8346722: (fs) Files.probeContentType throws ClassCastException with custom file system provider
Reviewed-by: alanb
1 parent 46ba515 commit 4b554b5

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/java.base/unix/classes/sun/nio/fs/DefaultFileTypeDetector.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,15 +25,12 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.FileSystems;
2928
import java.nio.file.spi.FileTypeDetector;
30-
import java.nio.file.spi.FileSystemProvider;
3129

3230
public class DefaultFileTypeDetector {
3331
private DefaultFileTypeDetector() { }
3432

3533
public static FileTypeDetector create() {
36-
FileSystemProvider provider = FileSystems.getDefault().provider();
37-
return ((UnixFileSystemProvider)provider).getFileTypeDetector();
34+
return DefaultFileSystemProvider.instance().getFileTypeDetector();
3835
}
3936
}

test/jdk/java/nio/file/spi/SetDefaultProvider.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
/*
2525
* @test
26-
* @bug 4313887 7006126 8142968 8178380 8183320 8210112 8266345 8263940 8331467 8346573
26+
* @bug 4313887 7006126 8142968 8178380 8183320 8210112 8266345 8263940 8331467
27+
* 8346573 8346722
2728
* @modules jdk.jartool jdk.jlink
2829
* @library /test/lib
2930
* @build testfsp/* testapp/* CustomSystemClassLoader

test/jdk/java/nio/file/spi/testapp/testapp/Main.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -58,5 +58,8 @@ public static void main(String[] args) throws Exception {
5858
throw new RuntimeException("'path' not in default file system");
5959
if (!path.equals(foo))
6060
throw new RuntimeException(path + " not equal to " + foo);
61+
62+
// exercise the file type detector
63+
String fileType = Files.probeContentType(Path.of("."));
6164
}
6265
}

0 commit comments

Comments
 (0)