sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-2515: Sqoop2: Findbugs: Fix warning in common module
Date Thu, 20 Aug 2015 16:00:41 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 c1e4fbd5e -> 7f7862895


SQOOP-2515: Sqoop2: Findbugs: Fix warning in common module

(Colin Ma via Jarek Jarcec Cecho)


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

Branch: refs/heads/sqoop2
Commit: 7f78628955a1c7e39a895f6af12384f32f1b5f75
Parents: c1e4fbd
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Thu Aug 20 08:59:55 2015 -0700
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Thu Aug 20 09:00:30 2015 -0700

----------------------------------------------------------------------
 .../apache/sqoop/json/ValidationResultBean.java |  5 ++++-
 .../java/org/apache/sqoop/json/VersionBean.java |  5 ++++-
 .../apache/sqoop/model/MAccountableEntity.java  | 22 ++++++++++++++++----
 .../java/org/apache/sqoop/model/MConnector.java |  8 +++----
 .../java/org/apache/sqoop/model/MDriver.java    |  3 +--
 .../java/org/apache/sqoop/model/MEnumInput.java | 11 ++++++++--
 .../java/org/apache/sqoop/model/MPrincipal.java |  4 +++-
 .../java/org/apache/sqoop/model/MPrivilege.java |  4 +++-
 .../java/org/apache/sqoop/model/MResource.java  |  4 +++-
 .../java/org/apache/sqoop/schema/Schema.java    | 11 ++++++++--
 .../java/org/apache/sqoop/utils/ClassUtils.java |  6 +++---
 .../org/apache/sqoop/utils/TestClassUtils.java  |  2 +-
 12 files changed, 62 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/json/ValidationResultBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/ValidationResultBean.java b/common/src/main/java/org/apache/sqoop/json/ValidationResultBean.java
index 4ac9533..7dfd9fc 100644
--- a/common/src/main/java/org/apache/sqoop/json/ValidationResultBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/ValidationResultBean.java
@@ -54,7 +54,10 @@ public class ValidationResultBean implements JsonBean {
   }
 
   public ConfigValidationResult[] getValidationResults() {
-    return results;
+    if (results == null) {
+      return new ConfigValidationResult[]{};
+    }
+    return results.clone();
   }
 
   public void setId(Long id) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/json/VersionBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/VersionBean.java b/common/src/main/java/org/apache/sqoop/json/VersionBean.java
