{"record":{"id":"cd00ac94da95fa35","repo":"beemdevelopment/Aegis","slug":"counter-is-not-an-integer","errorCode":null,"errorMessage":"Counter is not an integer.","messagePattern":"Counter is not an integer\\.","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java","lineNumber":774,"sourceCode":"\n            throw new ParseException(exceptionMessage);\n        }\n\n        OtpInfo info;\n        try {\n            switch (type.toLowerCase(Locale.ROOT)) {\n                case TotpInfo.ID:\n                    info = new TotpInfo(secret, algo, digits, parsePeriod());\n                    break;\n                case SteamInfo.ID:\n                    info = new SteamInfo(secret, algo, digits, parsePeriod());\n                    break;\n                case HotpInfo.ID:\n                    long counter;\n                    try {\n                        counter = Long.parseLong(_textPeriodCounter.getText().toString());\n                    } catch (NumberFormatException e) {\n                        throw new ParseException(\"Counter is not an integer.\");\n                    }\n                    info = new HotpInfo(secret, algo, digits, counter);\n                    break;\n                case YandexInfo.ID:\n                    info = new YandexInfo(secret, _textPin.getText().toString());\n                    break;\n                case MotpInfo.ID:\n                    info = new MotpInfo(secret, _textPin.getText().toString());\n                    break;\n                default:\n                    throw new RuntimeException(String.format(\"Unsupported OTP type: %s\", type));\n            }\n\n            info.setDigits(digits);\n            info.setAlgorithm(algo);\n        } catch (OtpInfoException e) {\n            throw new ParseException(\"The entered info is incorrect: \" + e.getMessage());\n        }","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/beemdevelopment/Aegis/blob/d6f4e5925a97e4e91593f1542085eae03432a759/app/src/main/java/com/beemdevelopment/aegis/ui/EditEntryActivity.java#L756-L792","documentation":"For HOTP entries, EditEntryActivity.parseEntry() reads the counter from the period/counter field with Long.parseLong and wraps NumberFormatException in a ParseException. The HOTP counter must be a 64-bit integer, so empty or non-numeric input is rejected before constructing HotpInfo.","triggerScenarios":"Saving an HOTP entry while the counter field is empty, contains letters/decimals, or exceeds Long range; Long.parseLong throws NumberFormatException.","commonSituations":"Switching an entry from TOTP to HOTP without setting a counter, or pasting a counter value with formatting such as '1,000' or '0x1F'.","solutions":["Enter a plain integer counter (e.g. 0) in the period/counter field before saving","Retype the value to remove whitespace or separators like commas","Use a value within signed 64-bit range (-9223372036854775808 to 9223372036854775807)"],"exampleFix":"// before\ncounterField.setText(\"1,000\");\n// after\ncounterField.setText(\"1000\");","handlingStrategy":"validation","validationCode":"String counter = _textPeriodCounter.getText().toString().trim();\nif (!counter.matches(\"-?\\\\d+\")) {\n    _textPeriodCounterLayout.setError(\"HOTP counter must be an integer\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    saveEntry();\n} catch (ParseException e) {\n    if (\"Counter is not an integer.\".equals(e.getMessage())) {\n        _textPeriodCounterLayout.setError(\"Enter an integer counter\");\n    }\n}","preventionTips":["Default the HOTP counter to 0 when switching a TOTP entry to HOTP","Use numeric input type and strip separators on paste","Range-check the value fits in a signed 64-bit long"],"tags":["android","validation","otp","hotp","input-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"d6f4e5925a97e4e91593f1542085eae03432a759","analyzedAt":"2026-09-08T00:46:31.111Z","contentChangedAt":"2026-09-08T00:46:31.111Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}