Konloch/bytecode-viewer · warning · NumberFormatException

Value is out of range

Error message

Value is out of range

What it means

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.

Source

Thrown at src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/ValuesPanel.java:388

        if (!valuesUpdater.isUpdateInProgress()
            && ((valuesCache[0] & 0x1) > 0 != binaryCheckBox7.isSelected()))
        {
            valuesCache[0] = (byte) (valuesCache[0] ^ 0x1);
            modifyValues(1);
        }
    }//GEN-LAST:event_binaryCheckBox7ActionPerformed

    private void byteTextFieldKeyReleased(java.awt.event.KeyEvent evt)
    {//GEN-FIRST:event_byteTextFieldKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable())
        {
            try
            {
                int intValue = Integer.parseInt(byteTextField.getText());
                if (isSigned())
                {
                    if (intValue < Byte.MIN_VALUE || intValue > Byte.MAX_VALUE)
                        throw new NumberFormatException(VALUE_OUT_OF_RANGE);
                }
                else
                {
                    if (intValue < 0 || intValue > UBYTE_MAX_VALUE)
                        throw new NumberFormatException(VALUE_OUT_OF_RANGE);
                }

                valuesCache[0] = (byte) intValue;
                modifyValues(1);
                updateValues();
            }
            catch (NumberFormatException ex)
            {
                showException(ex);
            }
        }
    }//GEN-LAST:event_byteTextFieldKeyReleased

View on GitHub (pinned to 31430e0033)

Solutions

  1. Enter a value within the valid range: -128..127 in signed mode, 0..255 in unsigned mode
  2. Toggle the signed/unsigned setting to match the intended interpretation
  3. Use hex editing mode for direct bit patterns instead of decimal text entry
  4. Clamp input in the UI (e.g. restrict text field length/format) before keyReleased fires

Example fix

// before
int intValue = Integer.parseInt(byteTextField.getText()); // 200 -> out of range in signed mode
// after
int intValue = Integer.parseInt(byteTextField.getText());
if (isSigned()) intValue = Math.max(Byte.MIN_VALUE, Math.min(Byte.MAX_VALUE, intValue));
else intValue = Math.max(0, Math.min(UBYTE_MAX_VALUE, intValue));
Defensive patterns

Strategy: validation

Validate before calling

boolean isByteValue(String text, boolean signed) {
    try {
        int v = Integer.parseInt(text.trim());
        return signed ? v >= Byte.MIN_VALUE && v <= Byte.MAX_VALUE
                      : v >= 0 && v <= 255;
    } catch (NumberFormatException e) { return false; }
}

Type guard

boolean inByteRange(int v, boolean signed) {
    return signed ? v >= -128 && v <= 127 : v >= 0 && v <= 255;
}

Try / catch

try {
    panel.setByteValue(textField.getText());
} catch (NumberFormatException e) {
    JOptionPane.showMessageDialog(panel, "Enter a value between " +
        (panel.isSigned() ? "-128 and 127" : "0 and 255"));
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.


AI-assisted analysis of Konloch/bytecode-viewer@31430e0033 (2026-09-05). Data as JSON: /api/errors/2b8f402f3e18d24b. Report an issue: GitHub.