瀏覽代碼

HADOOP-1392. Fix 'correctness' bugs identified by FindBugs in fs and dfs packages. Contributed by Raghu.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@546261 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 年之前
父節點
當前提交
a47a7bcdce

+ 3 - 0
CHANGES.txt

@@ -84,6 +84,9 @@ Trunk (unreleased changes)
  27. HADOOP-1414.  Fix a number of issues identified by FindBugs as
      "Bad Practice".  (Dhruba Borthakur via cutting)
 
+ 28. HADOOP-1392.  Fix "correctness" bugs reported by FindBugs in
+     fs and dfs packages.  (Raghu Angadi via cutting)
+
 
 Release 0.13.0 - 2007-06-08
 

+ 1 - 1
src/java/org/apache/hadoop/dfs/FSImage.java

@@ -583,7 +583,7 @@ class FSImage extends Storage {
       if (checkpointTime <= 0L)
         needToSave |= true;
       // set finalized flag
-      isUpgradeFinalized &= !sd.getPreviousDir().exists();
+      isUpgradeFinalized = isUpgradeFinalized && !sd.getPreviousDir().exists();
     }
     assert latestSD != null : "Latest storage directory was not determined.";
 

+ 8 - 3
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -842,11 +842,16 @@ class FSNamesystem implements FSConstants {
       throw new SafeModeException("Cannot complete file " + src, safeMode);
     FileUnderConstruction pendingFile = pendingCreates.get(src);
 
-    if (dir.getFileBlocks(src.toString()) != null || pendingFile == null) {
+    Block[] fileBlocks =  dir.getFileBlocks(src.toString());
+    if (fileBlocks!= null || pendingFile == null) {    
       NameNode.stateChangeLog.warn("DIR* NameSystem.completeFile: "
                                    + "failed to complete " + src
-                                    + " because dir.getFile()==" + dir.getFileBlocks(src.toString()) 
-                                   + " and " + pendingFile);
+                                   + " because dir.getFileBlocks() is " + 
+                                   ((fileBlocks == null) ? "null":"non-null") + 
+                                   " and pendingFile is " + 
+                                   ((pendingFile == null) ? "null" : 
+                                     ("from " + pendingFile.getClientMachine()))
+                                  );                      
       return OPERATION_FAILED;
     } else if (!checkFileProgress(pendingFile, true)) {
       return STILL_WAITING;

+ 1 - 1
src/java/org/apache/hadoop/dfs/NamenodeFsck.java

@@ -420,7 +420,7 @@ public class NamenodeFsck {
     }
     if (chosenNode == null) {
       do  {
-        chosenNode = nodes[Math.abs(r.nextInt())  % nodes.length];
+        chosenNode = nodes[r.nextInt(nodes.length)];
       } while (deadNodes.contains(chosenNode));
     }
     return chosenNode;

+ 3 - 2
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -200,10 +200,11 @@ public abstract class FileSystem extends Configured {
     String thisAuthority = this.getUri().getAuthority();
     String thatAuthority = uri.getAuthority();
     if (!(this.getUri().getScheme().equals(uri.getScheme()) &&
-          (thisAuthority == null && thatAuthority == null)
-          || thisAuthority.equals(thatAuthority)))
+           (thisAuthority == thatAuthority || 
+             (thisAuthority != null && thisAuthority.equals(thatAuthority))))){
       throw new IllegalArgumentException("Wrong FS: "+path+
                                          ", expected: "+this.getUri());
+    }
   }
 
   /**

+ 3 - 3
src/java/org/apache/hadoop/util/CopyFiles.java

@@ -298,8 +298,8 @@ public class CopyFiles extends ToolBase {
       jobConf.setBoolean(readFailuresAttribute, ignoreReadFailures);
       
       Random r = new Random();
-      Path jobDirectory = new Path(jobConf.getSystemDir(), "distcp_" 
-                                   + Integer.toString(Math.abs(r.nextInt()), 36));
+      Path jobDirectory = new Path(jobConf.getSystemDir(), "distcp_"
+                                   + Integer.toString(r.nextInt(Integer.MAX_VALUE), 36));
       Path inDir = new Path(jobDirectory, "in");
       Path fakeOutDir = new Path(jobDirectory, "out");
       FileSystem fileSys = FileSystem.get(jobConf);
@@ -477,7 +477,7 @@ public class CopyFiles extends ToolBase {
       FileSystem fileSystem = FileSystem.get(conf);
       Random r = new Random();
       Path jobDirectory = new Path(jobConf.getSystemDir(), "distcp_" + 
-                                   Integer.toString(Math.abs(r.nextInt()), 36));
+                                   Integer.toString(r.nextInt(Integer.MAX_VALUE), 36));
       Path jobInputDir = new Path(jobDirectory, "in");
       if (!fileSystem.mkdirs(jobInputDir)) {
         throw new IOException("Mkdirs failed to create " + jobInputDir.toString());

+ 1 - 1
src/webapps/datanode/browseBlock.jsp

@@ -61,7 +61,7 @@
 
     String blockSizeStr = req.getParameter("blockSize"); 
     long blockSize = 0;
-    if (blockSizeStr == null && blockSizeStr.length() == 0) {
+    if (blockSizeStr == null || blockSizeStr.length() == 0) {
       out.print("Invalid input");
       return;
     }