Skip to content

Commit

Permalink
Fix NPE in lfc error reporting
Browse files Browse the repository at this point in the history
The lfc tool currently fails with an NPE if an issue is reported without an
associated resource (see #1650).
This PR fixes this NPE, but not the source of the error in the program mentioned
in #1650.
  • Loading branch information
cmnrd committed Mar 15, 2023
1 parent 95b5b54 commit 3e2824a
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions org.lflang/src/org/lflang/cli/CliBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,29 @@ public void validateResource(Resource resource) {
assert resource != null;

List<Issue> issues = this.validator.validate(
resource, CheckMode.ALL, CancelIndicator.NullImpl);
resource, CheckMode.ALL, CancelIndicator.NullImpl);

for (Issue issue : issues) {
// Issues may also relate to imported resources.
URI uri = issue.getUriToProblem();
try {
issueCollector.accept(
new LfIssue(
issue.getMessage(),
issue.getSeverity(),
issue.getLineNumber(),
issue.getColumn(),
issue.getLineNumberEnd(),
issue.getColumnEnd(),
issue.getLength(),
FileUtil.toPath(uri)));
} catch (IOException e) {
reporter.printError(
"Unable to convert '" + uri + "' to path." + e);
URI uri = issue.getUriToProblem();
Path path = null;
if (uri != null) {
try {
path = FileUtil.toPath(uri);
} catch (IOException e) {
reporter.printError("Unable to convert '" + uri + "' to path." + e);
}
}
issueCollector.accept(
new LfIssue(
issue.getMessage(),
issue.getSeverity(),
issue.getLineNumber(),
issue.getColumn(),
issue.getLineNumberEnd(),
issue.getColumnEnd(),
issue.getLength(),
path));
}
}

Expand Down

0 comments on commit 3e2824a

Please sign in to comment.