Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1636262: getDate triggers NPE with 3.18.0 (regression) #1874

Closed
jnd77 opened this issue Aug 22, 2024 · 6 comments
Closed

SNOW-1636262: getDate triggers NPE with 3.18.0 (regression) #1874

jnd77 opened this issue Aug 22, 2024 · 6 comments
Assignees
Labels
bug status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. status-triage_done Initial triage done, will be further handled by the driver team

Comments

@jnd77
Copy link

jnd77 commented Aug 22, 2024

  1. What version of JDBC driver are you using?

3.18.0

  1. What operating system and processor architecture are you using?

Linux

  1. What version of Java are you using?

Java 17

  1. What did you do?
import static org.assertj.core.api.Assertions.assertThat;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.LocalDate;
import java.util.List;
import java.util.Properties;
import net.snowflake.client.core.SFSessionProperty;
import net.snowflake.client.jdbc.SnowflakeResultSet;
import net.snowflake.client.jdbc.SnowflakeResultSetSerializable;
import org.junit.jupiter.api.Test;

public class SnowflakeSplitTest {

	@Test
	void testReadDateAfterSplittingResultSet() throws Exception {
		Properties props = new Properties();
		props.put(SFSessionProperty.PASSWORD, getPassword());
		props.put(SFSessionProperty.WAREHOUSE, TEST_WAREHOUSE);
		props.put(SFSessionProperty.DATABASE, TEST_DATABASE_NAME);
		props.put(SFSessionProperty.SCHEMA, TEST_SCHEMA_NAME);
		Connection conn = DriverManager.getConnection(TEST_CONNECTION_STRING, props);
		try (Statement statement = conn.createStatement()) {
			statement.execute(
					"create or replace table table_with_date (int_c int, date_c date)");
			statement.execute(
					"insert into table_with_date values (1, '2015-10-25')");

			try (ResultSet rs = statement.executeQuery("select * from table_with_date")) {
				final SnowflakeResultSet resultSet = rs.unwrap(SnowflakeResultSet.class);
				final List<SnowflakeResultSetSerializable> serializables = resultSet.getResultSetSerializables(1<<20);
				final List<Date> dates = serializables.stream().map(s -> {
					try {
						return s.getResultSet().getDate(2);
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}).toList();
				assertThat(dates).containsExactly(Date.valueOf(LocalDate.of(2015, 10, 25)));
			}
		}
	}
}

  1. What did you expect to see?

    I would expect the test to pass (like with version 3.17.0) , but it fails with NPE.
    This is due to the change in this PR:

2843788#diff-7cfeb1bc1d98b12948358aee582bf563cd540c249b1771257214e573df0eab8e

Some constructors leave session null ...

@jnd77 jnd77 added the bug label Aug 22, 2024
@github-actions github-actions bot changed the title getDate triggers NPE with 3.18.0 (regression) SNOW-1636262: getDate triggers NPE with 3.18.0 (regression) Aug 22, 2024
@sfc-gh-sghosh sfc-gh-sghosh self-assigned this Aug 26, 2024
@sfc-gh-sghosh sfc-gh-sghosh added the status-triage Issue is under initial triage label Aug 26, 2024
@sfc-gh-sghosh
Copy link
Contributor

Hello @jnd77 ,

Thanks for raising the issue; we are checking and will update you.

Regards,
Sujan

@sfc-gh-jszczerbinski sfc-gh-jszczerbinski self-assigned this Aug 26, 2024
@sfc-gh-sghosh
Copy link
Contributor

Hello @jnd77 ,

We are able to reproduce the issue with 3.18.0, we will work on eliminating it.

ResultSet rs = stmt.executeQuery("select * from table_with_date");

       final SnowflakeResultSet resultSet = rs.unwrap(SnowflakeResultSet.class);
       final List<SnowflakeResultSetSerializable> serializables = resultSet.getResultSetSerializables(1 << 20);

       final List<Date> dates = serializables.stream().map(s -> {
           try {
              
               Date date_= s.getResultSet().getDate(2);
               System.out.println(date_);
               return date_;
           } catch (Exception e) {
               throw new RuntimeException(e);
           }
       }).collect(Collectors.toList());  // Correctly collect the Stream into a List

Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "net.snowflake.client.core.SFBaseSession.getGetDateUseNullTimezone()" because "this.session" is null
   at sample_con_getDate.lambda$0(sample_con_getDate.java:91)
   at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
   at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
   at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
   at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
   at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
   at sample_con_getDate.Query(sample_con_getDate.java:93)
   at sample_con_getDate.main(sample_con_getDate.java:32)
Caused by: java.lang.NullPointerException: Cannot invoke "net.snowflake.client.core.SFBaseSession.getGetDateUseNullTimezone()" because "this.session" is null
   at net.snowflake.client.jdbc.SnowflakeBaseResultSet.getDate(SnowflakeBaseResultSet.java:139)
   at sample_con_getDate.lambda$0(sample_con_getDate.java:87)
   ... 9 more

Regards,
Sujan

@sfc-gh-sghosh sfc-gh-sghosh added status-triage_done Initial triage done, will be further handled by the driver team and removed status-triage Issue is under initial triage labels Aug 29, 2024
@sfc-gh-jszczerbinski
Copy link
Contributor

Fixed in: #1877

@sfc-gh-dszmolka sfc-gh-dszmolka added the status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. label Aug 29, 2024
@sfc-gh-jszczerbinski
Copy link
Contributor

sfc-gh-jszczerbinski commented Aug 29, 2024

The fix will be released today 🤞 in version 3.19

@sfc-gh-dszmolka
Copy link
Contributor

Released with JDBC v3.19.0 in August 2024 release cycle

@jnd77
Copy link
Author

jnd77 commented Sep 2, 2024

Thanks a lot guys for the quick fix and release. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status-fixed_awaiting_release The issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector. status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

4 participants