Closed Bug 361351 Opened 18 years ago Closed 18 years ago

nsIFile.exists() should throw NOT_INITIALIZED if nsIFile is not initialized

Categories

(Core :: XPCOM, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: paulie4, Assigned: sciguyryan)

Details

Attachments

(2 files, 2 obsolete files)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 nsIFile.exists() causes an error if nsIFile is not initialized, even though it just returns false in Windows. Returning false seems like the most reasonable thing to do. This makes programming cross platform extensions more tedious. Reproducible: Always Steps to Reproduce: 1.var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile); 2.file.exists(); Actual Results: NS_ERROR_NOT_INITIALIZED on line 1: Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIFile.exists] (just false on Windows) Expected Results: false
I would assert that the behavior on linux is entirely correct. But I do agree that the same behavior should exist on all platforms.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Expected behavior should be to throw NOT_INITIALIZED on all platforms.
How does one check for initialization? (nsIFile.nativePath != "") OR (nsIFile.path != "")?
OK, this bug exists on at least Win and OSX. Unix checks for initialization here: http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsLocalFileUnix.cpp#109
OS: Linux → All
Hardware: PC → All
Summary: nsIFile.exists() causes an error if nsIFile is not initialized → nsIFile.exists() should throw NOT_INITIALIZED if nsIFile is not initialized
(In reply to comment #4) > OK, this bug exists on at least Win and OSX. Unix checks for initialization > here: > > http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsLocalFileUnix.cpp#109 > The same thing (or similar) can be done on Windows and Mac too then? I'll try and look at this tomorrow after school.
Attached patch Like this? (nsLocalFileWin v1) (obsolete) — Splinter Review
* Attempt v1. Only patch for nsLocalFileWin.cpp - if this looks correct I'll make a similar patch for Mac and OS2 if its required.
Attachment #246490 - Flags: review?(darin.moz)
Comment on attachment 246490 [details] [diff] [review] Like this? (nsLocalFileWin v1) Do all of the other platform ports behave the same? Is this something you could create a PASS/FAIL unit test for in mozilla/xpcom/tests? Maybe extend nsIFileTest.cpp or create a new test that mimics how TestTArray.cpp and TestStrings.cpp are written.
Attachment #246490 - Flags: review?(darin.moz) → review+
Assignee: nobody → sciguyryan+bugzilla
It looks like Mac already does this: http://lxr.mozilla.org/mozilla/source/xpcom/io/nsLocalFileOSX.cpp#417 For example. OS2 does appear to be affected and I will submit a patch shortly.
Attached patch nsLocalFileOS2 v1 (obsolete) — Splinter Review
* Patch v1 for nsLocalFileOS2.
Attachment #246816 - Flags: superreview?(darin.moz)
Attachment #246816 - Flags: review?(darin.moz)
Attachment #246490 - Flags: superreview?(darin.moz)
I've checked Mac and Unix and they seem to be covered in this case.(In reply to comment #7) > (From update of attachment 246490 [details] [diff] [review] [edit]) > Do all of the other platform ports behave the same? Is this something you > could create a PASS/FAIL unit test for in mozilla/xpcom/tests? > > Maybe extend nsIFileTest.cpp or create a new test that mimics how > TestTArray.cpp and TestStrings.cpp are written. > Would a test be needed in this case? If so I'll try and create one.
> It looks like Mac already does this: not for exists(): http://lxr.mozilla.org/mozilla/source/xpcom/io/nsLocalFileOSX.cpp#915
Attachment #246490 - Flags: superreview?(darin.moz)
Attachment #246816 - Flags: superreview?(darin.moz)
Attachment #246816 - Flags: review?(darin.moz)
Attached patch Merged patch v1Splinter Review
* Merged patch v1. This is a merged patch containing the changes too nsLocalFileOSX, nsLocalFileWin and nsLocalFileOS2. If there are any other functions that require initialization checking let me know and I will make a new patch as required.
Attachment #246832 - Flags: superreview?(darin.moz)
Attachment #246832 - Flags: review?(darin.moz)
Attachment #246832 - Flags: superreview?(darin.moz)
Attachment #246832 - Flags: superreview+
Attachment #246832 - Flags: review?(darin.moz)
Attachment #246832 - Flags: review+
I'll get working on a test for this as soon as I get a little free time (hopefully this week).
Status: NEW → ASSIGNED
Whiteboard: [checkin needed]
mozilla/xpcom/io/nsLocalFileOS2.cpp 1.93 mozilla/xpcom/io/nsLocalFileOSX.cpp 1.45 mozilla/xpcom/io/nsLocalFileWin.cpp 1.168
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Target Milestone: --- → mozilla1.9alpha
Attachment #246490 - Attachment is obsolete: true
Attachment #246816 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: