Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7829] Android: IllegalFormatConversionException in String.format for integers with positional arguments

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-03-20T04:32:49.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.0.2
ComponentsAndroid
Labelsn/a
ReporterPaul Mietz Egli
Assigneejithinpv
Created2012-01-19T09:18:45.000+0000
Updated2017-03-21T21:26:56.000+0000

Description

Problem Description

Integer format strings that contain positional arguments result in an IllegalFormatConversionException when passed to String.format(). If the positional part of the format is removed, the call works fine.

Expected Results

Strings with positional should work fine.

Actual results

The strings with positional information are throwing an exception.

Test case

var win = Ti.UI.createWindow();

Ti.API.info(String.format('non-positional: %d', 1));
Ti.API.info(String.format('positional: %1$d', 1));

win.open();

Crashlog

/TiAPI   (  275): non-positional: 1
E/TitaniumModule(  275): (KrollRuntimeThread) [363,3214] Error in string format
E/TitaniumModule(  275): java.util.IllegalFormatConversionException: d is incompatible with java.lang.Double
E/TitaniumModule(  275): 	at java.util.Formatter$Transformer.badArgumentType(Formatter.java:1452)
E/TitaniumModule(  275): 	at java.util.Formatter$Transformer.transformFromInteger(Formatter.java:1683)
E/TitaniumModule(  275): 	at java.util.Formatter$Transformer.transform(Formatter.java:1410)
E/TitaniumModule(  275): 	at java.util.Formatter.doFormat(Formatter.java:1082)
E/TitaniumModule(  275): 	at java.util.Formatter.format(Formatter.java:994)
E/TitaniumModule(  275): 	at java.lang.String.format(String.java:2254)
E/TitaniumModule(  275): 	at java.lang.String.format(String.java:2219)
E/TitaniumModule(  275): 	at ti.modules.titanium.TitaniumModule.stringFormat(TitaniumModule.java:294)
E/TitaniumModule(  275): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
E/TitaniumModule(  275): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:116)
E/TitaniumModule(  275): 	at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:207)
E/TitaniumModule(  275): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:136)
E/TitaniumModule(  275): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/TitaniumModule(  275): 	at android.os.Looper.loop(Looper.java:123)
E/TitaniumModule(  275): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:102)
I/TiAPI   (  275): null

Comments

  1. Paul Mietz Egli 2012-01-19

    Workaround is to use ".0f" as the format instead of "d":
       Ti.API.info(String.format('positional: %1$.0f', 1));
       
  2. Wilson Luu 2012-03-22

    I get the same exception when launching KS from current master branch on: SDK build: 2.0.0.v20120321231752 Runtime: V8 Titanium Studio, build: 2.0.0.201203211914 OS: Linux 11.10 Device: Droid 3 (2.3.4)
  3. jithinpv 2013-03-20

    log: [INFO][TiAPI (28480)] non-positional: 1 [INFO][TiAPI (28480)] positional: 1 Issue does not reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 (03/11/13 15:43 0c88429) Titanium SDK version: 3.0.2 (02/07/13 16:46 a4def81) Device: Samsung galaxy s duos Android version: 4.0.4 jithinpv
  4. Lee Morris 2017-03-21

    Closing ticket as the issue cannot be reproduced.

JSON Source