Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8085] Android: Exception when getting the events between 2 dates

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-06-03T20:10:39.000+0000
Affected Version/sRelease 2.0.0, Release 3.1.1
Fix Version/sRelease 2.0.0, Sprint 2012-06
ComponentsAndroid
Labelsmodule_android, qe-3.1.1, qe-testadded
ReporterEduardo Gomez
AssigneeOpie Cyrus
Created2012-03-19T13:41:16.000+0000
Updated2017-03-16T20:54:36.000+0000

Description

Issue

Error when trying to get the events between 2 dates.

To reproduce

1. Run code below 2. Monitor console output i.e. eGomez-MacBook-Pro:platform-tools egomez$ ./adb -d logcat

Repro sequence

var startDate = new Date(2012, 03, 10, 12, 0, 0);
var endDate = new Date(2012, 03, 19, 14, 0, 0);

        var out = [];
        var calendars = Ti.Android.Calendar.allCalendars;
        Ti.API.info('-> '+JSON.stringify(calendars));
        for (var i=0; i < calendars.length; i++) {
            Ti.API.info('=> '+JSON.stringify(calendars[i]));
                var cal_events = calendars[i].getEventsBetweenDates(startDate,endDate);

                for (var j=0; j < cal_events.length; j++) {
                    out.push(cal_events[j]);
                };
        };

Console output Ti SDK 2.0

=com.appcelerator.com/.T15422Activity }
I/ActivityManager( 1345): Start proc com.appcelerator.com for activity com.appcelerator.com/.T15422Activity: pid=6674 uid=10071 gids={1015, 3003}
I/TiApplication( 6674): (main) [0,0] checkpoint, app created.
I/TiApplication( 6674): (main) [247,247] Titanium 2.0.0 (2012/03/18 15:48 fc5c94a)
I/TiDbHelper( 6674): (main) [2020,2267] No value in database for platform key: 'unique_machine_id' returning supplied default ''
I/TiDbHelper( 6674): (main) [18,2285] No value in database for platform key: 'hardware_machine_id' returning supplied default ''
I/TiApplication( 6674): (main) [197,2482] Titanium Javascript runtime: v8
I/TiRootActivity( 6674): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
D/TiAnalyticsDb( 6674): (main) [100,100] Creating Database tianalytics.db
I/TiAnalyticsDb( 6674): (main) [227,327] Upgrading Database from 1 to 4
D/WifiStateTracker( 1345): WifiStateTracker.requestConnectionStatus() reply is null init values.
E/TiApplication( 6674): (KrollRuntimeThread) [1972,2299] APP PROXY: ti.modules.titanium.app.AppModule@44a689d8
I/TiAPI   ( 6674): -> [{"hidden":false,"id":"1","selected":true,"name":"eduardo.www@gmail.com"}]
I/TiAPI   ( 6674): => {"hidden":false,"id":"1","selected":true,"name":"eduardo.www@gmail.com"}
03-19 10:01:22.375: W/System.err(22687): java.lang.NullPointerException
03-19 10:01:22.375: W/System.err(22687):    at ti.modules.titanium.android.calendar.EventProxy.queryEventsBetweenDates(EventProxy.java:86)
03-19 10:01:22.375: W/System.err(22687):    at ti.modules.titanium.android.calendar.EventProxy.queryEventsBetweenDates(EventProxy.java:210)
03-19 10:01:22.380: W/System.err(22687):    at ti.modules.titanium.android.calendar.CalendarProxy.getEventsBetweenDates(CalendarProxy.java:146)
03-19 10:01:22.380: W/System.err(22687):    at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
03-19 10:01:22.380: W/System.err(22687):    at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:60)
03-19 10:01:22.380: W/System.err(22687):    at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:494)
03-19 10:01:22.380: W/System.err(22687):    at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:675)
03-19 10:01:22.380: W/System.err(22687):    at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:392)
03-19 10:01:22.380: W/System.err(22687):    at android.os.Handler.dispatchMessage(Handler.java:95)
03-19 10:01:22.380: W/System.err(22687):    at android.os.Looper.loop(Looper.java:132)
03-19 10:01:22.380: W/System.err(22687):    at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)
03-19 10:01:22.390: E/TiJSError(22687): (main) [7740,11480] ----- Titanium Javascript Runtime Error -----
03-19 10:01:22.395: E/TiJSError(22687): (main) [0,11480] - In helpers/calendar_helper.js:62,35
03-19 10:01:22.395: E/TiJSError(22687): (main) [0,11480] - Message: Uncaught Error: Java Exception occurred
03-19 10:01:22.395: E/TiJSError(22687): (main) [0,11480] - Source:              var cal_events = calendars[i].getEventsBetweenDates(startDate,endDate);

Attachments

FileDateSize
Event_app.txt2013-06-03T10:41:42.000+00002112
event_exception.txt2013-06-03T10:41:42.000+0000582

