This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 250159 - AbstractFileObject don't override getMIMEType(String... withinMIMETypes)
Summary: AbstractFileObject don't override getMIMEType(String... withinMIMETypes)
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Filesystems (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Jaroslav Havlin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-02 12:48 UTC by amaembo
Modified: 2015-02-14 06:47 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description amaembo 2015-02-02 12:48:07 UTC
AbstractFileObject overrides [1] FileObject.getMIMEType() allowing user file system to provide its own algorithm of mime type resolution by implemnting AbstractFileSystem.Info.mimeType. However it does not override getMIMEType(String... withinMIMETypes) [2] which uses default algorithm. This may result in inconsistency if user file system resolves mime type in its own way: these methods may return different result. It's hard to workaround this problem in the user code as AbstractFileObject is final and package protected and AbstractFileSystem.createFileObject is package protected too.

Expected: new method AbstractFileObject.getMIMEType(String... withinMIMETypes) which first asks Info.mimeType. If the resulting mimeType is contained in withinMIMETypes, then return it, otherwise fallback to superclass implementation.

[1] http://hg.netbeans.org/main/file/095408c482d6/openide.filesystems/src/org/openide/filesystems/AbstractFileObject.java#l190
[2] http://hg.netbeans.org/main/file/095408c482d6/openide.filesystems/src/org/openide/filesystems/FileObject.java#l674
Comment 1 Jaroslav Havlin 2015-02-13 13:26:29 UTC
Good point, I agree.

> ...If the resulting mimeType is contained in withinMIMETypes, then return it...
I'm not sure this would be the expected behavior.
Let's assume this case.

 - We have custom abstract file system that assigns MIME type "text/xamil" to
   files with extension .xml. 
 - Standard XML resolver recognized .xml files as "text/xml".

 -> fo.getMIMEType()           - would return "text/xamil"
 -> fo.getMIMEType("text/xml") - would return "text/xml", which is incorrect

Using "withinMIMETypes" should affect just performance, but never the result.
So fallback to superclass implementation should be used only if the MIME type is
not recognized by info.mimeType(path).

Fixed:
http://hg.netbeans.org/core-main/rev/45d0edb00c9a

Thank you very much for reporting.
Comment 2 amaembo 2015-02-13 15:48:46 UTC
> Using "withinMIMETypes" should affect just performance, but never the result.

Yes, sounds reasonable. Thank you very much for fixing this!
Comment 3 Quality Engineering 2015-02-14 06:47:00 UTC
Integrated into 'main-silver', will be available in build *201502140001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/45d0edb00c9a
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #250159: AbstractFileObject don't override getMIMEType(String... withinMIMETypes)