You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2020/08/17 18:06:55 UTC

[accumulo] branch 1.10 updated: Fix warnings from #1687

This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch 1.10
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/1.10 by this push:
     new 7a2d12e  Fix warnings from #1687
7a2d12e is described below

commit 7a2d12eaf785f924f555733a54f40828cdb2414f
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Mon Aug 17 12:40:40 2020 -0400

    Fix warnings from #1687
---
 .../crypto/CachingHDFSSecretKeyEncryptionStrategy.java | 18 ++++++------------
 .../java/org/apache/accumulo/server/fs/VolumeUtil.java |  2 +-
 .../src/main/java/org/apache/accumulo/shell/Shell.java |  4 ++--
 .../commands/ShellPluginConfigurationCommand.java      |  4 ++--
 .../java/org/apache/accumulo/shell/ShellUtilTest.java  |  4 ++--
 .../java/org/apache/accumulo/test/AuditMessageIT.java  | 11 ++---------
 6 files changed, 15 insertions(+), 28 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java b/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
index b3197ee..89b90a7 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
@@ -30,7 +30,6 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.util.CachedConfiguration;
-import org.apache.commons.io.IOUtils;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.slf4j.Logger;
@@ -137,24 +136,19 @@ public class CachingHDFSSecretKeyEncryptionStrategy implements SecretKeyEncrypti
       Path pathToKey = new Path(pathToKeyName);
       FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
 
-      DataInputStream in = null;
       try {
         if (!fs.exists(pathToKey)) {
           initializeKeyEncryptionKey(fs, pathToKey, context);
         }
 
-        in = fs.open(pathToKey);
-
-        int keyEncryptionKeyLength = in.readInt();
-        keyEncryptionKey = new byte[keyEncryptionKeyLength];
-        in.readFully(keyEncryptionKey);
-
-        initialized = true;
-
+        try (DataInputStream in = fs.open(pathToKey)) {
+          int keyEncryptionKeyLength = in.readInt();
+          keyEncryptionKey = new byte[keyEncryptionKeyLength];
+          in.readFully(keyEncryptionKey);
+          initialized = true;
+        }
       } catch (IOException e) {
         log.error("Could not initialize key encryption cache", e);
-      } finally {
-        IOUtils.closeQuietly(in);
       }
     }
 
diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java
index 4469f6d..4cc53cc 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java
@@ -376,7 +376,7 @@ public class VolumeUtil {
   private static String hash(FileSystem fs, Path dir, String name) throws IOException {
     FSDataInputStream in = fs.open(new Path(dir, name));
     try {
-      return DigestUtils.shaHex(in);
+      return DigestUtils.sha1Hex(in);
     } finally {
       in.close();
     }
diff --git a/shell/src/main/java/org/apache/accumulo/shell/Shell.java b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
index 6f8eab0..a3efa9a 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -163,8 +163,8 @@ import org.apache.accumulo.shell.commands.WhoAmICommand;
 import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
 import org.apache.accumulo.start.classloader.vfs.ContextManager;
 import org.apache.accumulo.start.spi.KeywordExecutable;
-import org.apache.commons.cli.BasicParser;
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.MissingOptionException;
 import org.apache.commons.cli.Option;
@@ -836,7 +836,7 @@ public class Shell extends ShellOptions implements KeywordExecutable {
         Options parseOpts = sc.getOptionsWithHelp();
 
         // Parse the string using the given options
-        CommandLine cl = new BasicParser().parse(parseOpts, fields);
+        CommandLine cl = new DefaultParser().parse(parseOpts, fields);
 
         int actualArgLen = cl.getArgs().length;
         int expectedArgLen = sc.numArgs();
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/ShellPluginConfigurationCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/ShellPluginConfigurationCommand.java
index 9c35e71..507cda0 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/ShellPluginConfigurationCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/ShellPluginConfigurationCommand.java
@@ -26,8 +26,8 @@ import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.shell.Shell;
 import org.apache.accumulo.shell.Shell.Command;
-import org.apache.commons.cli.BasicParser;
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
@@ -116,7 +116,7 @@ public abstract class ShellPluginConfigurationCommand extends Command {
           o.addOption(OptUtil.tableOpt());
           args[0] = "-t";
           args[1] = tableName;
-          CommandLine cl = new BasicParser().parse(o, args);
+          CommandLine cl = new DefaultParser().parse(o, args);
           pluginClazz =
               shellState.getClassLoader(cl, shellState).loadClass(ent.getValue()).asSubclass(clazz);
         } catch (ClassNotFoundException e) {
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java
index c430ab0..50b4648 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java
@@ -48,7 +48,7 @@ public class ShellUtilTest {
   @Test
   public void testWithoutDecode() throws IOException {
     File testFile = new File(folder.getRoot(), "testFileNoDecode.txt");
-    FileUtils.writeStringToFile(testFile, FILEDATA);
+    FileUtils.writeStringToFile(testFile, FILEDATA, UTF_8);
     List<Text> output = ShellUtil.scanFile(testFile.getAbsolutePath(), false);
     assertEquals(ImmutableList.of(new Text("line1"), new Text("line2")), output);
   }
@@ -56,7 +56,7 @@ public class ShellUtilTest {
   @Test
   public void testWithDecode() throws IOException {
     File testFile = new File(folder.getRoot(), "testFileWithDecode.txt");
-    FileUtils.writeStringToFile(testFile, B64_FILEDATA);
+    FileUtils.writeStringToFile(testFile, B64_FILEDATA, UTF_8);
     List<Text> output = ShellUtil.scanFile(testFile.getAbsolutePath(), true);
     assertEquals(ImmutableList.of(new Text("line1"), new Text("line2")), output);
   }
diff --git a/test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java b/test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java
index 54042e9..abaed73 100644
--- a/test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java
@@ -52,7 +52,6 @@ import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
 import org.apache.accumulo.server.security.AuditedSecurityOperation;
 import org.apache.accumulo.test.functional.ConfigurableMacBase;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.LineIterator;
 import org.apache.hadoop.io.Text;
 import org.junit.After;
 import org.junit.Before;
@@ -133,8 +132,7 @@ public class AuditMessageIT extends ConfigurableMacBase {
     for (File file : files) {
       // We want to grab the files called .out
       if (file.getName().contains(".out") && file.isFile() && file.canRead()) {
-        LineIterator it = FileUtils.lineIterator(file, UTF_8.name());
-        try {
+        try (java.util.Scanner it = new java.util.Scanner(file, UTF_8.name())) {
           while (it.hasNext()) {
             String line = it.nextLine();
             if (line.matches(".* \\[" + AuditedSecurityOperation.AUDITLOG + "\\s*\\].*")) {
@@ -145,8 +143,6 @@ public class AuditMessageIT extends ConfigurableMacBase {
                 result.add(line);
             }
           }
-        } finally {
-          LineIterator.closeQuietly(it);
         }
       }
     }
@@ -330,19 +326,16 @@ public class AuditMessageIT extends ConfigurableMacBase {
     // to re-import it
     File distCpTxt = new File(exportDir.toString() + "/distcp.txt");
     File importFile = null;
-    LineIterator it = FileUtils.lineIterator(distCpTxt, UTF_8.name());
 
     // Just grab the first rf file, it will do for now.
     String filePrefix = "file:";
-    try {
+    try (java.util.Scanner it = new java.util.Scanner(distCpTxt, UTF_8.name())) {
       while (it.hasNext() && importFile == null) {
         String line = it.nextLine();
         if (line.matches(".*\\.rf")) {
           importFile = new File(line.replaceFirst(filePrefix, ""));
         }
       }
-    } finally {
-      LineIterator.closeQuietly(it);
     }
     FileUtils.copyFileToDirectory(importFile, exportDir);
     auditConnector.tableOperations().importTable(NEW_TEST_TABLE_NAME, exportDir.toString());