Repository: knox Updated Branches: refs/heads/master 15bb53810 -> 2d51810c2
KNOX-876 - Fix FindBugs "Experimental" issues (Colm O hEigeartaigh via lmccay) Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/2d51810c Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/2d51810c Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/2d51810c Branch: refs/heads/master Commit: 2d51810c2b9123a9ff6be1a6d269efecc32ba16f Parents: 15bb538 Author: Larry McCay <lmc...@hortonworks.com> Authored: Wed Feb 22 09:57:06 2017 -0500 Committer: Larry McCay <lmc...@hortonworks.com> Committed: Wed Feb 22 09:57:06 2017 -0500 ---------------------------------------------------------------------- .../deploy/impl/ApplicationDeploymentContributor.java | 7 ++++--- .../java/org/apache/hadoop/gateway/shell/KnoxSh.java | 8 ++------ .../services/security/impl/BaseKeystoreService.java | 13 +++---------- .../services/security/impl/X509CertificateUtil.java | 5 +---- 4 files changed, 10 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/2d51810c/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ApplicationDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ApplicationDeploymentContributor.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ApplicationDeploymentContributor.java index f93c38a..ce642d1 100644 --- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ApplicationDeploymentContributor.java +++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/impl/ApplicationDeploymentContributor.java @@ -60,7 +60,7 @@ public class ApplicationDeploymentContributor extends ServiceDeploymentContribut private UrlRewriteRulesDescriptor serviceRules; - private static ServiceDefinition loadServiceDefinition( Application application, File file ) throws JAXBException, FileNotFoundException { + private static ServiceDefinition loadServiceDefinition( Application application, File file ) throws JAXBException, FileNotFoundException, IOException { ServiceDefinition definition; if( !file.exists() ) { definition = new ServiceDefinition(); @@ -77,8 +77,9 @@ public class ApplicationDeploymentContributor extends ServiceDeploymentContribut } else { JAXBContext context = JAXBContext.newInstance( ServiceDefinition.class ); Unmarshaller unmarshaller = context.createUnmarshaller(); - FileInputStream inputStream = new FileInputStream( file ); - definition = (ServiceDefinition) unmarshaller.unmarshal( inputStream ); + try( FileInputStream inputStream = new FileInputStream( file ) ) { + definition = (ServiceDefinition) unmarshaller.unmarshal( inputStream ); + } } return definition; } http://git-wip-us.apache.org/repos/asf/knox/blob/2d51810c/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java index 0e2a14d..15ad535 100644 --- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java +++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java @@ -186,18 +186,14 @@ public class KnoxSh { System.out.println("knoxinit successful!"); displayTokenDetails(json); - FileOutputStream fos = null; - try { - File tokenfile = new File(System.getProperty("user.home"), ".knoxtokencache"); - fos = new FileOutputStream(tokenfile); + File tokenfile = new File(System.getProperty("user.home"), ".knoxtokencache"); + try( FileOutputStream fos = new FileOutputStream(tokenfile) ) { fos.write(text.getBytes("UTF-8")); Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); //add owners permission only perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(Paths.get(System.getProperty("user.home") + "/.knoxtokencache"), perms); - } finally { - fos.close(); } } catch(HadoopException he) { http://git-wip-us.apache.org/repos/asf/knox/blob/2d51810c/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/BaseKeystoreService.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/BaseKeystoreService.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/BaseKeystoreService.java index 055cbe3..70e5689 100644 --- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/BaseKeystoreService.java +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/BaseKeystoreService.java @@ -212,26 +212,19 @@ public class BaseKeystoreService { protected void writeCertificateToFile( Certificate cert, final File file ) throws CertificateEncodingException, IOException { byte[] bytes = cert.getEncoded(); - final FileOutputStream out = new FileOutputStream( file ); Base64 encoder = new Base64( 76, "\n".getBytes( "ASCII" ) ); - try { + try( final FileOutputStream out = new FileOutputStream( file ) ) { out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( "ASCII" ) ); out.write( encoder.encodeToString( bytes ).getBytes( "ASCII" ) ); out.write( "-----END CERTIFICATE-----\n".getBytes( "ASCII" ) ); - } finally { - out.close(); } } protected void writeKeystoreToFile(final KeyStore keyStore, final File file) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { // TODO: backup the keystore on disk before attempting a write and restore on failure - final FileOutputStream out = new FileOutputStream(file); - try { - keyStore.store( out, masterService.getMasterSecret()); - } - finally { - out.close(); + try( final FileOutputStream out = new FileOutputStream(file) ) { + keyStore.store( out, masterService.getMasterSecret() ); } } http://git-wip-us.apache.org/repos/asf/knox/blob/2d51810c/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/X509CertificateUtil.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/X509CertificateUtil.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/X509CertificateUtil.java index f6a7ecd..87bb78c 100644 --- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/X509CertificateUtil.java +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/X509CertificateUtil.java @@ -276,14 +276,11 @@ public class X509CertificateUtil { public static void writeCertificateToFile(Certificate cert, final File file) throws CertificateEncodingException, IOException { byte[] bytes = cert.getEncoded(); - final FileOutputStream out = new FileOutputStream( file ); Base64 encoder = new Base64( 76, "\n".getBytes( "ASCII" ) ); - try { + try( final FileOutputStream out = new FileOutputStream( file ) ) { out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( "ASCII" ) ); out.write( encoder.encodeToString( bytes ).getBytes( "ASCII" ) ); out.write( "-----END CERTIFICATE-----\n".getBytes( "ASCII" ) ); - } finally { - out.close(); } }