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

stoty pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.1 by this push:
     new 09a3da069b PHOENIX-7494 NPE thrown when enable applyTimeZone (#2049)
09a3da069b is described below

commit 09a3da069b7390f78cd455c0c5734b56541f5eef
Author: chaijunjie0101 <[email protected]>
AuthorDate: Fri Jan 10 17:18:07 2025 +0800

    PHOENIX-7494 NPE thrown when enable applyTimeZone (#2049)
---
 .../phoenix/end2end/TimeZoneDisplacementIT.java    | 47 ++++++++++++++++++++++
 .../org/apache/phoenix/jdbc/PhoenixResultSet.java  |  3 ++
 2 files changed, 50 insertions(+)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimeZoneDisplacementIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimeZoneDisplacementIT.java
index 6b50efd43b..5c6c99a90b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimeZoneDisplacementIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TimeZoneDisplacementIT.java
@@ -33,6 +33,7 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.DateUtil;
 import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -296,4 +297,50 @@ public class TimeZoneDisplacementIT extends 
ParallelStatsEnabledIT {
                 rs.getString("ROWTS"));
         }
     }
+
+    @Test
+    public void testGetObjectWithNullValue() throws Exception {
+        String tableName = generateUniqueName();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.put(QueryServices.APPLY_TIME_ZONE_DISPLACMENT_ATTRIB, 
Boolean.TRUE.toString());
+        try (PhoenixConnection conn =
+                     (PhoenixConnection) DriverManager.getConnection(getUrl(), 
props)) {
+            conn.setAutoCommit(true);
+            try (Statement stmt = conn.createStatement()) {
+                stmt.execute("CREATE TABLE " + tableName +
+                        " (ID INTEGER PRIMARY KEY, D1 DATE)");
+            }
+
+            String dateString = "2025-01-01 10:00:00";
+            try (PreparedStatement insertPstmt = conn.prepareStatement("UPSERT 
INTO " + tableName +
+                    " (ID, D1) values" + " (?, ?) ")) {
+                insertPstmt.setInt(1, 1);
+                insertPstmt.setString(2, dateString);
+                insertPstmt.executeUpdate();
+
+                insertPstmt.setInt(1, 2);
+                insertPstmt.setString(2, null);
+                insertPstmt.executeUpdate();
+            }
+
+            PreparedStatement queryPstmt = conn.prepareStatement("SELECT * 
FROM "
+                    + tableName + " WHERE ID = ?");
+            ResultSet resultSet;
+            try {
+                queryPstmt.setInt(1, 1);
+                resultSet = queryPstmt.executeQuery();
+                Assert.assertTrue(resultSet.next());
+                Assert.assertNotNull(resultSet.getObject("D1"));
+
+                queryPstmt.setInt(1, 2);
+                resultSet = queryPstmt.executeQuery();
+                Assert.assertTrue(resultSet.next());
+                Assert.assertNull(resultSet.getObject("D1"));
+            } finally {
+                if (queryPstmt != null) {
+                    queryPstmt.close();
+                }
+            }
+        }
+    }
 }
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java 
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
index 0ebfc5720e..506c54f910 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixResultSet.java
@@ -589,6 +589,9 @@ public class PhoenixResultSet implements ResultSet, 
SQLCloseable {
         ColumnProjector projector = 
getRowProjector().getColumnProjector(columnIndex - 1);
         Object value = projector.getValue(currentRow, 
projector.getExpression().getDataType(), ptr);
         wasNull = (value == null);
+        if (wasNull) {
+            return null;
+        }
         if (isApplyTimeZoneDisplacement) {
             PDataType type = projector.getExpression().getDataType();
             if (type == PDate.INSTANCE || type == PUnsignedDate.INSTANCE) {

Reply via email to