{"record":{"id":"2b8f402f3e18d24b","repo":"Konloch/bytecode-viewer","slug":"value-is-out-of-range","errorCode":null,"errorMessage":"Value is out of range","messagePattern":"Value is out of range","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"warning","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/ValuesPanel.java","lineNumber":388,"sourceCode":"        if (!valuesUpdater.isUpdateInProgress()\n            && ((valuesCache[0] & 0x1) > 0 != binaryCheckBox7.isSelected()))\n        {\n            valuesCache[0] = (byte) (valuesCache[0] ^ 0x1);\n            modifyValues(1);\n        }\n    }//GEN-LAST:event_binaryCheckBox7ActionPerformed\n\n    private void byteTextFieldKeyReleased(java.awt.event.KeyEvent evt)\n    {//GEN-FIRST:event_byteTextFieldKeyReleased\n        if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable())\n        {\n            try\n            {\n                int intValue = Integer.parseInt(byteTextField.getText());\n                if (isSigned())\n                {\n                    if (intValue < Byte.MIN_VALUE || intValue > Byte.MAX_VALUE)\n                        throw new NumberFormatException(VALUE_OUT_OF_RANGE);\n                }\n                else\n                {\n                    if (intValue < 0 || intValue > UBYTE_MAX_VALUE)\n                        throw new NumberFormatException(VALUE_OUT_OF_RANGE);\n                }\n\n                valuesCache[0] = (byte) intValue;\n                modifyValues(1);\n                updateValues();\n            }\n            catch (NumberFormatException ex)\n            {\n                showException(ex);\n            }\n        }\n    }//GEN-LAST:event_byteTextFieldKeyReleased\n","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/ValuesPanel.java#L370-L406","documentation":"The hex viewer's byte ValuesPanel parses the byte text field on key release and throws NumberFormatException('Value is out of range') when the parsed integer cannot fit in a byte. In signed mode the valid range is -128..127; in unsigned mode 0..255. The Swing keyReleased handler catches this and shows a validation message instead of writing the value.","triggerScenarios":"Typing a value into the byte cell of the hex viewer's values panel that exceeds byte range: e.g. 200 while the panel is in signed mode, or -5 / 300 in unsigned mode, or any integer whose magnitude exceeds 255.","commonSituations":"Users editing hex bytes while the signed/unsigned toggle doesn't match their expectation; pasting multi-digit numbers; switching between signed and unsigned display modes and forgetting the range changed.","solutions":["Enter a value within the valid range: -128..127 in signed mode, 0..255 in unsigned mode","Toggle the signed/unsigned setting to match the intended interpretation","Use hex editing mode for direct bit patterns instead of decimal text entry","Clamp input in the UI (e.g. restrict text field length/format) before keyReleased fires"],"exampleFix":"// before\nint intValue = Integer.parseInt(byteTextField.getText()); // 200 -> out of range in signed mode\n// after\nint intValue = Integer.parseInt(byteTextField.getText());\nif (isSigned()) intValue = Math.max(Byte.MIN_VALUE, Math.min(Byte.MAX_VALUE, intValue));\nelse intValue = Math.max(0, Math.min(UBYTE_MAX_VALUE, intValue));","handlingStrategy":"validation","validationCode":"boolean isByteValue(String text, boolean signed) {\n    try {\n        int v = Integer.parseInt(text.trim());\n        return signed ? v >= Byte.MIN_VALUE && v <= Byte.MAX_VALUE\n                      : v >= 0 && v <= 255;\n    } catch (NumberFormatException e) { return false; }\n}","typeGuard":"boolean inByteRange(int v, boolean signed) {\n    return signed ? v >= -128 && v <= 127 : v >= 0 && v <= 255;\n}","tryCatchPattern":"try {\n    panel.setByteValue(textField.getText());\n} catch (NumberFormatException e) {\n    JOptionPane.showMessageDialog(panel, \"Enter a value between \" +\n        (panel.isSigned() ? \"-128 and 127\" : \"0 and 255\"));\n}","preventionTips":["Check signed/unsigned mode before typing values","Prefer hex input for raw bit patterns","Paste only values that fit the field width (8 bits)","Clamp input programmatically before committing"],"tags":["swing","hex-editor","user-input","range","byte"],"backgroundTag":"value-out-of-range","analyzedSha":"31430e0033fa220db566b5ef461256727ff6793b","analyzedAt":"2026-09-05T18:22:22.725Z","contentChangedAt":"2026-09-05T18:22:22.725Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}