Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-17889

TiConvert toBoolean doesnt handle type Interger

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 7.3.0
    • Component/s: Android
    • Environment:

      Titanium SDK 3.4.0.GA - building for Android

    • Story Points:
      1
    • Sprint:
      2018 Sprint 05 SDK

      Description

      Problem

      Have tracked down a pesky problem where setting the visible property of a TiLabel >> TiView to 0 (type integer) crashed the application. (see log below)

      Pulled SDK and updated the method to have a case where it handles an input of type Integer. Built the SDK and ran the App. All fixed. Example below of what I added. I don't know Java but it gives you an idea of what to look at.

      Logs

      console

      [ERROR] :  AndroidRuntime: FATAL EXCEPTION: main
      [ERROR] :  AndroidRuntime: java.lang.IllegalArgumentException: Unable to convert java.lang.Integer to boolean.
      [ERROR] :  AndroidRuntime: 	at org.appcelerator.titanium.util.TiConvert.toBoolean(TiConvert.java:357)
      [ERROR] :  AndroidRuntime: 	at org.appcelerator.titanium.view.TiUIView.propertyChanged(TiUIView.java:723)
      [ERROR] :  AndroidRuntime: 	at ti.modules.titanium.ui.widget.TiUILabel.propertyChanged(TiUILabel.java:280)
      [ERROR] :  AndroidRuntime: 	at org.appcelerator.kroll.KrollPropertyChange.fireEvent(KrollPropertyChange.java:21)
      [ERROR] :  AndroidRuntime: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1059)
      [ERROR] :  AndroidRuntime: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347)
      [ERROR] :  AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:95)
      [ERROR] :  AndroidRuntime: 	at android.os.Looper.loop(Looper.java:137)
      [ERROR] :  AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:4745)
      [ERROR] :  AndroidRuntime: 	at java.lang.reflect.Method.invokeNative(Native Method)
      [ERROR] :  AndroidRuntime: 	at java.lang.reflect.Method.invoke(Method.java:511)
      [ERROR] :  AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
      [ERROR] :  AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
      [ERROR] :  AndroidRuntime: 	at dalvik.system.NativeStart.main(Native Method)
      

      Changes

      org.appcelerator.titanium.util.TiConvert.toBoolean(TiConvert.java:357)

      console

      public static boolean toBoolean(Object value)
      	{
      		if (value instanceof Boolean) {
      			return (Boolean) value;
      		} else if (value instanceof String) {
      			return Boolean.parseBoolean(((String) value));
      		} 
      		// -- added handling for Integer
      		else if (value instanceof Integer) {
      			int numeric = (Integer) value;
      			return numeric > 0;
      		} 
      		// /-- added handling for Integer
      		else {
      			throw new IllegalArgumentException("Unable to convert " + (value == null ? "null" : value.getClass().getName()) + " to boolean.");
      		}
      	}
      

        Attachments

          Activity

            People

            • Assignee:
              gmathews Gary Mathews
              Reporter:
              Campbell Campbell Anderson
            • Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code