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 2019/06/13 23:45:39 UTC
[accumulo] branch master updated: Fix #1192 use Charset instead of
String
This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push:
new 8e81e74 Fix #1192 use Charset instead of String
8e81e74 is described below
commit 8e81e744fe8bc6cbef47b747a94a214a7716c4fb
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Thu Jun 13 19:43:56 2019 -0400
Fix #1192 use Charset instead of String
Use Charset type instead of String charset names where appropriate in
the new Java 11 APIs which accept the more strongly typed Charset type.
---
.../core/client/mapreduce/lib/partition/RangePartitioner.java | 2 +-
.../accumulo/core/clientImpl/mapreduce/lib/ConfiguratorBase.java | 2 +-
.../java/org/apache/accumulo/core/conf/ClientConfigGenerate.java | 8 +++-----
.../java/org/apache/accumulo/core/conf/ConfigurationDocGen.java | 8 +++-----
.../java/org/apache/accumulo/core/iterators/user/RegExFilter.java | 4 ++--
.../accumulo/hadoop/mapreduce/partition/RangePartitioner.java | 2 +-
.../accumulo/hadoopImpl/mapreduce/lib/ConfiguratorBase.java | 2 +-
shell/src/main/java/org/apache/accumulo/shell/Shell.java | 2 +-
shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java | 6 +++---
shell/src/main/java/org/apache/accumulo/shell/ShellUtil.java | 8 +++-----
.../java/org/apache/accumulo/shell/commands/ExecfileCommand.java | 2 +-
.../java/org/apache/accumulo/shell/PasswordConverterTest.java | 4 ++--
shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java | 2 +-
test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java | 4 ++--
.../java/org/apache/accumulo/test/replication/StatusMakerIT.java | 2 +-
15 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java
index 1e11178..4eaf4e0 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/partition/RangePartitioner.java
@@ -88,7 +88,7 @@ public class RangePartitioner extends Partitioner<Text,Writable> implements Conf
try (
InputStream inputStream =
DistributedCacheHelper.openCachedFile(cutFileName, CUTFILE_KEY, conf);
- Scanner in = new Scanner(inputStream, UTF_8.name())) {
+ Scanner in = new Scanner(inputStream, UTF_8)) {
while (in.hasNextLine()) {
cutPoints.add(new Text(Base64.getDecoder().decode(in.nextLine())));
}
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/ConfiguratorBase.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/ConfiguratorBase.java
index 82ab4f9..e747951 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/ConfiguratorBase.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/mapreduce/lib/ConfiguratorBase.java
@@ -288,7 +288,7 @@ public class ConfiguratorBase {
try (InputStream inputStream = DistributedCacheHelper.openCachedFile(tokenFile,
cachedTokenFileName(implementingClass), conf)) {
- try (Scanner fileScanner = new Scanner(inputStream, UTF_8.name())) {
+ try (Scanner fileScanner = new Scanner(inputStream, UTF_8)) {
while (fileScanner.hasNextLine()) {
Credentials creds = Credentials.deserialize(fileScanner.nextLine());
if (principal.equals(creds.getPrincipal())) {
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/ClientConfigGenerate.java b/core/src/main/java/org/apache/accumulo/core/conf/ClientConfigGenerate.java
index 55e996f..189c21b 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/ClientConfigGenerate.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/ClientConfigGenerate.java
@@ -18,9 +18,8 @@ package org.apache.accumulo.core.conf;
import static java.nio.charset.StandardCharsets.UTF_8;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
@@ -187,10 +186,9 @@ class ClientConfigGenerate {
* @throws IllegalArgumentException
* if args is invalid
*/
- public static void main(String[] args)
- throws FileNotFoundException, UnsupportedEncodingException {
+ public static void main(String[] args) throws IOException {
if (args.length == 2) {
- try (PrintStream stream = new PrintStream(args[1], UTF_8.name())) {
+ try (PrintStream stream = new PrintStream(args[1], UTF_8)) {
ClientConfigGenerate clientConfigGenerate = new ClientConfigGenerate(stream);
if (args[0].equals("--generate-markdown")) {
clientConfigGenerate.generateMarkdown();
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationDocGen.java b/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationDocGen.java
index 12420df..5ea19d9 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationDocGen.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/ConfigurationDocGen.java
@@ -18,9 +18,8 @@ package org.apache.accumulo.core.conf;
import static java.nio.charset.StandardCharsets.UTF_8;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
import java.util.TreeMap;
/**
@@ -152,10 +151,9 @@ class ConfigurationDocGen {
* @throws IllegalArgumentException
* if args is invalid
*/
- public static void main(String[] args)
- throws FileNotFoundException, UnsupportedEncodingException {
+ public static void main(String[] args) throws IOException {
if (args.length == 2 && args[0].equals("--generate-markdown")) {
- new ConfigurationDocGen(new PrintStream(args[1], UTF_8.name())).generate();
+ new ConfigurationDocGen(new PrintStream(args[1], UTF_8)).generate();
} else {
throw new IllegalArgumentException(
"Usage: " + ConfigurationDocGen.class.getName() + " --generate-markdown <filename>");
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java b/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java
index 2bdcdf3..7b4b2c4 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java
@@ -59,6 +59,8 @@ public class RegExFilter extends Filter {
public static final String ENCODING_DEFAULT = UTF_8.name();
+ private Charset encoding = UTF_8;
+
private Matcher rowMatcher;
private Matcher colfMatcher;
private Matcher colqMatcher;
@@ -66,8 +68,6 @@ public class RegExFilter extends Filter {
private boolean orFields = false;
private boolean matchSubstring = false;
- private Charset encoding = Charset.forName(ENCODING_DEFAULT);
-
private Matcher copyMatcher(Matcher m) {
if (m == null)
return m;
diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoop/mapreduce/partition/RangePartitioner.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoop/mapreduce/partition/RangePartitioner.java
index f0ec055..caf15df 100644
--- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoop/mapreduce/partition/RangePartitioner.java
+++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoop/mapreduce/partition/RangePartitioner.java
@@ -86,7 +86,7 @@ public class RangePartitioner extends Partitioner<Text,Writable> implements Conf
try (
InputStream inputStream =
DistributedCacheHelper.openCachedFile(cutFileName, CUTFILE_KEY, conf);
- Scanner in = new Scanner(inputStream, UTF_8.name())) {
+ Scanner in = new Scanner(inputStream, UTF_8)) {
while (in.hasNextLine()) {
cutPoints.add(new Text(Base64.getDecoder().decode(in.nextLine())));
}
diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/ConfiguratorBase.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/ConfiguratorBase.java
index ad6ad58..92461b0 100644
--- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/ConfiguratorBase.java
+++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/ConfiguratorBase.java
@@ -109,7 +109,7 @@ public class ConfiguratorBase {
cachedClientPropsFileName(implementingClass), conf)) {
StringBuilder sb = new StringBuilder();
- try (Scanner scanner = new Scanner(inputStream, UTF_8.name())) {
+ try (Scanner scanner = new Scanner(inputStream, UTF_8)) {
while (scanner.hasNextLine()) {
sb.append(scanner.nextLine() + "\n");
}
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 74b5ef2..32559cb 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -562,7 +562,7 @@ public class Shell extends ShellOptions implements KeywordExecutable {
ShellCompletor userCompletor = null;
if (execFile != null) {
- try (java.util.Scanner scanner = new java.util.Scanner(execFile, UTF_8.name())) {
+ try (java.util.Scanner scanner = new java.util.Scanner(execFile, UTF_8)) {
while (scanner.hasNextLine() && !hasExited()) {
execCommand(scanner.nextLine(), true, isVerbose());
}
diff --git a/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java b/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
index e428c51..22da578 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
@@ -19,7 +19,7 @@ package org.apache.accumulo.shell;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -62,9 +62,9 @@ public class ShellOptionsJC {
String process(String value) {
Scanner scanner = null;
try {
- scanner = new Scanner(new File(value), UTF_8.name());
+ scanner = new Scanner(new File(value), UTF_8);
return scanner.nextLine();
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
throw new ParameterException(e);
} finally {
if (scanner != null) {
diff --git a/shell/src/main/java/org/apache/accumulo/shell/ShellUtil.java b/shell/src/main/java/org/apache/accumulo/shell/ShellUtil.java
index 6a1e0ee..fa980e4 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/ShellUtil.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/ShellUtil.java
@@ -19,7 +19,7 @@ package org.apache.accumulo.shell;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
@@ -48,15 +48,13 @@ public class ShellUtil {
* @param decode
* Whether to decode lines in the file
* @return List of {@link Text} objects containing data in the given file
- * @throws FileNotFoundException
- * if the given file doesn't exist
*/
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
justification = "app is run in same security context as user providing the filename")
- public static List<Text> scanFile(String filename, boolean decode) throws FileNotFoundException {
+ public static List<Text> scanFile(String filename, boolean decode) throws IOException {
String line;
List<Text> result = new ArrayList<>();
- try (Scanner file = new Scanner(new File(filename), UTF_8.name())) {
+ try (Scanner file = new Scanner(new File(filename), UTF_8)) {
while (file.hasNextLine()) {
line = file.nextLine();
if (!line.isEmpty()) {
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/ExecfileCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/ExecfileCommand.java
index d1df7e6..052ea24 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/ExecfileCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/ExecfileCommand.java
@@ -42,7 +42,7 @@ public class ExecfileCommand extends Command {
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
- try (Scanner scanner = new Scanner(new File(cl.getArgs()[0]), UTF_8.name())) {
+ try (Scanner scanner = new Scanner(new File(cl.getArgs()[0]), UTF_8)) {
while (scanner.hasNextLine()) {
shellState.execCommand(scanner.nextLine(), true, cl.hasOption(verboseOption.getOpt()));
}
diff --git a/shell/src/test/java/org/apache/accumulo/shell/PasswordConverterTest.java b/shell/src/test/java/org/apache/accumulo/shell/PasswordConverterTest.java
index 58f065d..7b8f7e0 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/PasswordConverterTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/PasswordConverterTest.java
@@ -91,9 +91,9 @@ public class PasswordConverterTest {
}
@Test
- public void testFile() throws FileNotFoundException {
+ public void testFile() throws IOException {
argv[1] = "file:pom.xml";
- Scanner scan = new Scanner(new File("pom.xml"), UTF_8.name());
+ Scanner scan = new Scanner(new File("pom.xml"), UTF_8);
String expected = scan.nextLine();
scan.close();
new JCommander(password).parse(argv);
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 50b4648..94c8efa 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellUtilTest.java
@@ -62,7 +62,7 @@ public class ShellUtilTest {
}
@Test(expected = FileNotFoundException.class)
- public void testWithMissingFile() throws FileNotFoundException {
+ public void testWithMissingFile() throws IOException {
ShellUtil.scanFile("missingFile.txt", false);
}
}
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 c2a9b08..6612e06 100644
--- a/test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/AuditMessageIT.java
@@ -120,7 +120,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()) {
- try (java.util.Scanner it = new java.util.Scanner(file, UTF_8.name())) {
+ try (java.util.Scanner it = new java.util.Scanner(file, UTF_8)) {
while (it.hasNext()) {
String line = it.nextLine();
// strip off prefix, because log4j.properties does
@@ -326,7 +326,7 @@ public class AuditMessageIT extends ConfigurableMacBase {
// Just grab the first rf file, it will do for now.
String filePrefix = "file:";
- try (java.util.Scanner it = new java.util.Scanner(distCpTxt, UTF_8.name())) {
+ try (java.util.Scanner it = new java.util.Scanner(distCpTxt, UTF_8)) {
while (it.hasNext() && importFile == null) {
String line = it.nextLine();
if (line.matches(".*\\.rf")) {
diff --git a/test/src/main/java/org/apache/accumulo/test/replication/StatusMakerIT.java b/test/src/main/java/org/apache/accumulo/test/replication/StatusMakerIT.java
index 205f40f..e66fff9 100644
--- a/test/src/main/java/org/apache/accumulo/test/replication/StatusMakerIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/replication/StatusMakerIT.java
@@ -121,7 +121,7 @@ public class StatusMakerIT extends ConfigurableMacBase {
TableId tableId = StatusSection.getTableId(entry.getKey());
assertTrue("Found unexpected file: " + file, files.contains(file.toString()));
- assertEquals(fileToTableId.get(file.toString()), new Integer(tableId.canonical()));
+ assertEquals(fileToTableId.get(file.toString()), Integer.valueOf(tableId.canonical()));
timeCreated = fileToTimeCreated.get(file.toString());
assertNotNull(timeCreated);
assertEquals(StatusUtil.fileCreated(timeCreated), Status.parseFrom(entry.getValue().get()));