Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for null reactor to avoid NPE #998

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions org.lflang/src/org/lflang/generator/EclipseErrorReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 13 additions & 11 deletions org.lflang/src/org/lflang/graph/InstantiationGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,19 @@ public InstantiationGraph(final Model model, final boolean detectCycles) {
private void buildGraph(final Instantiation instantiation, final Set<Instantiation> 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);
}
}
}
}
Expand Down