[ 
https://issues.apache.org/jira/browse/CB-7522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14359523#comment-14359523
 ] 

Jonathon Lamon commented on CB-7522:
------------------------------------

Ran into this issue on upgrading from Cordova 3.3.  I disagree that this is not 
a bug.  The implementation of fullPathForFilesystemPath does not make sense to 
ever return null.

It is called if the full path starts with "/".  Then if the full path matches 
the rootURI, it removes the rootURI from the path, creating a relative URI, but 
if it does not, we end up with a null pointer exception.

On IOS and Desktop platforms, using a path beginning with a "/" does not cause 
issues and the path is returned as absolute relative to to the sdcard/app 
documents.

IMO, 1 of the following should occur

1. If the path provided begins with the rootURI, then only go down the path of 
removing it.
2. if the absolutePath provided does not begin with the rootUri, simply return 
the absolutePath, instead of null.
3. continue to return null, but if URLforFilesystemPath returns null, treat it 
as a relative path instead and call URLforFullPath.

I have personally modified LcalFilesystem to do option 2, which mimics the 
behavior from cordova 3.3.

> Wrong file path leads to error code 1000 due to NullPointerException on 
> Android
> -------------------------------------------------------------------------------
>
>                 Key: CB-7522
>                 URL: https://issues.apache.org/jira/browse/CB-7522
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin File
>    Affects Versions: 3.5.0
>         Environment: Android
>            Reporter: Leon
>            Priority: Minor
>
> Hi,
> I am using Cordova version 3.5.0-0.2.6 and version 1.3.0 of the File plugin 
> on Ubuntu. 
> Yesterday I got error code 1000 (corresponds to UNKNOWN_ERR as defined in 
> android/FileUtils.java) when I tried the following JavaScript code on Samsung 
> S2 (GT-I9100) with Android 4.1.2:
> {code:title=my.js|borderStyle=solid}
> var sFileLocation = '/Android/data/<package name>/assets/';   
> sFileLocation += filesToRemove[nFile];
> fileSystem.root.getFile(
>       sFileLocation,
>       null,
>       function(entry) {
>               entry.remove( function() {
>                       console.log("file removed");
>               }, onError);
>       }, onGetFileError);
> {code}
> My investigation showed that the error code 1000 was caused by Java 
> NullPointerException from implentation of the method 
> fullPathForFilesystemPath in class *LocalFilesystem* because of the following 
> code:
> {code:title=LocalFilesystem.java|borderStyle=solid}
> private String fullPathForFilesystemPath(String absolutePath) {
>               if (absolutePath != null && 
> absolutePath.startsWith(this.fsRoot)) {
>                       return absolutePath.substring(this.fsRoot.length());
>               }
>               return null;
>       }
> {code}
> The specified path at JavaScript snippet starts with / but its prefix does 
> not match the root of dir so in Android the Java method  
> fullPathForFilesystemPath returns *null* and leads to error *1000* at the 
> JavaScript. 
> The +JavaScript snippet works fine+ if the path is specified using any of the 
> following formats: *"Android/data/<package name>/assets/"* or 
> *"/storage/sdcard0/Android/data/<package name>/assets/"*.
> It is not exactly a bug but it is very inconvenient and not developer 
> friendly. I did not find anything about this behaviour at the docuemntation 
> of the plugin. It will be much better if error code such 
> FileError.ENCODING_ERR (5) or even FileError.NOT_FOUND_ERR (1) is returned. 
> May we modify the Java code and to update the documentation to make it more 
> friendly for developers?
> Best regards,
> Leon



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to