You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by mw...@apache.org on 2019/02/14 19:04:40 UTC
[accumulo] branch master updated: Fix minor code quality issues
(#960)
This is an automated email from the ASF dual-hosted git repository.
mwalch 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 c966961 Fix minor code quality issues (#960)
c966961 is described below
commit c9669613a0b463e449a07dea01d8e24ca7995e5b
Author: Mike Walch <mw...@apache.org>
AuthorDate: Thu Feb 14 14:04:35 2019 -0500
Fix minor code quality issues (#960)
* Use Objects.requireNonNull rather than nonNull
* Close stream
* Set clientProps correctly if using mini in Proxy
---
.../accumulo/core/conf/ClientConfigGenerate.java | 21 +++++++++++----------
.../main/java/org/apache/accumulo/proxy/Proxy.java | 15 +++++----------
.../server/constraints/MetadataConstraints.java | 2 +-
.../main/java/org/apache/accumulo/shell/Shell.java | 2 +-
4 files changed, 18 insertions(+), 22 deletions(-)
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 ebdfb03..55e996f 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
@@ -102,7 +102,7 @@ class ClientConfigGenerate {
@Override
void property(ClientProperty prop) {
- Objects.nonNull(prop);
+ Objects.requireNonNull(prop);
doc.print("| <a name=\"" + prop.getKey().replace(".", "_") + "\" class=\"prop\"></a> "
+ prop.getKey() + " | ");
String defaultValue = sanitize(prop.getDefaultValue()).trim();
@@ -163,7 +163,7 @@ class ClientConfigGenerate {
private final TreeMap<String,ClientProperty> sortedProps = new TreeMap<>();
private ClientConfigGenerate(PrintStream doc) {
- Objects.nonNull(doc);
+ Objects.requireNonNull(doc);
this.doc = doc;
for (ClientProperty prop : ClientProperty.values()) {
this.sortedProps.put(prop.getKey(), prop);
@@ -190,14 +190,15 @@ class ClientConfigGenerate {
public static void main(String[] args)
throws FileNotFoundException, UnsupportedEncodingException {
if (args.length == 2) {
- ClientConfigGenerate clientConfigGenerate = new ClientConfigGenerate(
- new PrintStream(args[1], UTF_8.name()));
- if (args[0].equals("--generate-markdown")) {
- clientConfigGenerate.generateMarkdown();
- return;
- } else if (args[0].equals("--generate-config")) {
- clientConfigGenerate.generateConfigFile();
- return;
+ try (PrintStream stream = new PrintStream(args[1], UTF_8.name())) {
+ ClientConfigGenerate clientConfigGenerate = new ClientConfigGenerate(stream);
+ if (args[0].equals("--generate-markdown")) {
+ clientConfigGenerate.generateMarkdown();
+ return;
+ } else if (args[0].equals("--generate-config")) {
+ clientConfigGenerate.generateConfigFile();
+ return;
+ }
}
}
throw new IllegalArgumentException("Usage: " + ClientConfigGenerate.class.getName()
diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java b/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
index 27da6a1..d5ef5cb 100644
--- a/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
+++ b/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
@@ -136,12 +136,6 @@ public class Proxy implements KeywordExecutable {
boolean useMini = Boolean
.parseBoolean(proxyProps.getProperty(USE_MINI_ACCUMULO_KEY, USE_MINI_ACCUMULO_DEFAULT));
- if (!useMini && clientProps == null) {
- System.err.println("The '-c' option must be set with an accumulo-client.properties file or"
- + " proxy.properties must contain either useMiniAccumulo=true");
- System.exit(1);
- }
-
if (!proxyProps.containsKey("port")) {
System.err.println("No port property");
System.exit(1);
@@ -152,10 +146,7 @@ public class Proxy implements KeywordExecutable {
final File folder = Files.createTempDirectory(System.currentTimeMillis() + "").toFile();
final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(folder, "secret");
accumulo.start();
- clientProps.setProperty(ClientProperty.INSTANCE_NAME.getKey(),
- accumulo.getConfig().getInstanceName());
- clientProps.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(),
- accumulo.getZooKeepers());
+ clientProps = accumulo.getClientProperties();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void start() {
@@ -169,6 +160,10 @@ public class Proxy implements KeywordExecutable {
}
}
});
+ } else if (clientProps == null) {
+ System.err.println("The '-c' option must be set with an accumulo-client.properties file or"
+ + " proxy.properties must contain either useMiniAccumulo=true");
+ System.exit(1);
}
Class<? extends TProtocolFactory> protoFactoryClass = Class
diff --git a/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java b/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
index 7de61d1..64182e8 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java
@@ -298,7 +298,7 @@ public class MetadataConstraints implements Constraint {
}
protected Arbitrator getArbitrator(ServerContext context) {
- Objects.nonNull(context);
+ Objects.requireNonNull(context);
return new ZooArbitrator(context);
}
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 a63b43f..58aeac4 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -657,7 +657,7 @@ public class Shell extends ShellOptions implements KeywordExecutable {
}
public String getDefaultPrompt() {
- Objects.nonNull(accumuloClient);
+ Objects.requireNonNull(accumuloClient);
ClientInfo info = ClientInfo.from(accumuloClient.properties());
return accumuloClient.whoami() + "@" + info.getInstanceName()
+ (getTableName().isEmpty() ? "" : " ") + getTableName() + "> ";