Browse Source

HADOOP-14400. Fix warnings from spotbugs in hadoop-tools. Contributed by Weiwei Yang.

(cherry picked from commit 2ba9903932e3c99afb0e6abb7cd3c5d29a554bd9)
Akira Ajisaka 8 years ago
parent
commit
2dffc1d8cb

+ 0 - 10
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/NativeAzureFileSystem.java

@@ -3010,8 +3010,6 @@ public class NativeAzureFileSystem extends FileSystem {
 
 
     ArrayList<String> keysToCreateAsFolder = new ArrayList<String>();
-    ArrayList<String> keysToUpdateAsFolder = new ArrayList<String>();
-    boolean childCreated = false;
     // Check that there is no file in the parent chain of the given path.
     for (Path current = absolutePath, parent = current.getParent();
         parent != null; // Stop when you get to the root
@@ -3023,14 +3021,6 @@ public class NativeAzureFileSystem extends FileSystem {
             + current + " is an existing file.");
       } else if (currentMetadata == null) {
         keysToCreateAsFolder.add(currentKey);
-        childCreated = true;
-      } else {
-        // The directory already exists. Its last modified time need to be
-        // updated if there is a child directory created under it.
-        if (childCreated) {
-          keysToUpdateAsFolder.add(currentKey);
-        }
-        childCreated = false;
       }
     }
 

+ 2 - 4
hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/InputStriper.java

@@ -131,9 +131,7 @@ class InputStriper {
   static final Comparator<Entry<String,Double>> hostRank =
     new Comparator<Entry<String,Double>>() {
       public int compare(Entry<String,Double> a, Entry<String,Double> b) {
-          final double va = a.getValue();
-          final double vb = b.getValue();
-          return va > vb ? -1 : va < vb ? 1 : 0;
-        }
+        return Double.compare(a.getValue(), b.getValue());
+      }
     };
 }

+ 14 - 2
hadoop-tools/hadoop-gridmix/src/main/java/org/apache/hadoop/mapred/gridmix/emulators/resourceusage/TotalHeapUsageEmulatorPlugin.java

@@ -19,6 +19,8 @@ package org.apache.hadoop.mapred.gridmix.emulators.resourceusage;
 
 import java.io.IOException;
 import java.util.ArrayList;
+
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.mapred.gridmix.Progressive;
 import org.apache.hadoop.tools.rumen.ResourceUsageMetrics;
@@ -129,7 +131,7 @@ implements ResourceUsageEmulatorPlugin {
   public static class DefaultHeapUsageEmulator 
   implements HeapUsageEmulatorCore {
     // store the unit loads in a list
-    protected static final ArrayList<Object> heapSpace =
+    private static final ArrayList<Object> heapSpace =
         new ArrayList<Object>();
     
     /**
@@ -142,7 +144,17 @@ implements ResourceUsageEmulatorPlugin {
         heapSpace.add((Object)new byte[ONE_MB]);
       }
     }
-    
+
+    /**
+     * Gets the total number of 1mb objects stored in the emulator.
+     *
+     * @return total number of 1mb objects.
+     */
+    @VisibleForTesting
+    public int getHeapSpaceSize() {
+      return heapSpace.size();
+    }
+
     /**
      * This will initialize the core and check if the core can emulate the 
      * desired target on the underlying hardware.

+ 1 - 1
hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixMemoryEmulation.java

@@ -58,7 +58,7 @@ public class TestGridmixMemoryEmulation {
     
     // Get the total number of 1mb objects stored within
     long getHeapUsageInMB() {
-      return heapSpace.size();
+      return getHeapSpaceSize();
     }
     
     @Override

+ 5 - 5
hadoop-tools/hadoop-rumen/src/main/java/org/apache/hadoop/tools/rumen/datatypes/util/MapReduceJobPropertiesParser.java

@@ -131,7 +131,7 @@ public class MapReduceJobPropertiesParser implements JobPropertyParser {
   /**
    * Extracts the -Xmx heap option from the specified string.
    */
-  public static void extractMaxHeapOpts(String javaOptions, 
+  public static void extractMaxHeapOpts(final String javaOptions,
                                         List<String> heapOpts, 
                                         List<String> others) {
     for (String opt : javaOptions.split(" ")) {
@@ -161,6 +161,7 @@ public class MapReduceJobPropertiesParser implements JobPropertyParser {
   
   // Maps the value of the specified key.
   private DataType<?> fromString(String key, String value) {
+    DefaultDataType defaultValue = new DefaultDataType(value);
     if (value != null) {
       // check known configs
       //  job-name
@@ -191,14 +192,13 @@ public class MapReduceJobPropertiesParser implements JobPropertyParser {
       // check if the config parameter represents a number
       try {
         format.parse(value);
-        return new DefaultDataType(value);
+        return defaultValue;
       } catch (ParseException pe) {}
 
       // check if the config parameters represents a boolean 
       // avoiding exceptions
       if ("true".equals(value) || "false".equals(value)) {
-        Boolean.parseBoolean(value);
-        return new DefaultDataType(value);
+        return defaultValue;
       }
 
       // check if the config parameter represents a class
@@ -209,7 +209,7 @@ public class MapReduceJobPropertiesParser implements JobPropertyParser {
       // handle distributed cache sizes and timestamps
       if (latestKey.endsWith("sizes") 
           || latestKey.endsWith(".timestamps")) {
-        new DefaultDataType(value);
+        return defaultValue;
       }
       
       // check if the config parameter represents a file-system path