LtByXsl throws NoSuchElementException when defect element has no text content
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from objectionary/lints
-
LtUnlintNonExistingDefect throws NoSuchElementException when +unlint meta has empty or missing tailPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
objectionary/lints#1639 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
objectionary/lints#1614 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/lints#1613 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/lints#1612 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
objectionary/lints#1611 ·
Maintainers usually reply within 1 day
All issues in objectionary/lints
Similar issues
-
maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
apache/maven-resources-plugin#569 ·
Maintainers usually reply within 1 day
-
Data Sources visit drilldown returns an empty visitDurationByType for Achilles 1.7+ results (query still reads analysis 211)Possibly taken @DG47 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
BUG
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
camel-tooling/camel-language-server#1482 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
micronaut-projects/micronaut-redis#844 ·
Maintainers usually reply within 4 days