[ 
https://issues.apache.org/jira/browse/PHOENIX-7940?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andrew Kyle Purtell updated PHOENIX-7940:
-----------------------------------------
    Description: 
{{PhoenixConnection.getTable(@Nullable String tenantId, String fullTableName, 
@Nullable Long timestamp)}} promises that a {{null}} {{timestamp}} returns the 
latest cached {{PTable}}, falling back to a server lookup on cache miss.

However, when the cache is empty such as on the first call from a 
{{PhoenixConnection}} freshly handed out by the pool and {{timestamp == null}}, 
the JVM with try to auto-unbox the {{Timestamp}} parameter and this will throw 
{{NullPointerException: Cannot invoke
"java.lang.Long.longValue()" because "timestamp" is null}}.

The fix is trivial:

{noformat}
diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -640,7 +640,11 @@ public class PhoenixConnection
         throw new TableNotFoundException(fullTableName);
       }
     } catch (TableNotFoundException e) {
-      table = getTableNoCache(pTenantId, fullTableName, timestamp);
+      if (timestamp == null) {
+        table = getTableNoCache(pTenantId, fullTableName);
+      } else {
+        table = getTableNoCache(pTenantId, fullTableName, timestamp);
+      }
     }
     return table;
   }
{noformat}

  was:
{{PhoenixConnection.getTable(@Nullable String tenantId, String fullTableName, 
@Nullable Long timestamp)}} promises that a {{null}} {{timestamp}} returns the 
latest cached {{PTable}}, falling back to a server lookup on cache miss.

However, when the cache is empty such as on the first call from a 
{{PhoenixConnection}} freshly handed out by the pool and {{timestamp == null}}, 
the JVM with try to auto-unbox the {{Timestamp}} parameter and this will throw 
{{NullPointerException: Cannot invoke
"java.lang.Long.longValue()" because "timestamp" is null}}.

The fix is trivial:

{{noformat}}
diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -640,7 +640,11 @@ public class PhoenixConnection
         throw new TableNotFoundException(fullTableName);
       }
     } catch (TableNotFoundException e) {
-      table = getTableNoCache(pTenantId, fullTableName, timestamp);
+      if (timestamp == null) {
+        table = getTableNoCache(pTenantId, fullTableName);
+      } else {
+        table = getTableNoCache(pTenantId, fullTableName, timestamp);
+      }
     }
     return table;
   }
{{noformat}}


> PhoenixConnection.getTable throws NullPointerException on a cache miss when 
> timestamp is null
> ---------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-7940
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-7940
>             Project: Phoenix
>          Issue Type: Bug
>          Components: core
>            Reporter: Andrew Kyle Purtell
>            Priority: Major
>             Fix For: 5.4.0, 5.3.2
>
>
> {{PhoenixConnection.getTable(@Nullable String tenantId, String fullTableName, 
> @Nullable Long timestamp)}} promises that a {{null}} {{timestamp}} returns 
> the latest cached {{PTable}}, falling back to a server lookup on cache miss.
> However, when the cache is empty such as on the first call from a 
> {{PhoenixConnection}} freshly handed out by the pool and {{timestamp == 
> null}}, the JVM with try to auto-unbox the {{Timestamp}} parameter and this 
> will throw {{NullPointerException: Cannot invoke
> "java.lang.Long.longValue()" because "timestamp" is null}}.
> The fix is trivial:
> {noformat}
> diff --git 
> a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
>  
> b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
> --- 
> a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
> +++ 
> b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
> @@ -640,7 +640,11 @@ public class PhoenixConnection
>          throw new TableNotFoundException(fullTableName);
>        }
>      } catch (TableNotFoundException e) {
> -      table = getTableNoCache(pTenantId, fullTableName, timestamp);
> +      if (timestamp == null) {
> +        table = getTableNoCache(pTenantId, fullTableName);
> +      } else {
> +        table = getTableNoCache(pTenantId, fullTableName, timestamp);
> +      }
>      }
>      return table;
>    }
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to