Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-8689

Unhandled NullPointerException thrown resolving a file entry

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.3.0, 3.5.0
    • None
    • cordova-plugin-file
    • None

    Description

      This is the log of the exception:

      03-16 20:38:33.961  31560-31859/com.f.tc E/FileTransfer﹕ {"code":3,"source":"https:\/\/localdev.f.com\/static\/tc\/resources\/css\/app.css","target":"file:\/\/\/data\/data\/com.f.tc\/files\/wwwTmp\/resources\/css\/app.css","http_status":200,"exception":"Attempt to read from field 'java.lang.String org.apache.cordova.file.LocalFilesystemURL.path' on a null object reference"}
          java.lang.NullPointerException: Attempt to read from field 'java.lang.String org.apache.cordova.file.LocalFilesystemURL.path' on a null object reference
                  at org.apache.cordova.file.Filesystem.makeEntryForURL(Filesystem.java:56)
                  at org.apache.cordova.file.Filesystem.makeEntryForNativeUri(Filesystem.java:91)
                  at org.apache.cordova.file.Filesystem.makeEntryForFile(Filesystem.java:99)
                  at org.apache.cordova.file.FileUtils.getEntryForFile(FileUtils.java:895)
                  at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:902)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                  at java.lang.Thread.run(Thread.java:818)
      

      The fix is that in FileSystem.java, the following method:

          public JSONObject makeEntryForNativeUri(Uri nativeUri) {
              LocalFilesystemURL inputUrl = toLocalUri(nativeUri);
              return makeEntryForURL(inputUrl, nativeUri);
          }
      

      should be changed to:

          public JSONObject makeEntryForNativeUri(Uri nativeUri) {
              LocalFilesystemURL inputUrl = toLocalUri(nativeUri);
              return inputUrl != null ? makeEntryForURL(inputUrl, nativeUri) : null;
          }
      

      With that change, I can successfully download the file using FileTransfer, which depends on the File plugin.

      Attachments

        Activity

          People

            agrieve Andrew Grieve
            jacobgu Jacob G
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: