jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1783503 - /jmeter/trunk/src/components/org/apache/jmeter/assertions/SMIMEAssertion.java
Date Sat, 18 Feb 2017 11:05:43 GMT
Author: fschumacher
Date: Sat Feb 18 11:05:43 2017
New Revision: 1783503

URL: http://svn.apache.org/viewvc?rev=1783503&view=rev
Log:
Use try-with statement to close all streams.

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/assertions/SMIMEAssertion.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/SMIMEAssertion.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/SMIMEAssertion.java?rev=1783503&r1=1783502&r2=1783503&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/SMIMEAssertion.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/SMIMEAssertion.java Sat Feb 18
11:05:43 2017
@@ -245,20 +245,23 @@ class SMIMEAssertion {
                     if (testElement.isSignerCheckByFile()) {
                         CertificateFactory cf = CertificateFactory
                                 .getInstance("X.509");
-                        X509CertificateHolder certFromFile;
-                        InputStream inStream = null;
-                        try {
-                            inStream = new BufferedInputStream(new FileInputStream(testElement.getSignerCertFile()));
-                            certFromFile = new JcaX509CertificateHolder((X509Certificate)
cf.generateCertificate(inStream));
-                        } finally {
-                            IOUtils.closeQuietly(inStream);
-                        }
-
-                        if (!certFromFile.equals(cert)) {
+                        try (InputStream fis = new FileInputStream(testElement.getSignerCertFile());
+                                InputStream bis = new BufferedInputStream(fis)){
+                            X509CertificateHolder certFromFile = new JcaX509CertificateHolder((X509Certificate)
cf.generateCertificate(bis));
+                            if (!certFromFile.equals(cert)) {
+                                res.setFailure(true);
+                                res.setFailureMessage("Signer certificate does not match
certificate "
+                                                + testElement.getSignerCertFile());
+                            }
+                        } catch (IOException e) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("Could not read cert file {}", testElement.getSignerCertFile(),
e);
+                            }
                             res.setFailure(true);
-                            res.setFailureMessage("Signer certificate does not match certificate
"
-                                            + testElement.getSignerCertFile());
+                            res.setFailureMessage("Could not read certificate file " + testElement.getSignerCertFile());
                         }
+
+                        
                     }
 
                 } else {



Mime
View raw message