alibaba/arthas · error · IllegalArgumentException

Line number must be greater than 0: {}

Error message

Line number must be greater than 0: {}

What it means

Thrown by parseLines() in the `line` command when the parsed line number is <= 0. Source line numbers are 1-based, so 0 (and any non-positive value that survived parseInt) is invalid. Note that negative literals like `-5` are intercepted earlier as 'range syntax' because they contain a dash.

Source

Thrown at core/src/main/java/com/taobao/arthas/core/command/monitor200/LineCommand.java:298

            }
            String[] parts = lineSpec.split(",");
            for (String part : parts) {
                String value = part.trim();
                if (value.length() == 0) {
                    continue;
                }
                if (value.indexOf('-') >= 0) {
                    throw new IllegalArgumentException("Line range syntax is not supported in the first version: "
                            + value);
                }
                final int lineNumber;
                try {
                    lineNumber = Integer.parseInt(value);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Invalid line number: " + value);
                }
                if (lineNumber <= 0) {
                    throw new IllegalArgumentException("Line number must be greater than 0: " + value);
                }
                result.add(lineNumber);
                if (result.size() > MAX_LINE_COUNT) {
                    throw new IllegalArgumentException("Too many line numbers, maximum is " + MAX_LINE_COUNT + ".");
                }
            }
        }
        if (result.isEmpty()) {
            throw new IllegalArgumentException("The --line option is required unless --list-lines is used.");
        }
        return result;
    }

    private void listLines(CommandProcess process) {
        try {
            Instrumentation instrumentation = process.session().getInstrumentation();
            Set<Class<?>> classes = GlobalOptions.isDisableSubClass
                    ? SearchUtils.searchClass(instrumentation, getClassNameMatcher())

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Use line numbers >= 1; source lines are 1-indexed.
  2. Run `line --list-lines --class <FQN>` to see the smallest valid line number for the class.
  3. If scripting, clamp or reject 0 before passing to --line.

Example fix

// before
line --class demo.MathGame --line 0
// after
line --class demo.MathGame --line 51
Defensive patterns

Strategy: validation

Validate before calling

static Integer parseLineOrThrow(String raw) {
    int n = Integer.parseInt(raw.trim());   // NumberFormatException handled separately
    if (n <= 0) throw new IllegalArgumentException("line must be > 0: " + raw);
    return n;
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Running `line --class demo.MathGame --line 0` or `--line 51,0`. The value parses to an integer successfully but fails the `lineNumber <= 0` guard.

Common situations: Assuming 0-based line indexing; passing a computed/variable line index that defaulted to 0; copy-paste error where a placeholder 0 was never replaced.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/0d99787b13646528. Report an issue: GitHub.