Skip to content

Commit

Permalink
Fix NPE in BasicRestProjectGenerator when a resource is missing
Browse files Browse the repository at this point in the history
Throw a dedicated IOException instead.
Closes #3331
  • Loading branch information
ia3andy committed Aug 12, 2019
1 parent 0d98c45 commit 508de04
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import static java.lang.String.format;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -111,8 +108,12 @@ private void generate(final String templateName, final Map<String, Object> conte
throws IOException {
if (!writer.exists(outputFilePath)) {
String path = templateName.startsWith("/") ? templateName : "/" + templateName;
InputStream resourceStream = getClass().getResourceAsStream(path);
if (resourceStream == null) {
throw new IOException("Template resource is missing: " + path);
}
try (final BufferedReader stream = new BufferedReader(
new InputStreamReader(getClass().getResourceAsStream(path), StandardCharsets.UTF_8))) {
new InputStreamReader(resourceStream, StandardCharsets.UTF_8))) {
String template = stream.lines().collect(Collectors.joining("\n"));
for (Entry<String, Object> e : context.entrySet()) {
if (e.getValue() != null) { // Exclude null values (classname and path can be null)
Expand Down

0 comments on commit 508de04

Please sign in to comment.