-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
17
-
generic
-
linux
ADDITIONAL SYSTEM INFORMATION :
OpenJDK
A DESCRIPTION OF THE PROBLEM :
On Linux, the java.nio.file.Files.probeContentType method unexpectedly returns null if the filename contains a hash mark "#".
The problem is caused by sun.net.www.MimeTable.findByFileName(String), which is used by the default file type detector (sun.nio.fs.DefaultFileTypeDetector) as fallback, and which tries to determine the extension for filenames and URLs alike and omits characters after a supposed fragment identifier "#".
However, the implementation neglects that "#" is a valid character for most file systems (especially under Linux).
Consequently, the content type for a file named "b.png" yields "image/png", but for "a#b.png" yields null.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
On Linux, without any FileTypeDetectors installed, probe the content type for a Path where the filename contains a hash mark "#" (e.g., "a#b.png").
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Content type based on filename extension (e.g., "image/png")
---------- BEGIN SOURCE ----------
Assert.assertEquals("image/png", Files.probeContentType(Paths.get("b.png"))); // Passes
Assert.assertEquals("image/png", Files.probeContentType(Paths.get("a#b.png"))); // Fails
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Install a custom FileTypeDetector.
FREQUENCY : always
OpenJDK
A DESCRIPTION OF THE PROBLEM :
On Linux, the java.nio.file.Files.probeContentType method unexpectedly returns null if the filename contains a hash mark "#".
The problem is caused by sun.net.www.MimeTable.findByFileName(String), which is used by the default file type detector (sun.nio.fs.DefaultFileTypeDetector) as fallback, and which tries to determine the extension for filenames and URLs alike and omits characters after a supposed fragment identifier "#".
However, the implementation neglects that "#" is a valid character for most file systems (especially under Linux).
Consequently, the content type for a file named "b.png" yields "image/png", but for "a#b.png" yields null.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
On Linux, without any FileTypeDetectors installed, probe the content type for a Path where the filename contains a hash mark "#" (e.g., "a#b.png").
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Content type based on filename extension (e.g., "image/png")
---------- BEGIN SOURCE ----------
Assert.assertEquals("image/png", Files.probeContentType(Paths.get("b.png"))); // Passes
Assert.assertEquals("image/png", Files.probeContentType(Paths.get("a#b.png"))); // Fails
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Install a custom FileTypeDetector.
FREQUENCY : always
- relates to
-
JDK-8287237 (fs) Files.probeContentType returns null if filename contains hash mark on Linux
-
- Closed
-