Comments

  1. Opie Cyrus 2012-03-19

    Opened PR https://github.com/appcelerator/titanium_mobile/pull/1752 to address the source of the error. I was unable to reproduce failure against master. What device and OS version (3.x.x) specifically (also runtime) was this reproduced on?
  2. Eduardo Gomez 2012-03-20

    Device

    Galaxy Tab 7 Plus model GT-P6210 Android version 3.2 Kernel 2.6.36-P6210UEKJC-CL567728 se.infra@SEI-20 #3

    Runtime

    V8
  3. Dustin Hyde 2012-03-21

    Closing as Fixed. SDK: 2.0.0.v20120321071752 Android: V8 Studio: 2.0.0.201203202130 OS: Snow Leopard Devices Tested: Droid3 2.3.4, GSlate 3.1, Galaxy Tab 10.1 3.2 Note: Tested on available 3.X devices as per Thomas. Test Code:
       var startDate = new Date(2012, 03, 10, 12, 0, 0);
       var endDate = new Date(2012, 03, 19, 14, 0, 0);
       
       var out = [];
       var calendars = Ti.Android.Calendar.allCalendars;
       Ti.API.info('-> '+JSON.stringify(calendars));
       for (var i=0; i < calendars.length; i++) {
           Ti.API.info('=> '+JSON.stringify(calendars[i]));
               var cal_events = calendars[i].getEventsBetweenDates(startDate,endDate);
       
               for (var j=0; j < cal_events.length; j++) {
                   out.push(cal_events[j]);
               };
       };
       
       //...
       <android xmlns:android="http://schemas.android.com/apk/res/android">
               <manifest>
                   <uses-permission android:name="android.permission.READ_CALENDAR"/>
                   <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
               </manifest>
           </android>
       //...
       
  4. Wilson Luu 2012-04-19

    Reopening to update labels.
  5. Paras Mishra 2013-06-03

    Runtime error occurred as: Uncaught Error: Java Exception occurred Log file "event_exception.txt" is attached. App file is Event_app.txt Tested on: Device : Google Nexus 7, Android Version: 4.1 SDK: 3.1.1.v20130531163723 CLI version : 3.1.0 OS : MAC OSX 10.7.5 Appcelerator Studio, build: 3.1.1.201306012403 XCode : 4.5.1
  6. Ping Wang 2013-06-03

    Ran the test case in Description on Nexus 7 (4.1) with the latest 3.1.1 and it works fine. Ran the attached "Event_app.txt" on Nexus 7 (4.1) with the latest 3.1.1. It crashes with the OutOfMemoryError:
       E/dalvikvm-heap( 4097): Out of memory on a 142794-byte allocation.
       I/dalvikvm( 4097): "KrollRuntimeThread" prio=5 tid=10 RUNNABLE
       I/dalvikvm( 4097):   | group="main" sCount=0 dsCount=0 obj=0x41e86d20 self=0x675021f0
       I/dalvikvm( 4097):   | sysTid=4111 nice=0 sched=0/0 cgrp=apps handle=1737923368
       I/dalvikvm( 4097):   | schedstat=( 6260051000 703337000 2367 ) utm=575 stm=51 core=3
       I/dalvikvm( 4097):   at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:64)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:835)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1059)
       I/dalvikvm( 4097):   at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:316)
       I/dalvikvm( 4097):   at android.os.Handler.dispatchMessage(Handler.java:95)
       I/dalvikvm( 4097):   at android.os.Looper.loop(Looper.java:137)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
       I/dalvikvm( 4097): 
       I/dalvikvm-heap( 4097): Clamp target GC heap from 65.282MB to 64.000MB
       D/dalvikvm( 4097): GC_FOR_ALLOC freed 1K, 2% free 64450K/65543K, paused 44ms, total 44ms
       I/dalvikvm-heap( 4097): Forcing collection of SoftReferences for 142796-byte allocation
       I/dalvikvm-heap( 4097): Clamp target GC heap from 65.282MB to 64.000MB
       D/dalvikvm( 4097): GC_BEFORE_OOM freed 0K, 2% free 64450K/65543K, paused 51ms, total 51ms
       E/dalvikvm-heap( 4097): Out of memory on a 142796-byte allocation.
       I/dalvikvm( 4097): "KrollRuntimeThread" prio=5 tid=10 RUNNABLE
       I/dalvikvm( 4097):   | group="main" sCount=0 dsCount=0 obj=0x41e86d20 self=0x675021f0
       I/dalvikvm( 4097):   | sysTid=4111 nice=0 sched=0/0 cgrp=apps handle=1737923368
       I/dalvikvm( 4097):   | schedstat=( 6357626000 705372000 2391 ) utm=584 stm=51 core=3
       I/dalvikvm( 4097):   at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:64)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:835)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1059)
       I/dalvikvm( 4097):   at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:316)
       I/dalvikvm( 4097):   at android.os.Handler.dispatchMessage(Handler.java:95)
       I/dalvikvm( 4097):   at android.os.Looper.loop(Looper.java:137)
       I/dalvikvm( 4097):   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
       I/dalvikvm( 4097): 
       W/dalvikvm( 4097): Exception thrown (Ljava/lang/OutOfMemoryError;) while throwing internal exception (Ljava/lang/OutOfMemoryError;)
       W/System.err( 4097): java.lang.OutOfMemoryError
       W/System.err( 4097): 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
       W/System.err( 4097): 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:64)
       W/System.err( 4097): 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:835)
       W/System.err( 4097): 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1059)
       W/System.err( 4097): 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:316)
       W/System.err( 4097): 	at android.os.Handler.dispatchMessage(Handler.java:95)
       W/System.err( 4097): 	at android.os.Looper.loop(Looper.java:137)
       W/System.err( 4097): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
       E/TiExceptionHandler( 4097): (main) [17077,17183] ----- Titanium Javascript Runtime Error -----
       E/TiExceptionHandler( 4097): (main) [0,17183] - In app.js:68,55
       E/TiExceptionHandler( 4097): (main) [0,17183] - Message: Uncaught Error: Java Exception occurred
       E/TiExceptionHandler( 4097): (main) [0,17183] - Source: 	        label.text += 'Description: ' + cal_events[j].description + '\n';
       D/dalvikvm( 4097): GC_FOR_ALLOC freed 52091K, 81% free 12687K/65543K, paused 45ms, total 45ms
       E/V8Exception( 4097): Exception occurred at app.js:68: Uncaught Error: Java Exception occurred
       
    This is because in "Event_app.txt" it appended all the info from 3485 events to ONE string. Modified the code and then it runs without any problem:
       var calendars = [];
       var selectedCalendar = null;
       var selectedCalendarName = '';
       var pickerData = [];
       
       var win = Ti.UI.createWindow({
         backgroundColor: 'white',
         exitOnClose: true,
         fullscreen: false,
         layout: 'vertical',
         title: 'TIMOB-8085'
       });
       
       var scrollView = Ti.UI.createScrollView({
         backgroundColor: '#eee',
         height: 500,
         top: 20,
         layout: 'vertical'
       });
       
       var label = Ti.UI.createLabel({
         backgroundColor: 'white',
         text: 'Click on the button to display the events for the selected calendar',
         textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
         top: 20
       });
       scrollView.add(label);
       
       var selectableCalendars = Ti.Android.Calendar.selectableCalendars;
       for (var i = 0; i< selectableCalendars.length; i++) {
       	
         	calendars.push({ name: selectableCalendars[i].name, calendarObj: selectableCalendars[i] });
        	pickerData.push( Ti.UI.createPickerRow({ title: calendars[i].name }) );
         
         	if(i === 0){
         		selectedCalendar = selectableCalendars[i];
         	}
       }
       
       if(!calendars.length){
         label.text = 'No calendars available. Select at least one in the native calendar before using this app';
       } else {
         	label.text = 'Click button to view calendar events';
         
         	var picker = Ti.UI.createPicker({
         	  top:20
         	});
         	
         	picker.add(pickerData);
         	win.add(picker);
         
         	picker.addEventListener('change', function(e){
           	selectedCalendar = calendars[e.rowIndex].calendarObj;
         	});
       
       	var button = Ti.UI.createButton({
       	    title: 'View events',
       	    top: 20
       	});
       	win.add(button);
         
       	button.addEventListener('click', function(e){
         		label.text = '';
           	label.text = 'Generating...';
           
           	var cal_events = selectedCalendar.getEventsBetweenDates(new Date(1990, 1, 0), new Date(2100, 31, 11));
           	label.text = cal_events.length > 0 ? '' : 'No events.'; 
           	Ti.API.info("*********************** cal_events.length = " + cal_events.length);
           	for (var j=0; j < cal_events.length; j++) {
           		var label1 = Ti.UI.createLabel();
       	        label1.text += 'Description: ' + cal_events[j].description + '\n';
       	        label1.text += 'Start Date: ' + JSON.stringify(cal_events[j].begin) + '\n';
       	        label1.text += 'End Date: ' + JSON.stringify(cal_events[j].end) + '\n';
       	        label1.text += '\n';
       	        scrollView.add(label1);
           	}
           
         	});
       }
       
       win.add(scrollView);
       
       win.open();
       
    Resolve the ticket as Fixed.
  7. jithinpv 2013-11-11

    Anvil test case added. https://github.com/appcelerator/titanium_mobile/pull/4944
  8. Lee Morris 2017-03-16

    Closing ticket as fixed.

JSON Source