Skip to content

Commit

Permalink
CodeQuality: Fix issue in SVG demo code that may cause some resource …
Browse files Browse the repository at this point in the history
…not to be released.

Thanks to the HP Fortify Open Review team for reporting
  • Loading branch information
abego committed Nov 5, 2015
1 parent 930eb87 commit 4476231
Showing 1 changed file with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,27 @@
*
* <pre>
* String s = doc(svg(
* 160,
* 200,
* rect(0, 0, 160, 200, &quot;fill:red;&quot;)
* + svg(10, 10, 100, 100,
* rect(0, 0, 100, 100, &quot;fill:orange; stroke:rgb(0,0,0);&quot;))
* + line(20, 20, 100, 100, &quot;stroke:black; stroke-width:2px;&quot;)
* + line(20, 100, 100, 20, &quot;stroke:black; stroke-width:2px;&quot;)
* + text(10,
* 140,
* &quot;font-family:verdana; font-size:20px; font-weight:bold;&quot;,
* &quot;Hello world&quot;)));
* 160,
* 200,
* rect(0, 0, 160, 200, &quot;fill:red;&quot;)
* + svg(10, 10, 100, 100,
* rect(0, 0, 100, 100, &quot;fill:orange; stroke:rgb(0,0,0);&quot;))
* + line(20, 20, 100, 100, &quot;stroke:black; stroke-width:2px;&quot;)
* + line(20, 100, 100, 20, &quot;stroke:black; stroke-width:2px;&quot;)
* + text(10, 140,
* &quot;font-family:verdana; font-size:20px; font-weight:bold;&quot;,
* &quot;Hello world&quot;)));
*
* File file = new File(&quot;demo.svg&quot;);
* FileWriter w = new FileWriter(file);
* w.write(s);
* w.close();
* FileWriter w = null;
* try {
* w = new FileWriter(file);
* w.write(s);
* } finally {
* if (w != null) {
* w.close();
* }
* }
* </pre>
*
* (see {@link #main(String[])})
Expand Down Expand Up @@ -228,10 +233,15 @@ public static void main(String[] args) throws IOException {
"Hello world")));

File file = new File("demo.svg");
FileWriter w = new FileWriter(file);
w.write(s);
w.close();

FileWriter w = null;
try {
w = new FileWriter(file);
w.write(s);
} finally {
if (w != null) {
w.close();
}
}
System.out.println(String.format("File written: %s",
file.getAbsolutePath()));

Expand Down

0 comments on commit 4476231

Please sign in to comment.