New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberFormatException #8

Closed
tianxiaogu opened this Issue Oct 30, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@tianxiaogu

tianxiaogu commented Oct 30, 2017

Reproduce:

Input a very large number that exceeds the limit of int32.

Patch:

You probably need to write such a safe helper.

int safeParseInt(String input) {
    return safeParseInt(input, 0);
}
int safeParseInt(String input, int defaultValue) {
    try {
        return Integer.parseInt(input);
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}
// CRASH: com.wmstein.transektcount (pid 20195) (elapsed nanos: 15388602262937)
// Short Msg: java.lang.NumberFormatException
// Long Msg: java.lang.NumberFormatException: Invalid int: "03076138850055"
// Build Label: google/hammerhead/hammerhead:6.0.1/M4B30Z/3437181:user/release-keys
// Build Changelist: 3437181
// Build Time: 1478203422000
// java.lang.NumberFormatException: Invalid int: "03076138850055"
// 	at java.lang.Integer.invalidInt(Integer.java:138)
// 	at java.lang.Integer.parse(Integer.java:413)
// 	at java.lang.Integer.parseInt(Integer.java:367)
// 	at java.lang.Integer.parseInt(Integer.java:334)
// 	at com.wmstein.transektcount.widgets.EditMetaWidget.getWidgetItem1(EditMetaWidget.java:129)
// 	at com.wmstein.transektcount.EditMetaActivity.saveData(EditMetaActivity.java:256)
// 	at com.wmstein.transektcount.EditMetaActivity.onOptionsItemSelected(EditMetaActivity.java:299)
// 	at android.app.Activity.onMenuItemSelected(Activity.java:2914)
// 	at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
// 	at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
// 	at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:113)
// 	at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:679)
// 	at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
// 	at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
// 	at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969)
// 	at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:959)
// 	at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:623)
// 	at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:154)
// 	at android.view.View.performClick(View.java:5204)
// 	at android.view.View$PerformClick.run(View.java:21153)
// 	at android.os.Handler.handleCallback(Handler.java:739)
// 	at android.os.Handler.dispatchMessage(Handler.java:95)
// 	at android.os.Looper.loop(Looper.java:148)
// 	at android.app.ActivityThread.main(ActivityThread.java:5417)
// 	at java.lang.reflect.Method.invoke(Native Method)
// 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
// 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
// 

@wistein

This comment has been minimized.

Owner

wistein commented Oct 31, 2017

@tianxiaogu: Thanks a lot for testing and the log.

Fixed in version 2.1.1.

@wistein wistein closed this Oct 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment