JDK-7133484 : (fs) Need FileTypeDetector implementation for MacOSX
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7u4
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-01-26
  • Updated: 2015-06-12
  • Resolved: 2013-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Duplicate :  
Description
From http://java.net/jira/browse/MACOSX_PORT-153 --

Files.probeContentType return null for htm/html files

Test for reproducing issue:

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class ContentTypeTest {

public static void main(String[] argv) {
String[] input = {"index.html", "index.htm"};
int failCount = 0;
try {
for (String s : input) {
Path path = Paths.get(s);
String filetype = Files.probeContentType(path);
if (filetype == null || !filetype.equals("text/html")) { System.out.println(path.toString() + " - file type is not text/html; file type is - " + filetype); failCount++; } else { System.out.println(path.toString() + " - file type is text/html"); }
}
} catch (Exception e) { e.printStackTrace(); }
if(failCount > 0) { System.out.println("TEST FAIL!"); } else { System.out.println("TEST PASS!"); }
}
}

Test result:

index.html - file type is not text/html; file type is - null
index.htm - file type is not text/html; file type is - null
TEST FAIL!

Comments
Don't be ridiculous. What users are going to know that they need to do that, and how to do it? That's equivalent to asking each individual user to patch this bug. End users are not ever going to do that. This issue was marked as fixed after one internal person patched a single machine to work. That is the only known OS X machine that this method works on. Note also that while it is true that the documentation says that "it returns null when the file type is not recognized", it also states that there is a default implementation, which would imply that it is possible to get something other than a null response. On OS X null is returned always.. the default implementation does nothing useful on any typical end user's system.
12-06-2015

~/mime.types can be created by the user, there isn't a system wide MIME type tables that we are aware of OS X.
12-06-2015

~/mime.types is not present on OS X. This bug should be re-opened and a reasonable solution should be investigated.
12-06-2015

The FileTypeDetector included on Mac uses mime types file and was added in the fix of JDK-7142921. It requires ~/.mime.types file to be present.
17-05-2013

EVALUATION I've changed the synopsis to reflect what this issue is about. In summary, we need a FileTypeDetector for MacOSX that plugs into its file type associations. This is not critical for 7u4 as the Files.probeContentType method is very clear that it returns null when the file type is not recognized (which is the case with the test case).
26-01-2012