diff --git a/s2a/src/test/java/io/grpc/s2a/internal/handshaker/FakeWriter.java b/s2a/src/test/java/io/grpc/s2a/internal/handshaker/FakeWriter.java index 8f91969788c..4455e77b1e2 100644 --- a/s2a/src/test/java/io/grpc/s2a/internal/handshaker/FakeWriter.java +++ b/s2a/src/test/java/io/grpc/s2a/internal/handshaker/FakeWriter.java @@ -106,10 +106,12 @@ FakeWriter setFailureReason(String failureReason) { @CanIgnoreReturnValue FakeWriter initializePrivateKey() throws InvalidKeySpecException, NoSuchAlgorithmException, IOException, FileNotFoundException, UnsupportedEncodingException { - FileInputStream keyInputStream = - new FileInputStream(keyFile); - privateKey = - CertificateUtils.getPrivateKey(keyInputStream); + FileInputStream keyInputStream = new FileInputStream(keyFile); + try { + privateKey = CertificateUtils.getPrivateKey(keyInputStream); + } finally { + keyInputStream.close(); + } return this; }