-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG] NPE when reading the resulting object after SimpleCosmosRepository.save #43755
Comments
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar @pjohari-ms @TheovanKraay. |
@trande4884 can you please take a look at this issue, thanks! |
@G0dC0der can you please put the line of code fully as to how you are calling save and then where you are trying to retrieve the item where it throws the error? Thanks! |
@G0dC0der whatever the entity type you are saving should be the return type of the .save(), you shouldn't need to call .getItem() I believe, below you can see how save() can be used and the response is the item:
|
It's the call to the save method that yields a NPE. I use it exactly as you do in your example. I of course populate the fields of the entity before I dod that. @Container(containerName = "organization")
public final class OrganizationEntity {
@Id
@PartitionKey
@JsonProperty("id")
private String databaseName;
private Integer organizationNumber;
private String contactPersonEmail;
private String contactPersonPhone;
private AccessLevel accessLevel;
private String bucket;
@Version
private String _etag;
//Getters and setters
}
@Repository
public interface OrganizationRepository extends CosmosRepository<OrganizationEntity, String> {
@Override @NotNull List<OrganizationEntity> findAll();
}
//Somehwere in a method:
organizationRepository.save(organizationEntity); //NPE: Cannot invoke "com.fasterxml.jackson.databind.JsonNode.isValueNode()" because "jsonNode" is null Full stacktrace
The last line of this stacktrace is my own code, and it calls OrganizationRepository.save(object), as seen in the line above: |
Describe the bug
I have a repository class:
And I am calling the
save
method, defined inorg.springframework.data.repository.CrudRepository
. This results in a call toSimpleCosmosRepository
, and eventuallyCosmosTemplate.upsertAndReturnEntity
. This method(upsertAndReturnEntity
) does mainly two things:save
).The first part works fine, but the second part yields null pointer exeception, because
CosmosItemResponse.getItem()
returns null. This is not surprising, because theCosmosItemRequestOptions
used does not setcontentResponseOnWriteEnabled
totrue
.Exception or Stack Trace
To Reproduce
Extend the interface CosmosRepository with your own, and save any object using using
save(object)
.Code Snippet
Expected behavior
I expect to get an object of OrganizationEntity and not a NPE.
Screenshots
n/a
Setup (please complete the following information):
Question
Is there something I am not understanding? I feel like this shouldn't happen, but at the same time, I have a hard time believing this was missed during testing.
Additional Info
This is where the problem lies:
https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/spring/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/CosmosTemplate.java#L537
If you put a breakpoint, and edit
options
to havecontentResponseOnWriteEnabled
set totrue
, the problem get solved.Workaround
I can use the save method defined in CosmosRepository, where we can customise the options. However, this is verbose and inconvenient. I. think
CosmosTemplate.upsertAndReturnEntity
should always setcontentResponseOnWriteEnabled
totrue
.Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
The text was updated successfully, but these errors were encountered: