{"record":{"id":"648bfc63d6e10211","repo":"theonedev/onedev","slug":"invalid-integer-value","errorCode":null,"errorMessage":"Invalid integer value","messagePattern":"Invalid integer value","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/integerinput/IntegerInput.java","lineNumber":47,"sourceCode":"\t\t\t} else {\n\t\t\t\tbuffer.append(\"    @Range(min=\" + minValue.toString() + \"L)\\n\");\n\t\t\t}\n\t\t} else if (maxValue != null) {\n\t\t\tbuffer.append(\"    @Range(max=\" + maxValue.toString() + \"L)\\n\");\n\t\t}\n\t\tinputSpec.appendMethods(buffer, index, \"Integer\", null, defaultValueProvider);\n\t\t\n\t\treturn buffer.toString();\n\t}\n\n\tpublic static Object convertToObject(List<String> strings) {\n\t\tif (strings.size() == 0) { \n\t\t\treturn null;\n\t\t} else if (strings.size() == 1) {\n\t\t\ttry {\n\t\t\t\treturn Integer.valueOf(strings.iterator().next());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new ValidationException(\"Invalid integer value\");\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new ValidationException(\"Not eligible for multi-value\");\n\t\t}\n\t}\n\n\tpublic static List<String> convertToStrings(Object value) {\n\t\tif (value instanceof Integer)\n\t\t\treturn Lists.newArrayList(String.valueOf(value));\n\t\telse\n\t\t\treturn new ArrayList<>();\n\t}\n\n}\n","sourceCodeStart":29,"sourceCodeEnd":62,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/integerinput/IntegerInput.java#L29-L62","documentation":"IntegerInput.convertToObject parses a single submitted string into an Integer via Integer.valueOf. On NumberFormatException it throws ValidationException \"Invalid integer value\" because the value is not a valid 32-bit integer literal (non-numeric, decimal point, empty, or out of Integer range).","triggerScenarios":"Calling IntegerInput.convertToObject(List<String>) with a single element like \"abc\", \"3.14\", \"\", \"99999999999\" (out of int range).","commonSituations":"User enters a decimal number in an integer field; a script substitutes an empty or text variable; a long/float value from another system is submitted to an integer input.","solutions":["Correct the value to a whole number within 32-bit range, e.g. \"42\", \"-7\".","Validate with a regex like -?\\d+ before submission and reject decimals explicitly.","If the source value is a float, round/truncate it deliberately (e.g. (int) Float.parseFloat(v)) before passing it.","Check for empty variables in scripts that interpolate into the input value."],"exampleFix":"// before\nString v = env.get(\"REPLICAS\"); // \"2.5\"\nObject i = IntegerInput.convertToObject(Lists.newArrayList(v)); // throws\n\n// after\nString v = env.get(\"REPLICAS\");\nif (!v.matches(\"-?\\\\d+\"))\n    throw new ValidationException(\"Replicas must be a whole number\");\nObject i = IntegerInput.convertToObject(Lists.newArrayList(v));","handlingStrategy":"validation","validationCode":"if (value != null && !value.matches(\"-?\\\\d+\"))\n    throw new ValidationException(\"Value must be a whole number\");","typeGuard":null,"tryCatchPattern":"try {\n    i = IntegerInput.convertToObject(Lists.newArrayList(value));\n} catch (ValidationException e) {\n    // invalid integer: correct value or apply default\n}","preventionTips":["Reject decimal points and thousands separators before submission.","Check int range (Integer.MIN_VALUE..Integer.MAX_VALUE) for large numbers.","Guard interpolated variables against being empty or textual."],"tags":["validation","input-spec","integer","number-format"],"backgroundTag":"invalid-argument-value","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}