[ 
https://issues.apache.org/jira/browse/CB-4504?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Joe Bowser resolved CB-4504.
----------------------------

    Resolution: Fixed

This is kind of a stupid fix for a very stupid bug in the Android SDK.

As usual, the Android Team never modified their Java API to properly cope with 
their file://android_asset and file://android_res URIs and when you try to 
write to either in Java, the filename gets lost because these aren't writable. 
They seem to think that putting the data on console.log is fine, which it 
mostly is, except that if you're only developing in JS, you will never see this.

So, we catch the NullPointerException with the expectation that the Java API 
won't throw NullPointerExceptions for any other reason other than this file URI 
stupidity, we then throw the correct exception which gets passed. I have no 
idea why Google couldn't just throw the right exception to begin with, but it 
gives me another shot to contribute to AOSP or Cyanogen.
                
> Attempt to write file to file:///android_asset folder crashes
> -------------------------------------------------------------
>
>                 Key: CB-4504
>                 URL: https://issues.apache.org/jira/browse/CB-4504
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.9.0
>         Environment: Android v4.3 emulator
>            Reporter: Peter
>            Assignee: Joe Bowser
>            Priority: Minor
>
> I wrote a Jasmine test case which attempts to write to the *android_assets* 
> folder. 
> The test expects the FileWriter.onerror callback will be called with some 
> appropriate error code. Instead, Cordova fails internally.
> It appears that FileHelper.getRealPath returns null, which the 
> FileUtils.write is not coping with, and when the null is passed to 
> FileOutputStream that throws NPE, which nobody is handling...
> Test code fragment:
> {code}
> it("onerror is called if write to file:///android_asset", function() {
>       var theWriter,
>       filePath = "file:///android_asset/jumpyfox.txt",
>       // file content
>       fox = "The quick brown fox";
>       // callbacks                
>       var onerrorCB = jasmine.createSpy().andCallFake(function(a) {
>               
> expect(theWriter.error.code).toBe(FileError.NO_MODIFICATION_ALLOWED_ERR);
>               
> expect(a.target.error.code).toBe(FileError.NO_MODIFICATION_ALLOWED_ERR);
>       });
>       // writes initial file content
>       var write_file = function(file) {
>               theWriter = new FileWriter(file);
>               theWriter.onerror = onerrorCB;
>               theWriter.write(fox);
>       };
>       // create file, then write to it
>       runs(function() {
>               var file = new File();
>               file.fullPath = filePath;
>               write_file(file);
>       });
>       waitsFor(function() { return onerrorCB.wasCalled; }, "onerrorCB never 
> called", Tests.TEST_TIMEOUT);
> });
> {code}
> Maybe other scenarios which call FileHelper.getRealPath could have similar 
> consequences if it returns null.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to