objectionary / objectionary/lints

`LineOf` incorrectly throws `NumberFormatException` for non-numeric `@line` in XMIR

Open Beginner friendly
#1,387 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug good-title
Dominant language
Java
Stars
14
Forks
39
Avg merge
22h 54m
Merged PRs (30d)
90

Description

Problem

LineOf throws an unhandled NumberFormatException when a hand-written/broken XMIR carries a non-numeric @line, taking down the whole Source.defects() run.

Root cause

src/main/java/org/eolang/lints/LineOf.java:39-41:

public static String value(final XML xml) {
    final String line;
    final Optional<String> attr = xml.xpath("@line").stream().findFirst();
    if (attr.isPresent()) {
        line = String.valueOf(Integer.parseInt(attr.get()));
    } else {
        line = "0";
    }
    return line;
}

The javadoc promises 0 only for an absent attribute. If @line is present but not an integer (malformed manual XMIR), Integer.parseInt throws NumberFormatException (unchecked), which escapes past the sole catch (IOException) in Source.defects() (src/main/java/org/eolang/lints/Source.java:104-118) and aborts the entire analysis.

LineOf is used by five hand-written lints: LtAsciiOnly.java:42, LtIncorrectUnlint.java:48, LtReservedName.java:54, LtSyntaxVersion.java:70, LtTestNotVerb.java:77.

Minimal example

new Source(new XMLDocument("<object><o name=\"x\" line=\"abc\"/></object>")).defects();
// throws NumberFormatException: For input string: "abc"

Expected behavior

A non-numeric @line should fall back to 0 (consistent with the rest of the codebase), or be reported as a controlled IllegalStateException — not an unhandled NumberFormatException from the public API.

Related

  • LtByXsl.java:179-205 — the XSL path has a stricter lineno(); the Java path should be consistent.
  • src/test/java/org/eolang/lints/LineOf.java has no dedicated test at all.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/java/org/eolang/lints/LineOf.java:39-41 and review how Source.defects() handles failures in src/main/java/org/eolang/lints/Source.java:104-118. Inspect the five lints that use LineOf, then add focused coverage under src/test/java/org/eolang/lints/LineOf.java for a non-numeric @line. Done means malformed XMIR no longer causes an unhandled NumberFormatException and the chosen controlled behavior is tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.