You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by mi...@apache.org on 2019/11/07 06:32:07 UTC

[phoenix] branch 4.x-HBase-1.3 updated: PHOENIX-5557 Prevent String comparison using ==

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

mihir6692 pushed a commit to branch 4.x-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.3 by this push:
     new 57c88d6  PHOENIX-5557 Prevent String comparison using ==
57c88d6 is described below

commit 57c88d6bd6074ecfc6b74566c73e3a7b9367ead3
Author: Viraj Jasani <vi...@gmail.com>
AuthorDate: Thu Nov 7 12:00:12 2019 +0530

    PHOENIX-5557 Prevent String comparison using ==
---
 .../src/main/java/org/apache/phoenix/schema/SequenceKey.java   | 10 ++++++++--
 .../src/main/java/org/apache/phoenix/util/UpgradeUtil.java     |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceKey.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceKey.java
index 6f82630..f83fc04 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceKey.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/SequenceKey.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.schema;
 
+import java.util.Objects;
+
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.util.ByteUtil;
@@ -56,9 +58,13 @@ public class SequenceKey implements Comparable<SequenceKey> {
 
     @Override
     public int compareTo(SequenceKey that) {
-        int c = this.tenantId == that.getTenantId() ? 0 : this.tenantId == null ? -1 : that.getTenantId() == null ? 1 : this.tenantId.compareTo(that.getTenantId());
+        int c = Objects.equals(this.tenantId, that.getTenantId()) ? 0
+          : this.tenantId == null ? -1 : that.getTenantId() == null ? 1
+          : this.tenantId.compareTo(that.getTenantId());
         if (c == 0) {
-            c = this.schemaName == that.getSchemaName() ? 0 : this.schemaName == null ? -1 : that.getSchemaName() == null ? 1 : this.schemaName.compareTo(that.getSchemaName());
+            c = Objects.equals(this.schemaName, that.getSchemaName()) ? 0
+              : this.schemaName == null ? -1 : that.getSchemaName() == null ? 1
+              : this.schemaName.compareTo(that.getSchemaName());
             if (c == 0) {
                 return sequenceName.compareTo(that.getSequenceName());
             }
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
index 254f78e..fe05aca 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java
@@ -1198,7 +1198,7 @@ public class UpgradeUtil {
 			props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(HConstants.LATEST_TIMESTAMP));
             while (rs.next()) {
             	String tenantId = rs.getString("TENANT_ID");
-				if (prevTenantId != tenantId) {
+				if (!java.util.Objects.equals(prevTenantId, tenantId)) {
 					prevTenantId = tenantId;
 					props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
             		metaConn = new PhoenixConnection(oldMetaConnection, props); 
@@ -2291,7 +2291,7 @@ public class UpgradeUtil {
         for (TableInfo viewInfo : viewInfoList) {
             tenantId = viewInfo.getTenantId()!=null ? Bytes.toString(viewInfo.getTenantId()) : null;
             String viewName = SchemaUtil.getTableName(viewInfo.getSchemaName(), viewInfo.getTableName());
-            if (prevTenantId != tenantId) {
+            if (!java.util.Objects.equals(prevTenantId, tenantId)) {
                 if (tenantId != null) {
                     props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
                 } else {