LtByXsl throws NoSuchElementException when defect element has no text content

Open Beginner friendly
#1,640 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@opusstudiohq-max is already working on this.

Since Nov 4, 2026.

  • #1642 by @opusstudiohq-max — open

Assessment

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

Research direction

Start in src/main/java/org/eolang/lints/LtByXsl.java, around lines 140–157, and compare how the code handles missing severity, line, and context with how it reads the defect text. Reproduce the case using the empty <defect> XML shown in the issue. Done when empty text no longer causes an unhandled NoSuchElementException and the behavior matches one of the issue's expected outcomes.

Written by the indexing model from the issue text.

Description

In src/main/java/org/eolang/lints/LtByXsl.java:140-157:

final Optional<String> sever = xml.attribute("severity").text();
if (sever.isEmpty()) {
    throw new IllegalStateException(
        String.format("No severity reported by %s", this.rule.value())
    );
}
defects.add(
    new DfContext(
        new Defect.Default(
            this.rule.value(),
            Severity.parsed(sever.get()),
            this.lineno(xml),
            xml.text().get(),
            LtByXsl.experimental(xml)
        ),
        xml.attribute("context").text().orElse("")
    )
);

While severity is checked with if (sever.isEmpty()) (raising a clear IllegalStateException), line is checked in this.lineno(xml), and context defaults safely via .orElse(""), the defect message on line 152 calls xml.text().get() directly without checking isEmpty().

When an XSL transformation produces a <defect> element with empty or whitespace-only text content (e.g. <defect line="10" severity="error"/> or <defect line="10" severity="warning"></defect>), xml.text() returns Optional.empty().

Calling xml.text().get() throws an unhandled java.util.NoSuchElementException: No value present, crashing the entire linting pipeline.

Steps to reproduce

In Java:

final XML defect = new XMLDocument("<defect line=\"10\" severity=\"error\"/>");
final Xnav xml = new Xnav(defect.inner());
xml.text().get(); // throws NoSuchElementException: No value present
Actual behavior

Throws:

java.util.NoSuchElementException: No value present
    at java.base/java.util.Optional.get(Optional.java:143)
    at org.eolang.lints.LtByXsl.defects(LtByXsl.java:152)
Expected behavior

LtByXsl should either safely default to an empty string (e.g. xml.text().orElse("")), or validate xml.text().isEmpty() and throw a descriptive IllegalStateException(String.format("No message reported by %s", this.rule.value())), consistent with how missing severity and line attributes are handled.

Environment
  • Repository: objectionary/lints
  • Master commit: 0c674f85
  • Java: 21
Dominant language
Java
Stars
14
Forks
41
Avg merge
1d 15h
Merged PRs (30d)
40

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from objectionary/lints

All issues in objectionary/lints

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.