apache / apache/cordova-plugin-file-transfer

NullPointerException When Downloading File

Open
#378 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
606
Forks
874
PR merge metrics
No merged PRs in 30d

Description

# Bug Report

## Problem

### What is expected to happen?
The file is downloaded and stored onto the device.

### What does actually happen?
An error showing that the file name is null and throws null pointer exception

## Information

`{"code":3,"source":"https:\/\/sample.io\/images\/logo.png","target":"https:\/\/localhost\/__cdvfile_persistent__\/imgcache\/04a568427e026c9d4dc0275d9ba360c7a24326be.png","http_status":200,"exception":"java.lang.NullPointerException"}
java.lang.NullPointerException
at java.io.FileOutputStream.(FileOutputStream.java:227)
at java.io.FileOutputStream.(FileOutputStream.java:186)
at org.apache.cordova.filetransfer.FileTransfer$2.run(FileTransfer.java:796)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)`

### Command or Code

`var fileTransfer = new Private.FileTransferWrapper(ImgCache.attributes.filesystem);
fileTransfer.download(
img_src,
filePath,
function (entry) {
entry.getMetadata(function (metadata) {
if (metadata && ('size' in metadata)) {
ImgCache.overridables.log('Cached file size: ' + metadata.size, LOG_LEVEL_INFO);
Private.setCurrentSize(ImgCache.getCurrentSize() + parseInt(metadata.size, 10));
} else {
ImgCache.overridables.log('No metadata size property available', LOG_LEVEL_INFO);
}
});
ImgCache.overridables.log('Download complete: ' + Helpers.EntryGetPath(entry), LOG_LEVEL_INFO);

// iOS: the file should not be backed up in iCloud
// new from cordova 1.8 only
if (entry.setMetadata) {
entry.setMetadata(
function () {
/* success*/
ImgCache.overridables.log('com.apple.MobileBackup metadata set', LOG_LEVEL_INFO);
},
function () {
/* failure */
ImgCache.overridables.log('com.apple.MobileBackup metadata could not be set', LOG_LEVEL_WARNING);
},
{
// 1=NO backup oddly enough..
'com.apple.MobileBackup': 1
}
);
}

if (success_callback) {
success_callback(entry.toURL());
}
},
function (error) {
if (error.source) { ImgCache.overridables.log('Download error source: ' + error.source, LOG_LEVEL_ERROR); }
if (error.target) { ImgCache.overridables.log('Download error target: ' + error.target, LOG_LEVEL_ERROR); }
ImgCache.overridables.log('Download error code: ' + error.code, LOG_LEVEL_ERROR);
if (error_callback) { error_callback(error); }
},
on_progress
);`

### Environment, Platform, Device

Android@13.0
Android Tablet

### Version information

Android Studio: Latest version as of this posting
Cordova Plugins:
cordova-plugin-device 3.0.0 "Device"
cordova-plugin-file-transfer 2.0.0 "File Transfer"
cordova-plugin-file 8.1.0 "File"

## Checklist

- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start by inspecting the Android download path at org.apache.cordova.filetransfer.FileTransfer.java:796 and compare it with the FileTransferWrapper.download call shown in the report. Reproduce the Android 13 download using the supplied source and target, then verify that a successful HTTP 200 response stores the file without a NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.