Explorar o código

HADOOP-14609. NPE in AzureNativeFileSystemStore.checkContainer() if StorageException lacks an error code. Contributed by Steve Loughran

Mingliang Liu %!s(int64=7) %!d(string=hai) anos
pai
achega
990aa34de2

+ 5 - 5
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/AzureNativeFileSystemStore.java

@@ -1194,8 +1194,8 @@ public class AzureNativeFileSystemStore implements NativeFileSystemStore {
         container.downloadAttributes(getInstrumentedContext());
         container.downloadAttributes(getInstrumentedContext());
         currentKnownContainerState = ContainerState.Unknown;
         currentKnownContainerState = ContainerState.Unknown;
       } catch (StorageException ex) {
       } catch (StorageException ex) {
-        if (ex.getErrorCode().equals(
-            StorageErrorCode.RESOURCE_NOT_FOUND.toString())) {
+        if (StorageErrorCode.RESOURCE_NOT_FOUND.toString()
+            .equals(ex.getErrorCode())) {
           currentKnownContainerState = ContainerState.DoesntExist;
           currentKnownContainerState = ContainerState.DoesntExist;
         } else {
         } else {
           throw ex;
           throw ex;
@@ -1596,7 +1596,7 @@ public class AzureNativeFileSystemStore implements NativeFileSystemStore {
       if (t != null && t instanceof StorageException) {
       if (t != null && t instanceof StorageException) {
         StorageException se = (StorageException) t;
         StorageException se = (StorageException) t;
         // If we got this exception, the blob should have already been created
         // If we got this exception, the blob should have already been created
-        if (!se.getErrorCode().equals("LeaseIdMissing")) {
+        if (!"LeaseIdMissing".equals(se.getErrorCode())) {
           throw new AzureException(e);
           throw new AzureException(e);
         }
         }
       } else {
       } else {
@@ -2427,7 +2427,7 @@ public class AzureNativeFileSystemStore implements NativeFileSystemStore {
       // 2. It got there after one-or-more retries THEN
       // 2. It got there after one-or-more retries THEN
       // we swallow the exception.
       // we swallow the exception.
       if (e.getErrorCode() != null &&
       if (e.getErrorCode() != null &&
-          e.getErrorCode().equals("BlobNotFound") &&
+          "BlobNotFound".equals(e.getErrorCode()) &&
           operationContext.getRequestResults().size() > 1 &&
           operationContext.getRequestResults().size() > 1 &&
           operationContext.getRequestResults().get(0).getException() != null) {
           operationContext.getRequestResults().get(0).getException() != null) {
         LOG.debug("Swallowing delete exception on retry: {}", e.getMessage());
         LOG.debug("Swallowing delete exception on retry: {}", e.getMessage());
@@ -2478,7 +2478,7 @@ public class AzureNativeFileSystemStore implements NativeFileSystemStore {
       Throwable t = e.getCause();
       Throwable t = e.getCause();
       if(t != null && t instanceof StorageException) {
       if(t != null && t instanceof StorageException) {
         StorageException se = (StorageException) t;
         StorageException se = (StorageException) t;
-        if(se.getErrorCode().equals(("LeaseIdMissing"))){
+        if ("LeaseIdMissing".equals(se.getErrorCode())){
           SelfRenewingLease lease = null;
           SelfRenewingLease lease = null;
           try {
           try {
             lease = acquireLease(key);
             lease = acquireLease(key);

+ 2 - 2
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azure/SelfRenewingLease.java

@@ -82,7 +82,7 @@ public class SelfRenewingLease {
         // Throw again if we don't want to keep waiting.
         // Throw again if we don't want to keep waiting.
         // We expect it to be that the lease is already present,
         // We expect it to be that the lease is already present,
         // or in some cases that the blob does not exist.
         // or in some cases that the blob does not exist.
-        if (!e.getErrorCode().equals("LeaseAlreadyPresent")) {
+        if (!"LeaseAlreadyPresent".equals(e.getErrorCode())) {
           LOG.info(
           LOG.info(
             "Caught exception when trying to get lease on blob "
             "Caught exception when trying to get lease on blob "
             + blobWrapper.getUri().toString() + ". " + e.getMessage());
             + blobWrapper.getUri().toString() + ". " + e.getMessage());
@@ -119,7 +119,7 @@ public class SelfRenewingLease {
     try {
     try {
       blobWrapper.getBlob().releaseLease(accessCondition);
       blobWrapper.getBlob().releaseLease(accessCondition);
     } catch (StorageException e) {
     } catch (StorageException e) {
-      if (e.getErrorCode().equals("BlobNotFound")) {
+      if ("BlobNotFound".equals(e.getErrorCode())) {
 
 
         // Don't do anything -- it's okay to free a lease
         // Don't do anything -- it's okay to free a lease
         // on a deleted file. The delete freed the lease
         // on a deleted file. The delete freed the lease

+ 3 - 3
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/TestBlobDataValidation.java

@@ -20,9 +20,9 @@ package org.apache.hadoop.fs.azure;
 
 
 import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_CHECK_BLOCK_MD5;
 import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_CHECK_BLOCK_MD5;
 import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_STORE_BLOB_MD5;
 import static org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.KEY_STORE_BLOB_MD5;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeNotNull;
 import static org.junit.Assume.assumeNotNull;
 
 
@@ -130,8 +130,8 @@ public class TestBlobDataValidation {
       }
       }
       StorageException cause = (StorageException)ex.getCause();
       StorageException cause = (StorageException)ex.getCause();
       assertNotNull(cause);
       assertNotNull(cause);
-      assertTrue("Unexpected cause: " + cause,
-          cause.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MD5));
+      assertEquals("Unexpected cause: " + cause,
+          StorageErrorCodeStrings.INVALID_MD5, cause.getErrorCode());
     }
     }
   }
   }