Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6460] Android is crashing when trying to delete a file in applicationDataDir

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2020-02-05T22:33:16.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid-10, android-8, android-9
ReporterCaio Perdona
AssigneeNazmus Salahin
Created2019-12-20T19:30:56.000+0000
Updated2020-09-11T18:38:46.000+0000

Description

When trying to delete a file inside applicationDataDir, android crashes with the following log:
[ERROR] TiExceptionHandler: (main) [1030,328883] ti:/invoker.js:105
[ERROR] TiExceptionHandler: 		return delegate.apply(invoker.__thisObj__, args);
[ERROR] TiExceptionHandler:                   ^
[ERROR] TiExceptionHandler: Error: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
[ERROR] TiExceptionHandler:     at SandboxAPI.invoker [as getFile] (ti:/invoker.js:105:19)
[ERROR] TiExceptionHandler:     at Object.exports.getf (/api.js:136:21)
[ERROR] TiExceptionHandler:     at deleteFiles (/form/form4.js:2240:5)
[ERROR] TiExceptionHandler:     at Titanium.checkStatus (/form/form4.js:2191:1)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.io.TiFileFactory.createTitaniumFile(TiFileFactory.java:88)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiFileProxy.<init>(TiFileProxy.java:83)
[ERROR] TiExceptionHandler:     ti.modules.titanium.filesystem.FileProxy.<init>(FileProxy.java:18)
[ERROR] TiExceptionHandler:     ti.modules.titanium.filesystem.FilesystemModule.getFile(FilesystemModule.java:92)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:55)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:41)
[ERROR] TiExceptionHandler:     ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:167)
[ERROR] TiExceptionHandler:     android.os.Handler.handleCallback(Handler.java:873)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:99)
[ERROR] V8Exception: Exception occurred at ti:/invoker.js:105: Uncaught Error: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
The code that's triggering is:
var photoCacheDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "myapp");
if (!photoCacheDir.exists()) {  photoCacheDir.createDirectory(); }

Ti.Filesystem.getFile(photoCacheDir.resolve(), fname).deleteFile();

Comments

  1. Nazmus Salahin 2019-12-21

    Hello! Thanks for reaching to us. What is your Ti SDK version? Could you share the steps to reproduce the issue in our end? Also, please share the complete trace. Thanks
  2. Caio Perdona 2019-12-26

    @Nazmus Ti-SDK 8.3.0.GA I've already provided the steps to reproduce. var photoCacheDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "myapp"); if (!photoCacheDir.exists()) { photoCacheDir.createDirectory(); } Ti.Filesystem.getFile(photoCacheDir.resolve(), fname).deleteFile(); When Ti tries to delete the file, the app crashes with the log given above.
  3. Motiur Rahman 2019-12-30

    [~perdona] I could not reproduce this issue. Please try with this sample code
       // create our starting file
       var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'myfile.txt');
       f.write('This is not empty');
       
       // get a handle to the as-yet non-existent directory
       var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'mysubdir');
       
       if (dir.exists() == false) {
       	// this creates the directory
       	Ti.API.info('Directory list to start: ' + dir.getDirectoryListing());
       	dir.createDirectory();
       	// let's move myfile.txt to our directory
       	f.move('mysubdir/myfile.txt');
       	
       }
       
       // output a directory listing
       Ti.API.info('Dir list with file: ' + dir.getDirectoryListing());
       
       var contents = f.read();
       Ti.API.info('Output as a blob: ' + contents);
       // useful if contents are binary
       Ti.API.info('Output text of the file: ' + contents.text);
       
       Ti.Filesystem.getFile(dir.resolve(), f).deleteFile();
       
    If the issue persists then share a runnable test case. Thanks!
  4. Caio Perdona 2020-01-06

    @Motiur, it is still happening here. Followed the same steps as you've done above. Turns out that the bug happens on the line with "Ti.Filesystem.getFile(dir.resolve(), f)" When I downgrade SDK to 8.2.1.GA the bug DOES NOT HAPPEN. How do we proceed?
  5. Motiur Rahman 2020-01-08

    [~perdona] Can you please share a reproducible test case? I could not reproduce the crash?
  6. AppDev 2020-01-09

    Happens to us as well on Android with 8.3.0.GA. Downgrading to 8.2.1.GA helped luckily. Unfortunately I am currenty unable to provide another test case. Would appreciate a fix though. Perhaps related to file system access permissions?
  7. Caio Perdona 2020-01-09

    Same here @AppDev.
  8. Caio Perdona 2020-01-09

    @Motiur, now I really don't have the time to share a runnable app, and this is kind of ineffective, bearing in mind that my app might have other properties and implementations that are different than the sample I would share, thus not reproducing the crash.
  9. Gary Mathews 2020-01-15

    This is addressed by https://github.com/appcelerator/titanium_mobile/pull/11395
  10. Ygor Lemos 2020-02-05

    @Gary, is this expected to drop on 8.3.2.GA ?
  11. Gary Mathews 2020-02-05

    [~ygbr] Looks like it's only scheduled for 9.0.0.GA
  12. Ygor Lemos 2020-02-17

    Isn't this critical enough for backporting the fix to 8.X.X?
  13. Ygor Lemos 2020-02-17

    PS: it seems simple enough for backporting the fix by applying https://github.com/appcelerator/titanium_mobile/pull/11395/files to https://github.com/appcelerator/titanium_mobile/blob/e9ef3702af3f75327af9056ec0bb9a7bf209e130/android/titanium/src/java/org/appcelerator/titanium/io/TitaniumBlob.java#L89 This has become a blocker on our main production app since we can't delete files anymore on android, filling users storage unnecessarily.
  14. Michael Gangolf 2020-02-17

    [~ygbr]: here is the 8.3.1 branch with the TitaniumBlob changes merged in: https://migaweb.de/mobilesdk-8.3.1-linux.zip
  15. Caio Perdona 2020-02-17

    @miga Can you provide the OSX version, please?
  16. Michael Gangolf 2020-02-18

    since it is only an Android change you can just rename the linux part to osx or use the iOS version from here: http://builds.appcelerator.com/#8_3_X and replace the Android folder with the one from my zip
  17. Snigdha Nooli 2020-09-09

    Hi Michael, We are facing the same issue in production with 8.3.1GA SDK. Unfortunately we can't move to 9.0 GA SDK currently. We tried to use above 8.3.1 branch with bob changes but could not access the link https://migaweb.de/mobilesdk-8.3.1-linux.zip Could you please help us on this.
  18. Michael Gangolf 2020-09-10

    [~Snigdha.Nooli] I've rebuild the SDK and the link is working again. Normally you can just clone the repo, include the PR and build it yourself
  19. Snigdha Nooli 2020-09-11

    Thanks for the help Michael.

JSON Source