Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7497] Ti.API: Properties - inconsistencies when storing integers using setInt method that exceed datatype range

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-06-09T16:45:40.000+0000
Affected Version/sRelease 1.8.1
Fix Version/sn/a
ComponentsTiAPI
Labelsparity
ReporterPaul Dowsett
AssigneeIngo Muschenetz
Created2012-02-01T07:21:45.000+0000
Updated2017-06-09T16:45:40.000+0000

Description

Problem

While valid integers stored in platform properties using the [Titanium.App.Properties.setInt](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.App.Properties.setInt-method.html) method behave correctly, those that exceed the value are returned differently on iOS and Android. Note that I have returned the stored values using both getInt() and getDouble, out of interest, which causes an exception on Android but not on iOS. Ideally, this behavior would also be consistent.

Test case

Ti.App.Properties.setInt("NegativeNumberLowInt", -2147483647);
Ti.API.info("****** NegativeNumberLowInt   -2147483647 Saved ******");
Ti.API.info("****** NegativeNumberLowInt: " + Ti.App.Properties.getInt("NegativeNumberLowInt"));

Ti.App.Properties.setInt("NegativeNumberMediumInt", -2147483648);
Ti.API.info("****** NegativeNumberMediumInt   -2147483648 Saved ******");
Ti.API.info("****** NegativeNumberMediumInt: " + Ti.App.Properties.getInt("NegativeNumberMediumInt"));

Ti.App.Properties.setInt("NegativeNumberHigherInt", -2147483649);
Ti.API.info("****** NegativeNumberHigherInt   -2147483649 Saved ******");
Ti.API.info("****** NegativeNumberHigherInt: " + Ti.App.Properties.getInt("NegativeNumberHigherInt"));

Ti.App.Properties.setInt("NegativeNumberHighestInt", -1325269931753);
Ti.API.info("****** NegativeNumberHighestInt   -1325269931753 Saved ******");
Ti.API.info("****** NegativeNumberHighestInt: " + Ti.App.Properties.getInt("NegativeNumberHighestInt"));

Ti.API.info("----------------------------------");

Ti.App.Properties.setInt("PositiveNumberLowInt", 2147483646);
Ti.API.info("****** PositiveNumberLowInt   2147483646 Saved ******");
Ti.API.info("****** PositiveNumberLowInt: " + Ti.App.Properties.getInt("PositiveNumberLowInt"));

Ti.App.Properties.setInt("PositiveNumberMediumInt", 2147483647);
Ti.API.info("****** PositiveNumberMediumInt   2147483647 Saved ******");
Ti.API.info("****** PositiveNumberMediumInt: " + Ti.App.Properties.getInt("PositiveNumberMediumInt"));

Ti.App.Properties.setInt("PositiveNumberHigherInt", 2147483648);
Ti.API.info("****** PositiveNumberHigherInt   2147483648 Saved ******");
Ti.API.info("****** PositiveNumberHigherInt: " + Ti.App.Properties.getInt("PositiveNumberHigherInt"));

Ti.App.Properties.setInt("PositiveNumberHighestInt", 1325269931753);
Ti.API.info("****** PositiveNumberHighestInt   1325269931753 Saved ******");
Ti.API.info("****** PositiveNumberHighestInt: " + Ti.App.Properties.getInt("PositiveNumberHighestInt"));

Ti.API.info("----------------------------------");
Ti.API.info("----------------------------------");

Ti.App.Properties.setInt("NegativeNumberLowInt", -2147483647);
Ti.API.info("****** NegativeNumberLowInt   -2147483647 Saved ******");
Ti.API.info("****** NegativeNumberLowInt: " + Ti.App.Properties.getDouble("NegativeNumberLowInt"));

Ti.App.Properties.setInt("NegativeNumberMediumInt", -2147483648);
Ti.API.info("****** NegativeNumberMediumInt   -2147483648 Saved ******");
Ti.API.info("****** NegativeNumberMediumInt: " + Ti.App.Properties.getDouble("NegativeNumberMediumInt"));

Ti.App.Properties.setInt("NegativeNumberHigherInt", -2147483649);
Ti.API.info("****** NegativeNumberHigherInt   -2147483649 Saved ******");
Ti.API.info("****** NegativeNumberHigherInt: " + Ti.App.Properties.getDouble("NegativeNumberHigherInt"));

Ti.App.Properties.setInt("NegativeNumberHighestInt", -1325269931753);
Ti.API.info("****** NegativeNumberHighestInt   -1325269931753 Saved ******");
Ti.API.info("****** NegativeNumberHighestInt: " + Ti.App.Properties.getDouble("NegativeNumberHighestInt"));

