Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8283622

Files.probeContentType returns null if filename contains hash mark

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      linux

      Description

      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


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: