From 2e98ad34ce64a9e5184c53447004de20a637f927 Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Tue, 9 Dec 2014 20:45:21 -0800 Subject: [PATCH] HADOOP-11381. Fix findbugs warnings in hadoop-distcp, hadoop-aws, hadoop-azure, and hadoop-openstack. Contributed by Li Lu. --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java | 4 ++++ .../org/apache/hadoop/fs/azure/NativeAzureFileSystem.java | 5 +++-- .../java/org/apache/hadoop/fs/azure/SelfRenewingLease.java | 7 ++++--- .../java/org/apache/hadoop/tools/FileBasedCopyListing.java | 4 +++- .../fs/swift/snative/SwiftNativeFileSystemStore.java | 7 ++++--- .../org/apache/hadoop/fs/swift/util/SwiftTestUtils.java | 4 ++-- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 0019b3a629d..9065ff5c003 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -555,6 +555,8 @@ Release 2.7.0 - UNRELEASED HADOOP-11349. RawLocalFileSystem leaks file descriptor while creating a file if creat succeeds but chmod fails. (Varun Saxena via Colin P. McCabe) + HADOOP-11381. Fix findbugs warnings in hadoop-distcp, hadoop-aws, + hadoop-azure, and hadoop-openstack. (Li Lu via wheat9) Release 2.6.0 - 2014-11-18 diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java index 6bdd2335065..457351d0242 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java @@ -875,6 +875,8 @@ public class S3AFileSystem extends FileSystem { case ProgressEvent.PART_COMPLETED_EVENT_CODE: statistics.incrementWriteOps(1); break; + default: + break; } } }; @@ -933,6 +935,8 @@ public class S3AFileSystem extends FileSystem { case ProgressEvent.PART_COMPLETED_EVENT_CODE: statistics.incrementWriteOps(1); break; + default: + break; } } }; diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/NativeAzureFileSystem.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/NativeAzureFileSystem.java index ad2e2e6635c..c1360022201 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/NativeAzureFileSystem.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/NativeAzureFileSystem.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -153,7 +154,7 @@ public class NativeAzureFileSystem extends FileSystem { "Error reading pending rename file contents -- " + "maximum file size exceeded"); } - String contents = new String(bytes, 0, l); + String contents = new String(bytes, 0, l, Charset.forName("UTF-8")); // parse the JSON ObjectMapper objMapper = new ObjectMapper(); @@ -253,7 +254,7 @@ public class NativeAzureFileSystem extends FileSystem { // Write file. try { output = fs.create(path); - output.write(contents.getBytes()); + output.write(contents.getBytes(Charset.forName("UTF-8"))); } catch (IOException e) { throw new IOException("Unable to write RenamePending file for folder rename from " + srcKey + " to " + dstKey, e); diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/SelfRenewingLease.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/SelfRenewingLease.java index 2d5c0c8ebde..bda6006d602 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/SelfRenewingLease.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/SelfRenewingLease.java @@ -18,7 +18,6 @@ package org.apache.hadoop.fs.azure; -import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.azure.StorageInterface.CloudBlobWrapper; @@ -27,6 +26,8 @@ import com.microsoft.windowsazure.storage.AccessCondition; import com.microsoft.windowsazure.storage.StorageException; import com.microsoft.windowsazure.storage.blob.CloudBlob; +import java.util.concurrent.atomic.AtomicInteger; + /** * An Azure blob lease that automatically renews itself indefinitely * using a background thread. Use it to synchronize distributed processes, @@ -56,7 +57,7 @@ public class SelfRenewingLease { private static final Log LOG = LogFactory.getLog(SelfRenewingLease.class); // Used to allocate thread serial numbers in thread name - private static volatile int threadNumber = 0; + private static AtomicInteger threadNumber = new AtomicInteger(0); // Time to wait to retry getting the lease in milliseconds @@ -99,7 +100,7 @@ public class SelfRenewingLease { // A Renewer running should not keep JVM from exiting, so make it a daemon. renewer.setDaemon(true); - renewer.setName("AzureLeaseRenewer-" + threadNumber++); + renewer.setName("AzureLeaseRenewer-" + threadNumber.getAndIncrement()); renewer.start(); LOG.debug("Acquired lease " + leaseID + " on " + blob.getUri() + " managed by thread " + renewer.getName()); diff --git a/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/FileBasedCopyListing.java b/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/FileBasedCopyListing.java index 0fe93c2f136..2bc343e1727 100644 --- a/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/FileBasedCopyListing.java +++ b/hadoop-tools/hadoop-distcp/src/main/java/org/apache/hadoop/tools/FileBasedCopyListing.java @@ -27,6 +27,7 @@ import org.apache.hadoop.security.Credentials; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -74,7 +75,8 @@ public class FileBasedCopyListing extends CopyListing { FileSystem fs = sourceListing.getFileSystem(getConf()); BufferedReader input = null; try { - input = new BufferedReader(new InputStreamReader(fs.open(sourceListing))); + input = new BufferedReader(new InputStreamReader(fs.open(sourceListing), + Charset.forName("UTF-8"))); String line = input.readLine(); while (line != null) { result.add(new Path(line)); diff --git a/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java b/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java index b3e6b941795..0138eae412d 100644 --- a/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java +++ b/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystemStore.java @@ -45,6 +45,7 @@ import java.io.InputStream; import java.io.InterruptedIOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.Charset; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -352,8 +353,8 @@ public class SwiftNativeFileSystemStore { final CollectionType collectionType = JSONUtil.getJsonMapper().getTypeFactory(). constructCollectionType(List.class, SwiftObjectFileStatus.class); - final List fileStatusList = - JSONUtil.toObject(new String(bytes), collectionType); + final List fileStatusList = JSONUtil.toObject( + new String(bytes, Charset.forName("UTF-8")), collectionType); //this can happen if user lists file /data/files/file //in this case swift will return empty array @@ -447,7 +448,7 @@ public class SwiftNativeFileSystemStore { //no object location, return an empty list return new LinkedList(); } - return extractUris(new String(objectLocation), path); + return extractUris(new String(objectLocation, Charset.forName("UTF-8")), path); } /** diff --git a/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java b/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java index 7e850e713de..c9e26acf3d4 100644 --- a/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java +++ b/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/util/SwiftTestUtils.java @@ -219,9 +219,9 @@ public class SwiftTestUtils extends org.junit.Assert { byte actual = dest[i]; byte expected = src[i]; String letter = toChar(actual); - String line = String.format("[%04d] %2x %s\n", i, actual, letter); + String line = String.format("[%04d] %2x %s%n", i, actual, letter); if (expected != actual) { - line = String.format("[%04d] %2x %s -expected %2x %s\n", + line = String.format("[%04d] %2x %s -expected %2x %s%n", i, actual, letter,