sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2449: Sqoop2: Findbugs: Fix smaller-ish warnings in common module
Date Wed, 12 Aug 2015 19:50:38 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 22dba9a85 -> 5b691c2b1


SQOOP-2449: Sqoop2: Findbugs: Fix smaller-ish warnings in common module

(Jarek Jarcec Cecho via Abraham Elmahrek)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/5b691c2b
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/5b691c2b
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/5b691c2b

Branch: refs/heads/sqoop2
Commit: 5b691c2b1059ac0e15f32438d49a8826b3470155
Parents: 22dba9a
Author: Abraham Elmahrek <abe@apache.org>
Authored: Wed Aug 12 12:50:06 2015 -0700
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Wed Aug 12 12:50:06 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/sqoop/common/MapContext.java |  6 +++---
 .../apache/sqoop/common/MutableMapContext.java   |  2 +-
 .../apache/sqoop/common/SupportedDirections.java | 19 +++++++++++++++++++
 .../json/util/ConfigInputSerialization.java      |  6 +++++-
 .../sqoop/json/util/SchemaSerialization.java     |  3 ++-
 .../java/org/apache/sqoop/model/ConfigUtils.java |  5 ++---
 .../apache/sqoop/model/MAccountableEntity.java   |  2 +-
 .../main/java/org/apache/sqoop/model/MJob.java   | 12 ++++++++++++
 .../main/java/org/apache/sqoop/model/MLink.java  |  7 +++++++
 .../java/org/apache/sqoop/model/MLinkConfig.java |  9 ---------
 .../java/org/apache/sqoop/model/MSubmission.java |  2 +-
 .../validation/validators/CSVURIValidator.java   |  4 +++-
 12 files changed, 56 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/common/MapContext.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/common/MapContext.java b/common/src/main/java/org/apache/sqoop/common/MapContext.java
