knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject knox git commit: KNOX-867 - Fix FindBugs, bad practice issues (Colm O hEigeartaigh via Sandeep More)
Date Thu, 02 Feb 2017 20:24:32 GMT
Repository: knox
Updated Branches:
  refs/heads/master 3db608ea9 -> dccdedda4


KNOX-867 - Fix FindBugs, bad practice issues (Colm O hEigeartaigh via Sandeep More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/dccdedda
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/dccdedda
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/dccdedda

Branch: refs/heads/master
Commit: dccdedda43ef1fd91200469273bcbc98d1b57735
Parents: 3db608e
Author: Sandeep More <more@apache.org>
Authored: Thu Feb 2 15:10:43 2017 -0500
Committer: Sandeep More <more@apache.org>
Committed: Thu Feb 2 15:10:43 2017 -0500

----------------------------------------------------------------------
 .../apache/hadoop/gateway/GatewayServer.java    | 22 ++++++++++----------
 .../gateway/deploy/DeploymentFactory.java       | 17 ++++++++-------
 .../apache/hadoop/gateway/trace/TraceInput.java |  2 +-
 .../hadoop/gateway/trace/TraceOutput.java       |  2 +-
 .../hadoop/gateway/trace/TraceRequest.java      |  2 +-
 .../hadoop/gateway/trace/TraceResponse.java     |  2 +-
 .../gateway/service/knoxsso/WebSSOResource.java | 13 ++++++------
 .../security/impl/CMFKeystoreService.java       |  4 ++--
 .../apache/hadoop/gateway/topology/Service.java | 16 ++++++++++++++
 .../apache/hadoop/test/mock/MockServlet.java    |  2 +-
 10 files changed, 50 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
index b5c12d6..fe59bf7 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Serializable;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.URI;
@@ -671,11 +672,8 @@ public class GatewayServer {
           internalDeactivateTopology( topology ); // KNOX-152
 
           EnterpriseArchive ear = DeploymentFactory.createDeployment( config, topology );
-          if( !deployDir.exists() ) {
-            deployDir.mkdirs();
-            if( !deployDir.exists() ) {
-              throw new DeploymentException( "Failed to create topology deployment temporary
directory: " + deployDir.getAbsolutePath() );
-            }
+          if( !deployDir.exists() && !deployDir.mkdirs() ) {
+            throw new DeploymentException( "Failed to create topology deployment temporary
directory: " + deployDir.getAbsolutePath() );
           }
           File tmp = ear.as( ExplodedExporter.class ).exportExploded( deployDir, topoDir.getName()
+ ".tmp" );
           if( !tmp.renameTo( topoDir ) ) {
@@ -702,11 +700,8 @@ public class GatewayServer {
 
   private File createArchiveTempDir( File warDir ) {
     File tempDir = FileUtils.getFile( warDir, "META-INF", "temp" );
-    if( !tempDir.exists() ) {
-      tempDir.mkdirs();
-      if( !tempDir.exists() ) {
-        throw new DeploymentException( "Failed to create archive temporary directory: " +
tempDir.getAbsolutePath() );
-      }
+    if( !tempDir.exists() && !tempDir.mkdirs() ) {
+      throw new DeploymentException( "Failed to create archive temporary directory: " + tempDir.getAbsolutePath()
);
     }
     return tempDir;
   }
@@ -784,7 +779,12 @@ public class GatewayServer {
     return frontendUri;
   }
 
-  private static class FileModificationTimeDescendingComparator implements Comparator<File>
{
+  private static class FileModificationTimeDescendingComparator implements Comparator<File>,
Serializable {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -2269785204848916823L;
+
     @Override
     public int compare( File left, File right ) {
       long leftTime = ( left == null ? Long.MIN_VALUE : left.lastModified() );

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
index e616501..db6476b 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/deploy/DeploymentFactory.java
@@ -29,6 +29,7 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.TreeMap;
@@ -369,8 +370,8 @@ public abstract class DeploymentFactory {
       DeploymentContext context,
       Map<String,List<ProviderDeploymentContributor>> providers ) {
     if( providers != null ) {
-      for( String role : providers.keySet() ) {
-        for( ProviderDeploymentContributor contributor : providers.get( role ) ) {
+      for( Entry<String, List<ProviderDeploymentContributor>> entry : providers.entrySet()
) {
+        for( ProviderDeploymentContributor contributor : entry.getValue() ) {
           try {
             injectServices( contributor );
             log.initializeProvider( contributor.getName(), contributor.getRole() );
@@ -386,8 +387,8 @@ public abstract class DeploymentFactory {
 
   private static void initializeServices( DeploymentContext context, Map<String, List<ServiceDeploymentContributor>>
services ) {
     if( services != null ) {
-      for( String role : services.keySet() ) {
-        for( ServiceDeploymentContributor contributor : services.get( role ) ) {
+      for( Entry<String, List<ServiceDeploymentContributor>> entry : services.entrySet()
) {
+        for( ServiceDeploymentContributor contributor : entry.getValue() ) {
           try {
             injectServices( contributor );
             log.initializeService( contributor.getName(), contributor.getRole() );
@@ -592,8 +593,8 @@ public abstract class DeploymentFactory {
 
   private static void finalizeProviders( DeploymentContext context, Map<String, List<ProviderDeploymentContributor>>
providers ) {
     if( providers != null ) {
-      for( String role : providers.keySet() ) {
-        for( ProviderDeploymentContributor contributor : providers.get( role ) ) {
+      for( Entry<String, List<ProviderDeploymentContributor>> entry : providers.entrySet()
) {
+        for( ProviderDeploymentContributor contributor : entry.getValue() ) {
           try {
             log.finalizeProvider( contributor.getName(), contributor.getRole() );
             contributor.finalizeContribution( context );
@@ -609,8 +610,8 @@ public abstract class DeploymentFactory {
 
   private static void finalizeServices( DeploymentContext context, Map<String, List<ServiceDeploymentContributor>>
services ) {
     if( services != null ) {
-      for( String role : services.keySet() ) {
-        for( ServiceDeploymentContributor contributor : services.get( role ) ) {
+      for( Entry<String, List<ServiceDeploymentContributor>> entry : services.entrySet()
) {
+        for( ServiceDeploymentContributor contributor : entry.getValue() ) {
           try {
             log.finalizeService( contributor.getName(), contributor.getRole() );
             contributor.finalizeContribution( context );

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceInput.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceInput.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceInput.java
index d6d7246..56c0dd8 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceInput.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceInput.java
@@ -61,7 +61,7 @@ class TraceInput extends SynchronousServletInputStreamAdapter {
       buffer.setLength( 0 );
       StringBuilder sb = new StringBuilder();
       TraceUtil.appendCorrelationContext( sb );
-      sb.append( String.format( "|RequestBody[%d]\n\t%s", body.length(), body ) );
+      sb.append( String.format( "|RequestBody[%d]%n\t%s", body.length(), body ) );
       if( bodyLog.isTraceEnabled() ) {
         log.trace( sb.toString() );
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceOutput.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceOutput.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceOutput.java
index 166753b..ac93403 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceOutput.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceOutput.java
@@ -66,7 +66,7 @@ class TraceOutput extends SynchronousServletOutputStreamAdapter {
       buffer.setLength( 0 );
       StringBuilder sb = new StringBuilder();
       TraceUtil.appendCorrelationContext( sb );
-      sb.append( String.format( "|ResponseBody[%d]\n\t%s", body.length(), body ) );
+      sb.append( String.format( "|ResponseBody[%d]%n\t%s", body.length(), body ) );
       if( bodyLog.isTraceEnabled() ) {
         log.trace( sb.toString() );
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceRequest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceRequest.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceRequest.java
index 3211c50..71123fd 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceRequest.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceRequest.java
@@ -74,7 +74,7 @@ class TraceRequest extends HttpServletRequestWrapper {
         Enumeration<String> values = getHeaders( name );
         while( values.hasMoreElements() ) {
           String value = values.nextElement();
-          sb.append( String.format( "\n\tHeader[%s]=%s", name, value ) );
+          sb.append( String.format( "%n\tHeader[%s]=%s", name, value ) );
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceResponse.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceResponse.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceResponse.java
index 632fa86..657aa14 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceResponse.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/trace/TraceResponse.java
@@ -66,7 +66,7 @@ class TraceResponse extends HttpServletResponseWrapper {
       Collection<String> names = getHeaderNames();
       for( String name : names ) {
         for( String value : getHeaders( name ) ) {
-          sb.append( String.format( "\n\tHeader[%s]=%s", name, value ) );
+          sb.append( String.format( "%n\tHeader[%s]=%s", name, value ) );
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
index 7f2114a..283b627 100644
--- a/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
+++ b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
@@ -23,6 +23,7 @@ import java.net.URISyntaxException;
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.annotation.PostConstruct;
 import javax.servlet.ServletContext;
@@ -237,11 +238,11 @@ public class WebSSOResource {
     // Probably not ideal but will not break existing integrations by requiring
     // some encoding.
     Map<String, String[]> params = request.getParameterMap();
-    for (String name : params.keySet()) {
-      if (!ORIGINAL_URL_REQUEST_PARAM.equals(name)
-          && !original.contains(name + "=")) {
-        buf.append("&").append(name);
-        String[] values = params.get(name);
+    for (Entry<String, String[]> entry : params.entrySet()) {
+      if (!ORIGINAL_URL_REQUEST_PARAM.equals(entry.getKey())
+          && !original.contains(entry.getKey() + "=")) {
+        buf.append("&").append(entry.getKey());
+        String[] values = entry.getValue();
         if (values.length > 0 && values[0] != null) {
           buf.append("=");
         }
@@ -249,7 +250,7 @@ public class WebSSOResource {
           if (values[0] != null) {
             buf.append(values[i]);
             if (i < values.length-1) {
-              buf.append("&").append(name).append("=");
+              buf.append("&").append(entry.getKey()).append("=");
             }
           }
         }

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/CMFKeystoreService.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/CMFKeystoreService.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/CMFKeystoreService.java
index 06dad1c..6069190 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/CMFKeystoreService.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/impl/CMFKeystoreService.java
@@ -50,8 +50,8 @@ public class CMFKeystoreService extends BaseKeystoreService {
     this.serviceName = serviceName;
     this.keyStoreDir = keystoreDir + File.separator;
     File ksd = new File(this.keyStoreDir);
-    if (!ksd.exists()) {
-      ksd.mkdirs();
+    if (!ksd.exists() && !ksd.mkdirs()) {
+      throw new ServiceLifecycleException("Cannot create the keystore directory");
     }
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
index c698c4c..80951cd 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Service.java
@@ -131,4 +131,20 @@ public class Service {
     }
     return true;
   }
+  
+  @Override
+  public int hashCode() {
+    int hashCode = 17;
+    if (getName() != null) {
+      hashCode *= 31 * getName().hashCode();
+    }
+    if (getRole() != null) {
+      hashCode *= 31 * getRole().hashCode();
+    }
+    if (getVersion() != null) {
+      hashCode *= 31 * getVersion().hashCode();
+    }
+
+    return hashCode;
+  }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/dccdedda/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
index 18191b5..ca4692c 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServlet.java
@@ -30,7 +30,7 @@ import static org.junit.Assert.fail;
 
 public class MockServlet extends HttpServlet {
 
-  Logger LOG = Logger.getLogger(MockServlet.class.getName());
+  private static final Logger LOG = Logger.getLogger(MockServlet.class.getName());
 
   public String name;
   public Queue<MockInteraction> interactions;


Mime
View raw message