Skip to content

Commit ec5a98b

Browse files
authored
Better exception handling (#1566)
1 parent f38279d commit ec5a98b

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/main/java/org/apache/maven/plugins/dependency/fromDependencies/RenderDependenciesMojo.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.File;
2424
import java.io.IOException;
2525
import java.io.StringWriter;
26+
import java.io.UncheckedIOException;
2627
import java.io.Writer;
2728
import java.nio.charset.Charset;
2829
import java.nio.charset.StandardCharsets;
@@ -154,9 +155,10 @@ protected void doExecute() throws MojoExecutionException {
154155
}
155156

156157
/**
157-
* Do render the template.
158-
* @param artifacts input.
159-
* @return the template rendered.
158+
* Render the template.
159+
*
160+
* @param artifacts input
161+
* @return the template rendered
160162
*/
161163
private String render(final List<Artifact> artifacts) {
162164
final Path templatePath = getTemplatePath();
@@ -178,20 +180,18 @@ private String render(final List<Artifact> artifacts) {
178180
context.put("sorter", new CollectionTool());
179181

180182
// Merge template + context
181-
final StringWriter writer = new StringWriter();
182-
try (StringWriter ignored = writer) {
183+
try (StringWriter writer = new StringWriter()) {
183184
if (fromFile) {
184185
final Template template =
185186
ve.getTemplate(templatePath.getFileName().toString());
186187
template.merge(context, writer);
187188
} else {
188189
ve.evaluate(context, writer, "tpl-" + Math.abs(hashCode()), template);
189190
}
191+
return writer.toString();
190192
} catch (final IOException e) {
191-
// no-op, not possible
193+
throw new UncheckedIOException("not possible", e);
192194
}
193-
194-
return writer.toString();
195195
}
196196

197197
private Path getTemplatePath() {

0 commit comments

Comments
 (0)