Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7777] iOS: Setting property of picker like new Date().setFullYear(2009, 0, 0) lead app to crash

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2012-02-23T14:11:39.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterEduardo Gomez
AssigneeNeeraj Gupta
Created2012-02-22T15:19:06.000+0000
Updated2017-03-09T22:53:06.000+0000

Description

Issue

Passing arguments likewise "new Date().setFullYear(2009, 0, 0)" lead the app to crash.

Steps to reproduce

Throw code below to an app.js and run

Unexpected behavior

App crashes immediately once launched

Snippet code

var win = Ti.UI.createWindow({
});

var view = Titanium.UI.createView({
    height : 260,
    bottom : -260,
    zIndex : 50
});

Ti.API.info( new Date().setFullYear(2009, 0, 0) );

var picker = Ti.UI.createPicker({
    type : Ti.UI.PICKER_TYPE_DATE,
    minDate : new Date().setFullYear(2009, 0, 0) ,
    maxDate : new Date(),
    top : 44,
    bottom : 0,
    selectionIndicator : true
});

view.add(picker);

win.add(view);

win.open();



//Sliding in & out
var slideIn = Titanium.UI.createAnimation({
bottom:50
});

var slideOut = Titanium.UI.createAnimation({
bottom:-250
});



//events to carry the slides
win.addEventListener('click', function() {
    view.animate(slideIn);
});

//if index change
picker.addEventListener('change', function() {
	view.animate(slideOut);    
});

Titanium SDK 1.8.0.1

[INFO] One moment, building ...
[INFO] Titanium SDK version: 1.8.0.1 (12/22/11 13:09 fbdc96f)
[INFO] iPhone Device family: universal
[INFO] iPhone SDK version: 5.0
[INFO] iPhone simulated device: iphone
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (2.40 seconds)
[INFO] Found 5.0 patch installed
[INFO] Application started
[INFO] T15034/1.0 (1.8.0.1.fbdc96f)
[INFO] 1230765016072
[ERROR] Invalid type passed to function. expected: NSDate, was: __NSCFNumber  in -[TiUIPicker setMinDate_:] (TiUIPicker.m:165)
2012-02-22 17:10:16.087 T15034[60656:17603] -[__NSCFNumber isEqualToDate:]: unrecognized selector sent to instance 0x8c75670
[ERROR] The application has crashed with an unhandled exception. Stack trace:
0   CoreFoundation                      0x02e67052 __exceptionPreprocess + 178
1   libobjc.A.dylib                     0x02c87d0a objc_exception_throw + 44
2   CoreFoundation                      0x02e68ced -[NSObject doesNotRecognizeSelector:] + 253
3   CoreFoundation                      0x02dcdf00 ___forwarding___ + 432
4   CoreFoundation                      0x02dcdce2 _CF_forwarding_prep_0 + 50
5   UIKit                               0x00be6eba -[UIDatePickerView setMinimumDate:] + 52
6   UIKit                               0x00be56d5 -[UIDatePicker setMinimumDate:] + 49
7   T15034                              0x00170c71 -[TiUIPicker setMinDate_:] + 897
8   CoreFoundation                      0x02e68e72 -[NSObject performSelector:withObject:] + 66
9   T15034                              0x000d16e1 DoProxyDelegateReadKeyFromProxy + 321
10  T15034                              0x000d19e3 DoProxyDelegateReadValuesWithKeysFromProxy + 627
11  T15034                              0x0008a241 -[TiUIView readProxyValuesWithKeys:] + 65
12  T15034                              0x000707d4 -[TiViewProxy firePropertyChanges] + 116
13  T15034                              0x0006e2d7 -[TiViewProxy view] + 1095
14  T15034                              0x0006e47d -[TiViewProxy view] + 1517
15  T15034                              0x0006e47d -[TiViewProxy view] + 1517
16  T15034                              0x00066143 -[TiWindowProxy openOnUIThread:] + 163
17  CoreFoundation                      0x02e68e72 -[NSObject performSelector:withObject:] + 66
18  Foundation                          0x006b09ef __NSThreadPerformPerform + 254
19  CoreFoundation                      0x02e3b97f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20  CoreFoundation                      0x02d9eb73 __CFRunLoopDoSources0 + 243
21  CoreFoundation                      0x02d9e454 __CFRunLoopRun + 1012
22  CoreFoundation                      0x02d9ddb4 CFRunLoopRunSpecific + 212
23  CoreFoundation                      0x02d9dccb CFRunLoopRunInMode + 123
24  GraphicsServices                    0x02ac6879 GSEventRunModal + 207
25  GraphicsServices                    0x02ac693e GSEventRun + 114
26  UIKit                               0x009e7a9b UIApplicationMain + 1175
27  T15034                              0x0000621a main + 442
28  T15034                              0x00002c35 start + 53
2012-02-22 17:10:16.090 T15034[60656:17603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToDate:]: unrecognized selector sent to instance 0x8c75670'
*** First throw call stack:
(0x2e67052 0x2c87d0a 0x2e68ced 0x2dcdf00 0x2dcdce2 0xbe6eba 0xbe56d5 0x170c71 0x2e68e72 0xd16e1 0xd19e3 0x8a241 0x707d4 0x6e2d7 0x6e47d 0x6e47d 0x66143 0x2e68e72 0x6b09ef 0x2e3b97f 0x2d9eb73 0x2d9e454 0x2d9ddb4 0x2d9dccb 0x2ac6879 0x2ac693e 0x9e7a9b 0x621a 0x2c35)
terminate called throwing an exception
[INFO] Application has exited from Simulator

Titanium SDK 2.0

[INFO] One moment, building ...
[INFO] Titanium SDK version: 2.0.0 (02/16/12 18:01 f0ea3e8)
[INFO] iPhone Device family: universal
[INFO] iPhone SDK version: 5.0
[INFO] iPhone simulated device: iphone
[INFO] Performing full rebuild. This will take a little bit. Hold tight...
[INFO] Skipping JS compile, running from simulator
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (39.58 seconds)
[INFO] Found 5.0 patch installed
[INFO] Application started
[INFO] T15034/1.0 (2.0.0.v20120216180135.f0ea3e8)
[INFO] 1230765259916
[ERROR] Invalid type passed to function. expected: NSDate, was: __NSCFNumber  in -[TiUIPicker setMinDate_:] (TiUIPicker.m:166)
[ERROR] Script Error = Invalid type passed to function. expected: NSDate, was: __NSCFNumber  in -[TiUIPicker setMinDate_:] (TiUIPicker.m:166) at app.js (line 25).

Definition and Usage

The setFullYear() method sets the year (four digits), according to local time. Note: This method is always used in conjunction with a Date object.

Further links

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/setFullYear

Comments

  1. Ivan Skugor 2012-02-23

    This test case is not valid. First thing is day number: dayValue An integer between 1 and 31 representing the day of the month. In test case it is defined as 0. Also, "setFullYear" does not return "Date" object, but "Number" object (that is, unix time) as can be seen in this example:
       var d = new Date();
       	
       var r = d.setFullYear(2009, 0, 1);
       
       Ti.API.info(Object.prototype.toString.call(d));
       Ti.API.info(Object.prototype.toString.call(r));
       
    The output is: [object Date] [object Number] So, to fix this example, date object needs to be passed to date picker and not a number.
  2. Neeraj Gupta 2012-02-23

    Thanks, Ivan.
  3. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source