From 3e2824af7e6e28cd6dc3c132481eb7f60bbc6749 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Wed, 15 Mar 2023 17:41:37 +0100 Subject: [PATCH] Fix NPE in lfc error reporting The lfc tool currently fails with an NPE if an issue is reported without an associated resource (see https://github.com/lf-lang/lingua-franca/issues/1650). This PR fixes this NPE, but not the source of the error in the program mentioned in https://github.com/lf-lang/lingua-franca/issues/1650. --- org.lflang/src/org/lflang/cli/CliBase.java | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/org.lflang/src/org/lflang/cli/CliBase.java b/org.lflang/src/org/lflang/cli/CliBase.java index 77581a6410..d4dfe9c782 100644 --- a/org.lflang/src/org/lflang/cli/CliBase.java +++ b/org.lflang/src/org/lflang/cli/CliBase.java @@ -207,26 +207,29 @@ public void validateResource(Resource resource) { assert resource != null; List 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)); } }