From b7c15cd77fbc7a02710306eed0b2ad3bedbe2937 Mon Sep 17 00:00:00 2001 From: eal Date: Thu, 3 Mar 2022 08:40:11 -0800 Subject: [PATCH 1/2] Check for null reactor to avoid NPE --- .../org/lflang/graph/InstantiationGraph.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/org.lflang/src/org/lflang/graph/InstantiationGraph.java b/org.lflang/src/org/lflang/graph/InstantiationGraph.java index ed50fb4817..0cfc6ce191 100644 --- a/org.lflang/src/org/lflang/graph/InstantiationGraph.java +++ b/org.lflang/src/org/lflang/graph/InstantiationGraph.java @@ -156,17 +156,19 @@ public InstantiationGraph(final Model model, final boolean detectCycles) { private void buildGraph(final Instantiation instantiation, final Set visited) { final ReactorDecl decl = instantiation.getReactorClass(); final Reactor reactor = ASTUtils.toDefinition(decl); - Reactor container = ASTUtils.getEnclosingReactor(instantiation); - if (visited.add(instantiation)) { - this.reactorToInstantiation.put(reactor, instantiation); - this.reactorToDecl.put(reactor, decl); - if (container != null) { - this.addEdge(container, reactor); - } else { - this.addNode(reactor); - } - for (final Instantiation inst : reactor.getInstantiations()) { - this.buildGraph(inst, visited); + if (reactor != null) { + Reactor container = ASTUtils.getEnclosingReactor(instantiation); + if (visited.add(instantiation)) { + this.reactorToInstantiation.put(reactor, instantiation); + this.reactorToDecl.put(reactor, decl); + if (container != null) { + this.addEdge(container, reactor); + } else { + this.addNode(reactor); + } + for (final Instantiation inst : reactor.getInstantiations()) { + this.buildGraph(inst, visited); + } } } } From b73dc51c8fb96875b33de8cfc43f216d1e47ea0e Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 4 Mar 2022 14:40:22 +0100 Subject: [PATCH 2/2] correctly fall back on the main resource when reporting errors in Epoch --- .../org/lflang/generator/EclipseErrorReporter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/EclipseErrorReporter.java b/org.lflang/src/org/lflang/generator/EclipseErrorReporter.java index a2dd652e31..95f86e0688 100644 --- a/org.lflang/src/org/lflang/generator/EclipseErrorReporter.java +++ b/org.lflang/src/org/lflang/generator/EclipseErrorReporter.java @@ -109,12 +109,19 @@ private String report(String message, Severity severity, Integer line, Path file if (line == null || file == null) System.err.println(header + ": " + message); else - System.err.println(header + ": " + file.toString() + " line " + line.toString() + System.err.println(header + ": " + file + " line " + line + "\n" + message); + // Determine the iResource to report on + IResource iResource = file != null ? FileUtil.getIResource(file) : null; + // if we couldn't find an iResource (for whatever reason), then use the + // iResource of the main file + if (iResource == null) { + iResource = fileConfig.iResource; + } + // Create a marker in the IDE for the error. - // See: https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_markers.htm - IResource iResource = file != null ? FileUtil.getIResource(file) : fileConfig.iResource; + // See: https://help.eclipse.org/2020-03/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_markers.html try { IMarker marker = iResource.createMarker(IMarker.PROBLEM);