Use try-with-resources to ensure inputStream gets closed.
Summary: Fix a warning about a potentially unclosed resource.
Test Plan: No warnings reported by Eclipse.
diff --git a/test/com/facebook/buck/cli/DaemonIntegrationTest.java b/test/com/facebook/buck/cli/DaemonIntegrationTest.java
index 32f9020..03d37e3 100644
--- a/test/com/facebook/buck/cli/DaemonIntegrationTest.java
+++ b/test/com/facebook/buck/cli/DaemonIntegrationTest.java
@@ -156,39 +156,40 @@
Thread.currentThread().setName("Test");
CapturingPrintStream serverLog = new CapturingPrintStream();
NGContext context = new NGContext();
- TestNGInputStream inputStream = new TestNGInputStream(
- new DataInputStream(createHeartbeatStream(100)),
- new DataOutputStream(new ByteArrayOutputStream(0)),
- serverLog);
- context.setArgs(new String[] {"targets"});
- context.in = inputStream;
- context.out = new CapturingPrintStream();
- context.err = new CapturingPrintStream();
+ try (TestNGInputStream inputStream = new TestNGInputStream(
+ new DataInputStream(createHeartbeatStream(100)),
+ new DataOutputStream(new ByteArrayOutputStream(0)),
+ serverLog)) {
+ context.setArgs(new String[] {"targets"});
+ context.in = inputStream;
+ context.out = new CapturingPrintStream();
+ context.err = new CapturingPrintStream();
- // NGSecurityManager is used to convert System.exit() calls in to NGExitExceptions.
- SecurityManager originalSecurityManager = System.getSecurityManager();
+ // NGSecurityManager is used to convert System.exit() calls in to NGExitExceptions.
+ SecurityManager originalSecurityManager = System.getSecurityManager();
- // Run command to register client listener.
- try {
- System.setSecurityManager(new NGSecurityManager(originalSecurityManager));
- Main.nailMain(context);
- fail("Should throw NGExitException.");
- } catch (NGExitException e) {
- assertEquals("Should exit with status 0.", SUCCESS_EXIT_CODE, e.getStatus());
- } finally {
- System.setSecurityManager(originalSecurityManager);
- }
+ // Run command to register client listener.
+ try {
+ System.setSecurityManager(new NGSecurityManager(originalSecurityManager));
+ Main.nailMain(context);
+ fail("Should throw NGExitException.");
+ } catch (NGExitException e) {
+ assertEquals("Should exit with status 0.", SUCCESS_EXIT_CODE, e.getStatus());
+ } finally {
+ System.setSecurityManager(originalSecurityManager);
+ }
- // Check listener was registered calls System.exit() with client disconnect exit code.
- try {
- System.setSecurityManager(new NGSecurityManager(originalSecurityManager));
- assertNotNull("Should register client listener.", inputStream.listener);
- inputStream.listener.clientDisconnected();
- fail("Should throw NGExitException.");
- } catch (NGExitException e) {
- assertEquals("Should exit with status 3", Main.CLIENT_DISCONNECT_EXIT_CODE, e.getStatus());
- } finally {
- System.setSecurityManager(originalSecurityManager);
+ // Check listener was registered calls System.exit() with client disconnect exit code.
+ try {
+ System.setSecurityManager(new NGSecurityManager(originalSecurityManager));
+ assertNotNull("Should register client listener.", inputStream.listener);
+ inputStream.listener.clientDisconnected();
+ fail("Should throw NGExitException.");
+ } catch (NGExitException e) {
+ assertEquals("Should exit with status 3", Main.CLIENT_DISCONNECT_EXIT_CODE, e.getStatus());
+ } finally {
+ System.setSecurityManager(originalSecurityManager);
+ }
}
}
}