Issue
It seems that Files.probeContentType()
returns null
for a file (where the MIME type is not indicated by its file name) on OpenJDK 11, while it was working on OpenJDK 8 (on Linux x64). What is the reason for that?
Note: It may work for files where the type is indicated by its name, e.g., "test.pdf" will produce "application/pdf", but renaming the file to "test" will produce null
.
Solution
File type detection is largely platform-specific and was not considered reliable. For instance, GnomeFileTypeDetector
was available in JDK 8, but only working on Linux systems.
The OpenJDK developers have decided to remove both GnomeFileTypeDetector
and MagicFileTypeDetector
from the JDK (already in JDK 9), see OpenJDK bug tracker and here.
Available detectors MimeTypesFileTypeDetector
(on Linux) or RegistryFileTypeDetector
on Windows simply implement a mapping from file name extensions to MIME types, but do not inspect the actual contents of files.
(Note: all detector implementations are found (or not) in package sun.nio.fs
.)
Answered By - pxcv7r
Answer Checked By - Pedro (JavaFixing Volunteer)