Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24159] Android: Null pointer exception in destroyRunners() of Android.Service

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-11-23T20:19:03.000+0000
Affected Version/sRelease 6.0.0
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsandroid, community, notable, nullpointer, service
ReporterMichael Gangolf
AssigneeGary Mathews
Created2016-11-20T13:59:08.000+0000
Updated2016-11-23T20:19:19.000+0000

Description

When working with Android background services this error appears:
11-16 09:15:04.549: W/TiJSIntervalService(17859): (main) [15,652959] Thrown while clearing interval service runners: Attempt to invoke interface method 'void java.util.List.clear()' on a null object reference
11-16 09:15:04.549: W/TiJSIntervalService(17859): java.lang.NullPointerException: Attempt to invoke interface method 'void java.util.List.clear()' on a null object reference
11-16 09:15:04.549: W/TiJSIntervalService(17859): at ti.modules.titanium.android.TiJSIntervalService.destroyRunners(TiJSIntervalService.java:114)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at ti.modules.titanium.android.TiJSIntervalService.onDestroy(TiJSIntervalService.java:125)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at android.app.ActivityThread.handleStopService(ActivityThread.java:4009)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at android.app.ActivityThread.access$2400(ActivityThread.java:210)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at android.os.Handler.dispatchMessage(Handler.java:102)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at android.os.Looper.loop(Looper.java:145)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at android.app.ActivityThread.main(ActivityThread.java:6938)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at java.lang.reflect.Method.invoke(Native Method)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at java.lang.reflect.Method.invoke(Method.java:372)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
11-16 09:15:04.549: W/TiJSIntervalService(17859): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
because the clear() method is called outside the null-check: https://github.com/appcelerator/titanium_mobile/blob/a8aceeaeee02ed9c8ea70c835a0e78960e254a55/android/modules/android/src/java/ti/modules/titanium/android/TiJSIntervalService.java#L113 Example and PR will follow

Comments

  1. Michael Gangolf 2016-11-22

    app.js
       var win = Ti.UI.createWindow({});
       var intent = Titanium.Android.createServiceIntent({
           url: 'myservice.js'
       });
       Titanium.Android.stopService(intent);
       var service = Titanium.Android.createService(intent);
       service.start();
       service.stop();
       
       win.open();
       
    myservice.js
       var service = Ti.Android.currentService;
       
       function showNotification() {
           var intent = Ti.Android.createIntent({
               action: Ti.Android.ACTION_MAIN,
               className: 'com.miga.service.VetmedicaActivity',
               packageName: 'com.miga.service'
           });
           intent.flags |= Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK;
           intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
       
           var pending = Titanium.Android.createPendingIntent({
               intent: intent,
               flags: Titanium.Android.FLAG_UPDATE_CURRENT
           });
       
           var notification = Titanium.Android.createNotification({
               icon: Ti.App.Android.R.drawable.appicon,
               contentTitle: "title",
               contentText: "text",
               contentIntent: pending
           });
           
           Titanium.Android.NotificationManager.notify(1, notification);
           Ti.Android.stopService(intent);
       }
       
       showNotification();
       
    tiapp.xml addition:
       ...
       <android xmlns:android="http://schemas.android.com/apk/res/android">
               <services>
                   <service url="myservice.js" type="interval"/>
               </services>
           </android>
       ...
       
    PR: https://github.com/appcelerator/titanium_mobile/pull/8634
  2. Hans Knöchel 2016-11-22

    Good catch! Assigning to [~gmathews] to review for 6.1.0. Thx!
  3. Samir Mohammed 2016-11-23

    Verified fixed, was no longer able to see the error caused by Android background services (error shown in the description) on SDK version 6.1.0.v20161123033537. *Environement*
       Appcelerator Command-Line Interface, version 6.0.0
       Android 7.0 (Google Nexus 6P)
       Operating System Name: Mac OS X El Capitan
       Operating System Version: 10.11.6
       Node.js Version: 4.6.0
       npm: 4.2.8
       Titanium CLI Version: 5.0.10
       Titanium SDK Version: 6.1.0.v20161123033537
       Xcode: 8.0
       Appcelerator Studio: 4.8.0.201611121409
       

JSON Source