index 3746ca4..c43d944 100644
--- a/common/src/main/java/org/apache/sqoop/json/VersionBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/VersionBean.java
@@ -109,7 +109,10 @@ public class VersionBean implements JsonBean {
   }
 
   public String[] getSupportedAPIVersions() {
-    return this.supportedRestAPIVersions;
+    if (supportedRestAPIVersions == null) {
+      return new String[]{};
+    }
+    return supportedRestAPIVersions.clone();
   }
 
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/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 2cbe67c..8fc744a 100644
--- a/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java
+++ b/common/src/main/java/org/apache/sqoop/model/MAccountableEntity.java
@@ -95,11 +95,18 @@ abstract public class MAccountableEntity extends MValidatedElement {
   }
 
   public void setCreationDate(Date createDate) {
-    this.creationDate = createDate;
+    if (createDate != null) {
+      this.creationDate = new Date(createDate.getTime());
+    } else {
+      this.creationDate = null;
+    }
   }
 
   public Date getCreationDate() {
-    return creationDate;
+    if (creationDate != null) {
+      return new Date(creationDate.getTime());
+    }
+    return null;
   }
 
   public void setLastUpdateUser(String name) {
@@ -111,11 +118,18 @@ abstract public class MAccountableEntity extends MValidatedElement {
   }
 
   public void setLastUpdateDate(Date lastUpdateDate) {
-    this.lastUpdateDate = lastUpdateDate;
+    if (lastUpdateDate != null) {
+      this.lastUpdateDate = new Date(lastUpdateDate.getTime());
+    } else {
+      this.lastUpdateDate = null;
+    }
   }
 
   public Date getLastUpdateDate() {
-    return lastUpdateDate;
+    if (lastUpdateDate != null) {
+      return new Date(lastUpdateDate.getTime());
+    }
+    return null;
   }
 
   public void setEnabled(boolean enable) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/model/MConnector.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MConnector.java b/common/src/main/java/org/apache/sqoop/model/MConnector.java
index cd41bc3..7c22f29 100644
--- a/common/src/main/java/org/apache/sqoop/model/MConnector.java
+++ b/common/src/main/java/org/apache/sqoop/model/MConnector.java
@@ -137,21 +137,21 @@ public final class MConnector extends Configurable {
 
   public MConnector clone(boolean cloneWithValue) {
     // Connector never have any values filled
-    cloneWithValue = false;
+    boolean isCloneWithValue = false;
 
     MFromConfig fromConfig = this.getFromConfig();
     MToConfig toConfig = this.getToConfig();
 
     if (fromConfig != null) {
-      fromConfig = fromConfig.clone(cloneWithValue);
+      fromConfig = fromConfig.clone(isCloneWithValue);
     }
 
     if (toConfig != null) {
-      toConfig = toConfig.clone(cloneWithValue);
+      toConfig = toConfig.clone(isCloneWithValue);
     }
 
     MConnector copy = new MConnector(this.getUniqueName(), this.getClassName(), this.getVersion(),
-        this.getLinkConfig().clone(cloneWithValue), fromConfig, toConfig);
+        this.getLinkConfig().clone(isCloneWithValue), fromConfig, toConfig);
     copy.setPersistenceId(this.getPersistenceId());
     return copy;
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/model/MDriver.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MDriver.java b/common/src/main/java/org/apache/sqoop/model/MDriver.java
index 75eaa46..74a7fc3 100644
--- a/common/src/main/java/org/apache/sqoop/model/MDriver.java
+++ b/common/src/main/java/org/apache/sqoop/model/MDriver.java
@@ -85,8 +85,7 @@ public final class MDriver extends Configurable {
 
   @Override
   public MDriver clone(boolean cloneWithValue) {
-    cloneWithValue = false;
-    MDriver copy = new MDriver(this.driverConfig.clone(cloneWithValue), this.version);
+    MDriver copy = new MDriver(this.driverConfig.clone(false), this.version);
     copy.setPersistenceId(this.getPersistenceId());
     return copy;
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/model/MEnumInput.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MEnumInput.java b/common/src/main/java/org/apache/sqoop/model/MEnumInput.java
index e630536..df702f8 100644
--- a/common/src/main/java/org/apache/sqoop/model/MEnumInput.java
+++ b/common/src/main/java/org/apache/sqoop/model/MEnumInput.java
@@ -38,11 +38,18 @@ public class MEnumInput extends MInput<String> {
 
   public MEnumInput(String name, boolean sensitive, InputEditable editable, String overrides,
String[] values) {
     super(name, sensitive, editable, overrides);
-    this.values = values;
+    if (values != null) {
+      this.values = values.clone();
+    } else {
+      this.values = null;
+    }
   }
 
   public String[] getValues() {
-    return values;
+    if (values != null) {
+      return values.clone();
+    }
+    return new String[]{};
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/model/MPrincipal.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MPrincipal.java b/common/src/main/java/org/apache/sqoop/model/MPrincipal.java
index 1fbf971..e4f46fd 100644
--- a/common/src/main/java/org/apache/sqoop/model/MPrincipal.java
+++ b/common/src/main/java/org/apache/sqoop/model/MPrincipal.java
@@ -17,6 +17,8 @@
  */
 package org.apache.sqoop.model;
 
+import java.util.Locale;
+
 /**
  * Model describing entire principal object which used in principal based authorization controller
  */
@@ -50,7 +52,7 @@ public class MPrincipal {
    */
   public MPrincipal(String name,
                     String typeName) {
-    this(name, TYPE.valueOf(typeName.toUpperCase()));
+    this(name, TYPE.valueOf(typeName.toUpperCase(Locale.getDefault())));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/model/MPrivilege.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MPrivilege.java b/common/src/main/java/org/apache/sqoop/model/MPrivilege.java
index e10f094..da4ec14 100644
--- a/common/src/main/java/org/apache/sqoop/model/MPrivilege.java
+++ b/common/src/main/java/org/apache/sqoop/model/MPrivilege.java
@@ -17,6 +17,8 @@
  */
 package org.apache.sqoop.model;
 
+import java.util.Locale;
+
 /**
  * Model describing entire privilege object which used in privilege based authorization controller
  */
@@ -57,7 +59,7 @@ public class MPrivilege {
   public MPrivilege(MResource resource,
                     String actionName,
                     boolean with_grant_option) {
-    this(resource, ACTION.valueOf(actionName.toUpperCase()), with_grant_option);
+    this(resource, ACTION.valueOf(actionName.toUpperCase(Locale.getDefault())), with_grant_option);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/model/MResource.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MResource.java b/common/src/main/java/org/apache/sqoop/model/MResource.java
index 1185e48..e573ec9 100644
--- a/common/src/main/java/org/apache/sqoop/model/MResource.java
+++ b/common/src/main/java/org/apache/sqoop/model/MResource.java
@@ -17,6 +17,8 @@
  */
 package org.apache.sqoop.model;
 
+import java.util.Locale;
+
 /**
  * Model describing entire resource object which used in resource based authorization controller
  */
@@ -50,7 +52,7 @@ public class MResource {
    */
   public MResource(String name,
                    String typeName) {
-    this(name, TYPE.valueOf(typeName.toUpperCase()));
+    this(name, TYPE.valueOf(typeName.toUpperCase(Locale.getDefault())));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/schema/Schema.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/schema/Schema.java b/common/src/main/java/org/apache/sqoop/schema/Schema.java
index 1520300..ca865ea 100644
--- a/common/src/main/java/org/apache/sqoop/schema/Schema.java
+++ b/common/src/main/java/org/apache/sqoop/schema/Schema.java
@@ -116,7 +116,10 @@ public class Schema {
   }
 
   public Date getCreationDate() {
-    return creationDate;
+    if (creationDate != null) {
+      return new Date(creationDate.getTime());
+    }
+    return null;
   }
 
   public String getNote() {
@@ -129,7 +132,11 @@ public class Schema {
   }
 
   public Schema setCreationDate(Date creationDate) {
-    this.creationDate = creationDate;
+    if (creationDate != null) {
+      this.creationDate = new Date(creationDate.getTime());
+    } else {
+      this.creationDate = null;
+    }
     return this;
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/main/java/org/apache/sqoop/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/utils/ClassUtils.java b/common/src/main/java/org/apache/sqoop/utils/ClassUtils.java
index 523dd19..6262802 100644
--- a/common/src/main/java/org/apache/sqoop/utils/ClassUtils.java
+++ b/common/src/main/java/org/apache/sqoop/utils/ClassUtils.java
@@ -145,7 +145,7 @@ public final class ClassUtils {
    */
   public static String[] getEnumStrings(Class klass) {
     if(!klass.isEnum()) {
-      return null;
+      return new String[]{};
     }
 
     ArrayList<String> values = new ArrayList<String>();
@@ -156,9 +156,9 @@ public final class ClassUtils {
       for(Object constant : klass.getEnumConstants()) {
         values.add((String) methodName.invoke(constant));
       }
-    } catch (Exception e) {
+    } catch (RuntimeException|NoSuchMethodException|IllegalAccessException|InvocationTargetException
e) {
       LOG.error("Can't get list of values from enumeration " + klass.getCanonicalName(),
e);
-      return null;
+      return new String[]{};
     }
 
     return values.toArray(new String[values.size()]);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/7f786289/common/src/test/java/org/apache/sqoop/utils/TestClassUtils.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/utils/TestClassUtils.java b/common/src/test/java/org/apache/sqoop/utils/TestClassUtils.java
index 986b878..4126e7b 100644
--- a/common/src/test/java/org/apache/sqoop/utils/TestClassUtils.java
+++ b/common/src/test/java/org/apache/sqoop/utils/TestClassUtils.java
@@ -114,7 +114,7 @@ public class TestClassUtils {
 
   @Test
   public void testGetEnumStrings() {
-    assertNull(ClassUtils.getEnumStrings(A.class));
+    assertEquals(new String[]{}, ClassUtils.getEnumStrings(A.class));
 
     assertEquals(
             new String[]{"A", "B", "C"},


Mime
View raw message