Ti.API.info("----------------------------------");

Ti.App.Properties.setInt("PositiveNumberLowInt", 2147483646);
Ti.API.info("****** PositiveNumberLowInt   2147483646 Saved ******");
Ti.API.info("****** PositiveNumberLowInt: " + Ti.App.Properties.getDouble("PositiveNumberLowInt"));

Ti.App.Properties.setInt("PositiveNumberMediumInt", 2147483647);
Ti.API.info("****** PositiveNumberMediumInt   2147483647 Saved ******");
Ti.API.info("****** PositiveNumberMediumInt: " + Ti.App.Properties.getDouble("PositiveNumberMediumInt"));

Ti.App.Properties.setInt("PositiveNumberHigherInt", 2147483648);
Ti.API.info("****** PositiveNumberHigherInt   2147483648 Saved ******");
Ti.API.info("****** PositiveNumberHigherInt: " + Ti.App.Properties.getDouble("PositiveNumberHigherInt"));

Ti.App.Properties.setInt("PositiveNumberHighestInt", 1325269931753);
Ti.API.info("****** PositiveNumberHighestInt   1325269931753 Saved ******");
Ti.API.info("****** PositiveNumberHighestInt: " + Ti.App.Properties.getDouble("PositiveNumberHighestInt"));

Logs

Android

On Android: * negative numbers that are below the max limit are stored as -2147483648 * positive numbers that are above the max limit are stored as 2147483647
I/TiApplication(  990): (main) [235,235] Titanium 1.8.1 (2012/01/27 17:31 a24502a)
D/dalvikvm(  990): GC_FOR_MALLOC freed 3623 objects / 319608 bytes in 61ms
D/TiFastDev(  990): (main) [175,410] Enabling Fastdev on port 52214
D/TiFastDev(  990): (main) [9,419] sent tokens successfully
D/TiFastDev(  990): (main) [1,420] Fastdev session handshake succesful.
I/TiApplication(  990): (main) [7,427] Titanium Javascript runtime: v8
D/dalvikvm(  990): Trying to load lib /data/data/com.appcelerator.testing11/lib/libstlport_shared.so 0x44e7e580
D/dalvikvm(  990): Added shared lib /data/data/com.appcelerator.testing11/lib/libstlport_shared.so 0x44e7e580
D/dalvikvm(  990): No JNI_OnLoad found in /data/data/com.appcelerator.testing11/lib/libstlport_shared.so 0x44e7e580, skipping init
D/dalvikvm(  990): Trying to load lib /data/data/com.appcelerator.testing11/lib/libkroll-v8.so 0x44e7e580
W/TiApplication(  990): (main) [62,489] activity stack is emtpy, unable to get current activity
I/TiRootActivity(  990): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
D/dalvikvm(  990): Added shared lib /data/data/com.appcelerator.testing11/lib/libkroll-v8.so 0x44e7e580
W/TiApplication(  990): (main) [119,119] activity stack is emtpy, unable to get current activity
W/TiApplication(  990): (main) [0,119] activity stack is emtpy, unable to get current activity
W/TiApplication(  990): (main) [1,120] activity stack is emtpy, unable to get current activity
E/TiApplication(  990): (KrollRuntimeThread) [1250,1370] APP PROXY: ti.modules.titanium.app.AppModule@44ec9198
D/TiAssetHelper(  990): Fetching "app.js" with Fastdev...
D/dalvikvm(  990): GC_FOR_MALLOC freed 3137 objects / 418352 bytes in 51ms
I/TiAPI   (  990): ****** NegativeNumberLowInt   -2147483647 Saved ******
I/TiAPI   (  990): ****** NegativeNumberLowInt: -2147483647
I/TiAPI   (  990): ****** NegativeNumberMediumInt   -2147483648 Saved ******
I/TiAPI   (  990): ****** NegativeNumberMediumInt: -2147483648
I/TiAPI   (  990): ****** NegativeNumberHigherInt   -2147483649 Saved ******
I/TiAPI   (  990): ****** NegativeNumberHigherInt: -2147483648
I/TiAPI   (  990): ****** NegativeNumberHighestInt   -1325269931753 Saved ******
I/TiAPI   (  990): ****** NegativeNumberHighestInt: -2147483648
I/TiAPI   (  990): ----------------------------------
I/TiAPI   (  990): ****** PositiveNumberLowInt   2147483646 Saved ******
I/TiAPI   (  990): ****** PositiveNumberLowInt: 2147483646
I/TiAPI   (  990): ****** PositiveNumberMediumInt   2147483647 Saved ******
I/TiAPI   (  990): ****** PositiveNumberMediumInt: 2147483647
I/TiAPI   (  990): ****** PositiveNumberHigherInt   2147483648 Saved ******
I/TiAPI   (  990): ****** PositiveNumberHigherInt: 2147483647
I/TiAPI   (  990): ****** PositiveNumberHighestInt   1325269931753 Saved ******
I/TiAPI   (  990): ****** PositiveNumberHighestInt: 2147483647
I/TiAPI   (  990): ----------------------------------
I/TiAPI   (  990): ----------------------------------

