Skip to content

Commit

Permalink
DebugOptionsTestCase: use try with resource
Browse files Browse the repository at this point in the history
"Mandatory close of resource 'out' has not been shown at this location"
  • Loading branch information
EcljpseB0T authored and jukzi committed Feb 13, 2024
1 parent 2472679 commit 1c9e696
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1147,27 +1147,26 @@ public void testTraceFile09() throws IOException {
public void testTraceSystemOut() throws IOException {
PrintStream old = System.out;
File traceFile = OSGiTestsActivator.getContext().getDataFile(getName() + ".trace"); //$NON-NLS-1$
OutputStream out = new FileOutputStream(traceFile);
final AtomicReference<Boolean> closed = new AtomicReference<>(Boolean.FALSE);
out = new FilterOutputStream(out) {
try (OutputStream out = new FilterOutputStream(new FileOutputStream(traceFile)) {

@Override
public void close() throws IOException {
super.close();
closed.set(Boolean.TRUE);
}

};
System.setOut(new PrintStream(out));
try {
TestDebugTrace debugTrace = this.createDebugTrace(new File("/does/not/exist/trace.out"));
debugOptions.setOption(getName() + "/debug", "true");
debugTrace.trace("/debug", "A message to System.out.");
debugTrace.trace("/debug", "Another message.");
assertFalse("Closed System.out.", closed.get().booleanValue());
} finally {
System.setOut(old);
out.close();
}) {
System.setOut(new PrintStream(out));
try {
TestDebugTrace debugTrace = this.createDebugTrace(new File("/does/not/exist/trace.out"));
debugOptions.setOption(getName() + "/debug", "true");
debugTrace.trace("/debug", "A message to System.out.");
debugTrace.trace("/debug", "Another message.");
assertFalse("Closed System.out.", closed.get().booleanValue());
} finally {
System.setOut(old);
}
}
TraceEntry[] traceOutput = null;
try {
Expand Down

0 comments on commit 1c9e696

Please sign in to comment.