Skip to content

NullPointerException when inserting entity with read only fields #354

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

Closed
ljrmorgan opened this issue Apr 22, 2020 · 3 comments
Closed

NullPointerException when inserting entity with read only fields #354

ljrmorgan opened this issue Apr 22, 2020 · 3 comments
Labels
type: bug A general bug

Comments

@ljrmorgan
Copy link
Contributor

I have an entity with a field annotated with@ReadOnlyProperty. When trying to save an entity of that type to my database I get a NullPointerException:

Suppressed: java.lang.NullPointerException
		at org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy.shouldConvertArrayValue(DefaultReactiveDataAccessStrategy.java:225)
		at org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy.getOutboundRow(DefaultReactiveDataAccessStrategy.java:209)
		at org.springframework.data.r2dbc.core.DefaultDatabaseClient$DefaultTypedInsertSpec.exchange(DefaultDatabaseClient.java:1171)
		at org.springframework.data.r2dbc.core.DefaultDatabaseClient$DefaultTypedInsertSpec.access$1300(DefaultDatabaseClient.java:1067)
		at org.springframework.data.r2dbc.core.DefaultDatabaseClient$DefaultTypedInsertSpec$1.lambda$first$1(DefaultDatabaseClient.java:1153)
		at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:151)
		... 85 more

The issue seems to be that the MappingR2dbcConverter does correctly skip read only properties when writing properties to the OutboundRow, but DefaultReactiveDataAccessStrategy#getOutboundRow does not skip read only properties when retrieving the SettableValues from the OutboundRow.

@ljrmorgan
Copy link
Contributor Author

I'm intending to open a PR shortly that addresses this

@ljrmorgan
Copy link
Contributor Author

On further investigation the issue is specifically because the property is considered "collection like" (my field is a byte[]). DefaultReactiveDataAccessStrategy#shouldConvertArrayValue dereferences value even though in this case it is null. Non collection properties are not impacted because that method returns early if property.isCollectionLike() returns true

mp911de pushed a commit that referenced this issue Apr 23, 2020
Previously a NullPointerException would be thrown.

Original pull request: #355.
@mp911de mp911de added this to the 1.1 RC2 (Neumann) milestone Apr 23, 2020
mp911de added a commit that referenced this issue Apr 23, 2020
Add author tags. Reformat code.

Original pull request: #355.
@mp911de mp911de added the type: bug A general bug label Apr 23, 2020
@mp911de
Copy link
Member

mp911de commented Apr 23, 2020

Thanks a lot. The fix is merged.

@mp911de mp911de closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants