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

selectOne(…) and event publication fails if entity is null [DATACASS-696] #866

Closed
spring-projects-issues opened this issue Oct 28, 2019 · 3 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 28, 2019

Hurelhuyag opened DATACASS-696 and commented

Some query can return null result. but event source can't be null. 

maybeEmitEvent(new AfterConvertEvent<>(row, result, tableName));

 can't accept null as second parameter.

 

private <T> Function<Row, T> getMapper(Class<?> entityType, Class<T> targetType, CqlIdentifier tableName) {

   Class<?> typeToRead = resolveTypeToRead(entityType, targetType);

   return row -> {

      maybeEmitEvent(new AfterLoadEvent<>(row, targetType, tableName));

      Object source = getConverter().read(typeToRead, row);

      T result = (T) (targetType.isInterface() ? getProjectionFactory().createProjection(targetType, source) : source);

      maybeEmitEvent(new AfterConvertEvent<>(row, result, tableName));

      return result;
   };
}

stack trace:

java.lang.IllegalArgumentException: null sourcejava.lang.IllegalArgumentException: null source at java.base/java.util.EventObject.<init>(EventObject.java:56) ~[na:na] at org.springframework.context.ApplicationEvent.<init>(ApplicationEvent.java:45) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.data.cassandra.core.mapping.event.CassandraMappingEvent.<init>(CassandraMappingEvent.java:43) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.mapping.event.AfterConvertEvent.<init>(AfterConvertEvent.java:43) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.CassandraTemplate.lambda$getMapper$9(CassandraTemplate.java:916) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.CassandraTemplate.lambda$select$0(CassandraTemplate.java:338) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.cql.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:83) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.cql.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:43) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.cql.CqlTemplate.query(CqlTemplate.java:296) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.cql.CqlTemplate.query(CqlTemplate.java:318) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:338) ~[spring-data-cassandra-2.2.0.RELEASE.jar:2.2.0.RELEASE]

sdf


Affects: 2.1.11 (Lovelace SR11), 2.2 GA (Moore)

Backported to: 2.2.1 (Moore SR1), 2.1.12 (Lovelace SR12)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 28, 2019

Mark Paluch commented

Care to describe how a Row can be null? Nullability at EntityReader.read(…) has a higher impact than just guarding this case

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 28, 2019

Hurelhuyag commented

Row is not null but query result is null.

Reproduce steps:

  1. create empty table
  2. run query: select max(column) from mytable
  3. null query result returned because of empty table
  4. exception  thrown because the project used query result as event source 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 28, 2019

Mark Paluch commented

That's fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants