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

NullPointerException thrown when native query returns 1 row, 1 column and the value is null #769

Closed
LucaFornelli opened this issue Oct 14, 2020 · 1 comment · Fixed by #771
Labels
status: pr submitted A pull request has been submitted for the issue type: bug Something isn't working

Comments

@LucaFornelli
Copy link

Description

In one of our repository classes, the query expects a String as result type, but it might occasionally return null value.
When this happens a NullPointerException is thrown instead of the expected empty Optional.

Steps to Reproduce

with this repository:

package default

import io.micronaut.data.annotation.Query
import io.micronaut.data.jdbc.annotation.JdbcRepository
import io.micronaut.data.model.query.builder.sql.Dialect
import io.micronaut.data.repository.GenericRepository

@JdbcRepository(dialect = Dialect.MYSQL)
abstract class NullTestRepository implements GenericRepository<String, Long> {

    @Query("select null")
    abstract Optional<String> somethingThatMightSometimesReturnNull()
}

When calling somethingThatMightSometimesReturnNull() a null pointer exception is thrown here:
https://github.com/micronaut-projects/micronaut-data/blob/master/data-runtime/src/main/java/io/micronaut/data/runtime/mapper/ResultReader.java#L50

Since the value is null, calling the .getClass() method will thrown a NullPointerException

Expected Behaviour

When a null value is the result of a query, an empty Optional should be returned.

Actual Behaviour

When a null value is the result of a query, a NullPointerException is thrown.

Environment Information

  • Operating System: MacOS 10.15.7
  • Micronaut Version: 1.3.6
  • Micronaut Data Version: 1.1.0 (also happening in version 1.1.3)
  • JDK Version: 1.8
@graemerocher
Copy link
Contributor

PR submitted for this #767

@graemerocher graemerocher added status: pr submitted A pull request has been submitted for the issue type: bug Something isn't working labels Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pr submitted A pull request has been submitted for the issue type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants