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

When retrieving data from DB Exception thrown with "Null value read for non-null constructor argument" message - after upgrading to Micronaut Parent 4.7.2 #3267

Open
balapal opened this issue Dec 17, 2024 · 12 comments
Assignees
Labels
type: bug Something isn't working

Comments

@balapal
Copy link

balapal commented Dec 17, 2024

Expected Behavior

@MappedEntity should be possible be created with null field values when retrieving data from DB.

Actual Behaviour

When retrieving data from DB Exception thrown with "Null value read for non-null constructor argument" message after upgrading to Micronaut Parent 4.7.2

Stack trace

io.micronaut.data.exceptions.DataAccessException: Null value read for non-null constructor argument [title] of type: micronaut.reproduce.Book
		at io.micronaut.data.runtime.mapper.sql.SqlResultEntityTypeMapper.readEntity(SqlResultEntityTypeMapper.java:541)
		at io.micronaut.data.runtime.mapper.sql.SqlResultEntityTypeMapper$4.processRow(SqlResultEntityTypeMapper.java:376)
		at io.micronaut.data.r2dbc.operations.DefaultR2dbcRepositoryOperations$DefaultR2dbcReactiveRepositoryOperations.lambda$findAll$8(DefaultR2dbcRepositoryOperations.java:544)
		at io.micronaut.data.r2dbc.operations.DefaultR2dbcRepositoryOperations.lambda$executeAndMapEachRow$7(DefaultR2dbcRepositoryOperations.java:451)
		at io.r2dbc.h2.H2Result.lambda$map$1(H2Result.java:103)
		at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106)
		... 52 more

See example at to reproduce the problem at https://github.com/balapal/micronaut-47-null-check-introduced

I downgrade to micronaut-parent 4.7.0, everything works again.

Steps To Reproduce

See the example app to reproduce this issue at https://github.com/balapal/micronaut-47-null-check-introduced

Environment Information

No response

Example Application

https://github.com/balapal/micronaut-47-null-check-introduced

Version

4.7.2

@radovanradic
Copy link
Contributor

Looks like caused by micronaut-core 4.7.6 release @graemerocher and supposedly this PR micronaut-projects/micronaut-core#11347
Adding property <micronaut.core.version>4.7.5</micronaut.core.version> fixes the issue.

@balapal
Copy link
Author

balapal commented Dec 17, 2024

Yeah, It works with micronaut.core.version 4.7.5

I have also tried with micronaut.core.version 4.7.9 to see if micronaut-projects/micronaut-core#11451 fixes it, but it does not

@radovanradic
Copy link
Contributor

radovanradic commented Dec 17, 2024

It gets fixed by annotating title field as @Nullable and adding this to lombok.config

lombok.copyableannotations += io.micronaut.core.annotation.Nullable

So this may not be a bug but configuration issue.

@balapal
Copy link
Author

balapal commented Dec 17, 2024

I did find that "workaround" and it "solves" it, but I don't think it is an elegant or reasonable solution.
I had a POJO with ~15 fields and had to add @Nullable to most of them after a version upgrade (works in 4.7.0, does not work in 4.7.1)

If I don't want a field to allow nulls I add @NotNull and not the other way around.
I think it is not user friendly or straightforward to force the client code to add @Nullable to all fields.

And also it is a not documented regression.

@aoyanb
Copy link

aoyanb commented Dec 18, 2024

@graemerocher
Could you please check this one too!
micronaut-projects/micronaut-core#11432 (comment)

@graemerocher
Copy link
Contributor

I don't think this is related to an upstream change. @radovanradic do you know if we added non-checking somewhere?

@graemerocher graemerocher added the type: bug Something isn't working label Dec 18, 2024
@graemerocher graemerocher moved this to Todo in 4.7.3 Release Dec 18, 2024
@radovanradic
Copy link
Contributor

I don't think there were changes in micronaut-data around this in this release where issue is reported.
Just changing to <micronaut.core.version>4.7.5</micronaut.core.version> which resolves issue made me think it was caused by core changes. As soon as it is updated to 4.7.6+ the issue pops up.

@graemerocher
Copy link
Contributor

ok will investigate

@graemerocher
Copy link
Contributor

I sent a PR for this micronaut-projects/micronaut-core#11481

@graemerocher graemerocher moved this to Ready for Review in 4.7.4 Release Jan 2, 2025
graemerocher added a commit to micronaut-projects/micronaut-core that referenced this issue Jan 3, 2025
…f builder (#11481)

Currently if there is a builder then it is preferred over the constructor. This is a regression from 4.6.x behaviour. This alters the behaviour to prefer the constructor if one is present when returning getConstructorArguments()

Fixes micronaut-projects/micronaut-data#3267
@sdelamo
Copy link
Contributor

sdelamo commented Jan 8, 2025

@graemerocher @radovanradic I have released core 4.7.10.

@graemerocher
Copy link
Contributor

should probably add a downstream test in data once we upgrade

@balapal
Copy link
Author

balapal commented Jan 9, 2025

Hi,
I have upgraded to micronaut-parent 4.7.3 and set the mirconaut-core version to 4.7.11 version and my attached example test works https://github.com/balapal/micronaut-47-null-check-introduced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: Ready for Review
Development

No branches or pull requests

5 participants