index abf5634..a0cc660 100644
--- a/common/src/main/java/org/apache/sqoop/common/MapContext.java
+++ b/common/src/main/java/org/apache/sqoop/common/MapContext.java
@@ -110,9 +110,9 @@ public class MapContext implements ImmutableContext {
    */
   public Map<String, String> getNestedProperties(String prefix) {
     Map<String, String> subProps = new HashMap<String, String>();
-    for (String key : options.keySet()) {
-      if (key.startsWith(prefix)) {
-        subProps.put(key.substring(prefix.length()), options.get(key));
+    for(Map.Entry<String, String> entry : options.entrySet()) {
+      if(entry.getKey().startsWith(prefix)) {
+        subProps.put(entry.getKey().substring(prefix.length()), entry.getKey());
       }
     }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java b/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
index 61751bf..59c520c 100644
--- a/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
+++ b/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
@@ -29,7 +29,7 @@ import java.util.Map;
  */
 @InterfaceAudience.Public
 @InterfaceStability.Unstable
-public class MutableMapContext extends MapContext implements Iterable<Map.Entry<String,
String>>, MutableContext {
+public class MutableMapContext extends MapContext implements MutableContext {
 
   public MutableMapContext(Map<String, String> options) {
     super(options);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/common/SupportedDirections.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/common/SupportedDirections.java b/common/src/main/java/org/apache/sqoop/common/SupportedDirections.java
index 2fae427..b5e9884 100644
--- a/common/src/main/java/org/apache/sqoop/common/SupportedDirections.java
+++ b/common/src/main/java/org/apache/sqoop/common/SupportedDirections.java
@@ -120,4 +120,23 @@ public class SupportedDirections implements Comparable<SupportedDirections>
{
 
     return hash - oHash;
   }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SupportedDirections that = (SupportedDirections) o;
+
+    if (from != that.from) return false;
+    return to == that.to;
+
+  }
+
+  @Override
+  public int hashCode() {
+    int result = (from ? 1 : 0);
+    result = 31 * result + (to ? 1 : 0);
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
b/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
index 1b1ec28..0d40715 100644
--- a/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
+++ b/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
@@ -188,7 +188,11 @@ public final class ConfigInputSerialization {
       }
 
       // Propagate config ID
-      mInput.setPersistenceId((Long)input.get(ConfigInputConstants.INPUT_ID));
+      Long id = (Long)input.get(ConfigInputConstants.INPUT_ID);
+      if(id == null) {
+        throw new SqoopException(SerializationError.SERIALIZATION_002, "Missing field: "
+ ConfigInputConstants.INPUT_ID);
+      }
+      mInput.setPersistenceId(id);
 
       // Propagate config optional value
       if(input.containsKey(ConfigInputConstants.CONFIG_INPUT_VALUE)) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/json/util/SchemaSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/util/SchemaSerialization.java b/common/src/main/java/org/apache/sqoop/json/util/SchemaSerialization.java
index 21fad35..1fa5743 100644
--- a/common/src/main/java/org/apache/sqoop/json/util/SchemaSerialization.java
+++ b/common/src/main/java/org/apache/sqoop/json/util/SchemaSerialization.java
@@ -21,6 +21,7 @@ import java.util.HashSet;
 
 import org.apache.sqoop.classification.InterfaceAudience;
 import org.apache.sqoop.classification.InterfaceStability;
+import org.apache.sqoop.common.SqoopException;
 import org.apache.sqoop.schema.NullSchema;
 import org.apache.sqoop.schema.Schema;
 import org.apache.sqoop.schema.type.AbstractComplexListType;
@@ -278,7 +279,7 @@ public class SchemaSerialization {
       output = new Unknown(name).setJdbcType(jdbcType);
       break;
     default:
-      // TODO(Jarcec): Throw an exception of unsupported type?
+      throw new SqoopException(SerializationError.SERIALIZATION_002, "Invalid type: " + type);
     }
     output.setNullable(nullable);
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java b/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
index 72565c7..52e7ef6 100644
--- a/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
+++ b/common/src/main/java/org/apache/sqoop/model/ConfigUtils.java
@@ -473,14 +473,13 @@ public class  ConfigUtils {
 
     for(Field configField : klass.getDeclaredFields()) {
       configField.setAccessible(true);
-      String configName = configField.getName();
 
       // We're processing only config validations
       Config configAnnotation = configField.getAnnotation(Config.class);
       if(configAnnotation == null) {
         continue;
       }
-      configName = getConfigName(configField, configAnnotation, configNames);
+      String configName = getConfigName(configField, configAnnotation, configNames);
 
       try {
         configField.set(configuration, configField.getType().newInstance());
@@ -533,7 +532,7 @@ public class  ConfigUtils {
           } else if(type == Integer.class) {
             inputField.set(configValue, ((Long)jsonInputs.get(inputName)).intValue());
           } else if(type == Long.class) {
-            inputField.set(configValue, ((Long)jsonInputs.get(inputName)).longValue());
+            inputField.set(configValue, ((Long)jsonInputs.get(inputName)));
           } else if(type.isEnum()) {
             inputField.set(configValue, Enum.valueOf((Class<? extends Enum>) inputField.getType(),
(String) jsonInputs.get(inputName)));
           } else if(type == Boolean.class) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java b/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java
index a2ec587..2cbe67c 100644
--- a/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java
+++ b/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java
@@ -30,7 +30,7 @@ import java.util.Date;
 @InterfaceStability.Unstable
 abstract public class MAccountableEntity extends MValidatedElement {
 
-  private final boolean DEFAULT_ENABLED = true;
+  private static final boolean DEFAULT_ENABLED = true;
 
   /**
    * The user who creates the entity

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/model/MJob.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MJob.java b/common/src/main/java/org/apache/sqoop/model/MJob.java
index 260b9cd..4be020a 100644
--- a/common/src/main/java/org/apache/sqoop/model/MJob.java
+++ b/common/src/main/java/org/apache/sqoop/model/MJob.java
@@ -181,4 +181,16 @@ public class MJob extends MAccountableEntity implements MClonable {
         && (job.getToJobConfig().equals(this.getToJobConfig()))
         && (job.getDriverConfig().equals(this.driverConfig));
   }
+
+  @Override
+  public int hashCode() {
+    int result = (int) (fromConnectorId ^ (fromConnectorId >>> 32));
+    result = 31 * result + (int) (toConnectorId ^ (toConnectorId >>> 32));
+    result = 31 * result + (int) (fromLinkId ^ (fromLinkId >>> 32));
+    result = 31 * result + (int) (toLinkId ^ (toLinkId >>> 32));
+    result = 31 * result + (fromConfig != null ? fromConfig.hashCode() : 0);
+    result = 31 * result + (toConfig != null ? toConfig.hashCode() : 0);
+    result = 31 * result + (driverConfig != null ? driverConfig.hashCode() : 0);
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/model/MLink.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MLink.java b/common/src/main/java/org/apache/sqoop/model/MLink.java
index 01ff5df..51a4008 100644
--- a/common/src/main/java/org/apache/sqoop/model/MLink.java
+++ b/common/src/main/java/org/apache/sqoop/model/MLink.java
@@ -109,4 +109,11 @@ public class MLink extends MAccountableEntity implements MClonable {
         && (mLink.getPersistenceId() == this.getPersistenceId())
         && (mLink.connectorLinkConfig.equals(this.connectorLinkConfig));
     }
+
+  @Override
+  public int hashCode() {
+    int result = (int) (connectorId ^ (connectorId >>> 32));
+    result = 31 * result + (connectorLinkConfig != null ? connectorLinkConfig.hashCode()
: 0);
+    return result;
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/model/MLinkConfig.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MLinkConfig.java b/common/src/main/java/org/apache/sqoop/model/MLinkConfig.java
index 9042ca5..6b33fdc 100644
--- a/common/src/main/java/org/apache/sqoop/model/MLinkConfig.java
+++ b/common/src/main/java/org/apache/sqoop/model/MLinkConfig.java
@@ -43,15 +43,6 @@ public class MLinkConfig extends MConfigList {
   }
 
   @Override
-  public boolean equals(Object other) {
-    if (other == this) {
-      return true;
-    }
-
-    return super.equals(other);
-  }
-
-  @Override
   public MLinkConfig clone(boolean cloneWithValue) {
     MLinkConfig copy = new MLinkConfig(super.clone(cloneWithValue).getConfigs());
     return copy;

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/model/MSubmission.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MSubmission.java b/common/src/main/java/org/apache/sqoop/model/MSubmission.java
index eb90f9a..11110ae 100644
--- a/common/src/main/java/org/apache/sqoop/model/MSubmission.java
+++ b/common/src/main/java/org/apache/sqoop/model/MSubmission.java
@@ -252,6 +252,6 @@ public class MSubmission extends MAccountableEntity {
         + ", error=" + error + ", fromSchema=" + fromSchema + ", toSchema=" + toSchema +
"]";
   }
 
-  public static MSubmission UNKNOWN = new MSubmission();
+  public final static MSubmission UNKNOWN = new MSubmission();
 
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/5b691c2b/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
b/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
index 1bef4e7..12d348f 100644
--- a/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
+++ b/common/src/main/java/org/apache/sqoop/validation/validators/CSVURIValidator.java
@@ -17,6 +17,8 @@
  */
 package org.apache.sqoop.validation.validators;
 
+import com.google.common.base.Strings;
+import org.apache.commons.lang.StringUtils;
 import org.apache.sqoop.classification.InterfaceAudience;
 import org.apache.sqoop.classification.InterfaceStability;
 import org.apache.sqoop.validation.Status;
@@ -31,7 +33,7 @@ public class CSVURIValidator extends AbstractValidator<String> {
   // validate that given string is a comma-separated list of host:port
   @Override
   public void validate(String str) {
-    if(str != null && str != "") {
+    if(!Strings.isNullOrEmpty(str)) {
       String[] pairs = str.split("\\s*,\\s*");
       for (String pair: pairs) {
         String[] parts = pair.split("\\s*:\\s*");


Mime
View raw message