// using getDouble()

I/TiAPI   (  990): ****** NegativeNumberLowInt   -2147483647 Saved ******
E/TiJSError(  990): (main) [567,1937] ----- Titanium Javascript Runtime Error -----
E/TiJSError(  990): (main) [1,1938] - In ti:/properties.js:18,20
E/TiJSError(  990): (main) [0,1938] - Message: Uncaught Error: java.lang.Integer
E/TiJSError(  990): (main) [0,1938] - Source: 			return delegate.call(Properties, key);
E/V8Exception(  990): Exception occurred at ti:/properties.js:18: Uncaught Error: java.lang.Integer
I/TiRootActivity(  990): (main) [0,0] checkpoint, on root activity resume. activity = com.appcelerator.testing11.Testing11Activity@44ee0098
I/ActivityManager(   60): Displayed activity com.appcelerator.testing11/.Testing11Activity: 4564 ms (total 4564 ms)
D/dalvikvm(  116): GC_EXPLICIT freed 135 objects / 7064 bytes in 50ms

iOS

On iOS: * negative numbers that are below the max limit are stored as 2147483647, very large negatives stored as 1874962711 * positive numbers that are above the max limit are stored as -2147483648, very large positives stored as -1874962711
[INFO] Application started
[INFO] testing11/1.0 (1.8.1.a24502a)
[INFO] ****** NegativeNumberLowInt   -2147483647 Saved ******
[INFO] ****** NegativeNumberLowInt: -2147483647
[INFO] ****** NegativeNumberMediumInt   -2147483648 Saved ******
[INFO] ****** NegativeNumberMediumInt: -2147483648
[INFO] ****** NegativeNumberHigherInt   -2147483649 Saved ******
[INFO] ****** NegativeNumberHigherInt: 2147483647
[INFO] ****** NegativeNumberHighestInt   -1325269931753 Saved ******
[INFO] ****** NegativeNumberHighestInt: 1874962711
[INFO] ----------------------------------
[INFO] ****** PositiveNumberLowInt   2147483646 Saved ******
[INFO] ****** PositiveNumberLowInt: 2147483646
[INFO] ****** PositiveNumberMediumInt   2147483647 Saved ******
[INFO] ****** PositiveNumberMediumInt: 2147483647
[INFO] ****** PositiveNumberHigherInt   2147483648 Saved ******
[INFO] ****** PositiveNumberHigherInt: -2147483648
[INFO] ****** PositiveNumberHighestInt   1325269931753 Saved ******
[INFO] ****** PositiveNumberHighestInt: -1874962711
[INFO] ----------------------------------
[INFO] ----------------------------------

// using getDouble()

[INFO] ****** NegativeNumberLowInt   -2147483647 Saved ******
[INFO] ****** NegativeNumberLowInt: -2147483647
[INFO] ****** NegativeNumberMediumInt   -2147483648 Saved ******
[INFO] ****** NegativeNumberMediumInt: -2147483648
[INFO] ****** NegativeNumberHigherInt   -2147483649 Saved ******
[INFO] ****** NegativeNumberHigherInt: 2147483647
[INFO] ****** NegativeNumberHighestInt   -1325269931753 Saved ******
[INFO] ****** NegativeNumberHighestInt: 1874962711
[INFO] ----------------------------------
[INFO] ****** PositiveNumberLowInt   2147483646 Saved ******
[INFO] ****** PositiveNumberLowInt: 2147483646
[INFO] ****** PositiveNumberMediumInt   2147483647 Saved ******
[INFO] ****** PositiveNumberMediumInt: 2147483647
[INFO] ****** PositiveNumberHigherInt   2147483648 Saved ******
[INFO] ****** PositiveNumberHigherInt: -2147483648
[INFO] ****** PositiveNumberHighestInt   1325269931753 Saved ******
[INFO] ****** PositiveNumberHighestInt: -1874962711

Related Info

[Java's Primitive Data Types](http://ibiblio.org/java/course/week2/02.html)

Comments

  1. Lee Morris 2017-06-09

    Closing ticket due to time passed, any problems please open a new ticket.

JSON Source