google / google/guice

GraphvizGrapher fails with non-descriptive NullPointerException when writer is not set

Open
#963 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

If `GraphvizGrapher#graph()` is invoked befroe the output `PrintWriter` is set, then a not very useful `NullPointerException` is thrown:

```
java.lang.NullPointerException
at com.google.inject.grapher.graphviz.GraphvizGrapher.start(GraphvizGrapher.java:100)
at com.google.inject.grapher.graphviz.GraphvizGrapher.postProcess(GraphvizGrapher.java:78)
at com.google.inject.grapher.AbstractInjectorGrapher.graph(AbstractInjectorGrapher.java:112)
at com.google.inject.grapher.AbstractInjectorGrapher.graph(AbstractInjectorGrapher.java:102)
```

Adding a `Preconditions.checkNotNull` with a more descriptive message at the beginning of [`GraphvizGrapher#postProcess()`](https://github.com/google/guice/blob/master/extensions/grapher/src/com/google/inject/grapher/graphviz/GraphvizGrapher.java#L77), or something along those lines, would be helpful.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.