Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.32k stars 10.69k forks source link

ToastUtils异常,FormatFlagsConversionMismatchException #1186

Closed aitsuki closed 4 years ago

aitsuki commented 4 years ago

ToastUtils.showShort,format异常

原因是服务器在极端的情况下返回的错误信息包含占位符,而ToastUtils的第一个参数为format

The code of bug

对应message为

"(pymysql.err.ProgrammingError) (1146, \"Table 'yc-test.popular_card' doesn't exist\")\n[SQL: SELECT popular_card.id AS popular_card_id, popular_card.card_id AS popular_card_card_id, popular_card.weight AS popular_card_weight, popular_card.is_del AS popular_card_is_del, popular_card.created_at AS popular_card_created_at, popular_card.updated_at AS popular_card_updated_at \nFROM popular_card \nWHERE popular_card.card_id = %(card_id_1)s AND popular_card.is_del = %(is_del_1)s \n LIMIT %(param_1)s]\n[parameters: {'card_id_1': 82, 'is_del_1': 0, 'param_1': 1}]\n(Background on this error at: http://sqlalche.me/e/f405)"
ToastUtils.showShort(it.message)

The stack of crash

W:  java.util.FormatFlagsConversionMismatchException: Conversion = c, Flags = (
W:     at java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4398)
W:     at java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:3091)
W:     at java.util.Formatter$FormatSpecifier.checkCharacter(Formatter.java:3068)
W:     at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2818)
W:     at java.util.Formatter$FormatSpecifierParser.<init>(Formatter.java:2624)
W:     at java.util.Formatter.parse(Formatter.java:2557)
W:     at java.util.Formatter.format(Formatter.java:2504)
W:     at java.util.Formatter.format(Formatter.java:2458)
W:     at java.lang.String.format(String.java:2842)
W:     at com.blankj.utilcode.util.ToastUtils.show(ToastUtils.java:251)
W:     at com.blankj.utilcode.util.ToastUtils.showShort(ToastUtils.java:141)
Blankj commented 4 years ago

我觉得你是用 kotlin 调用的,导致 arg 传入了 空 数组, java 应该是没问题的,是这个问题的话我下版本修复下

aitsuki commented 4 years ago

@Blankj 对的,是kotlin。明明有单参数的方法,kotlin默认情况下就会调用可变参数的那个方法,这互操作我是没搞懂=。=

Blankj commented 4 years ago

https://github.com/Blankj/AndroidUtilCode/releases/tag/1.27.0 1.27.0 版本已发布