Skip to content

NullPointerException in MongoPersistentEntityIndexResolver.appendTextIndexInformation(…) #3901

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
caspianb opened this issue Dec 6, 2021 · 4 comments
Assignees
Labels
status: feedback-provided Feedback has been provided type: regression A regression from a previous release

Comments

@caspianb
Copy link

caspianb commented Dec 6, 2021

Since upgrading to 2.6.1 I am seeing failures when invoking IndexResolver::resolveIndexFor(...) for some specific entities.

We have a generic pattern using javax.measure classes using an enum which implements an interface defined in this way:

public interface Uom<T extends javax.measure.Quantity.Quantity<T>> {
   javax.measure.Unit.Unit<T> getUnit();
}

public enum UomLength implements Uom<javax.measure.quantity.Length>{
   ...
}

// This is the embedded object type we actually persist.
public class UomMeasure<T extends Uom...> {
   T unit; // the enums are stored here
}

Pre 2.6, index resolution worked just fine on entities containing this object. However, after upgrading to 2.6.1 I get a NullPointerException with the following stack trace (Note: I can "fix" the issue by marking getUnit() as @transient which is an acceptable work-around for our use case -- the persistence mechanism still persists the enum via its string properly and we do not use the annotation based index resolution pattern most of the time).

When I debug into the code and view the state at the time of the NPE I see this:

entity = mappingContext.getPersistentEntity(persistentProperty.getActualType());
persistentProperty.getActualType() -> Integer.class
entity == null
java.lang.NullPointerException
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$100(MongoPersistentEntityIndexResolver.java:78)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:370)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:360)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$100(MongoPersistentEntityIndexResolver.java:78)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:370)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:360)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$100(MongoPersistentEntityIndexResolver.java:78)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:370)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:360)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$100(MongoPersistentEntityIndexResolver.java:78)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:370)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:360)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.access$100(MongoPersistentEntityIndexResolver.java:78)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:370)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$1.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:360)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.appendTextIndexInformation(MongoPersistentEntityIndexResolver.java:338)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.potentiallyCreateTextIndexDefinition(MongoPersistentEntityIndexResolver.java:314)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.resolveIndexForEntity(MongoPersistentEntityIndexResolver.java:128)
	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.resolveIndexFor(MongoPersistentEntityIndexResolver.java:103)
	at org.springframework.data.mongodb.core.index.IndexResolver.resolveIndexFor(IndexResolver.java:69)
	at com.blueyonder.lof.bedrock.tenancy.mongo.SpringMongoContextDatabaseInitializer.lambda$execute$4(SpringMongoContextDatabaseInitializer.java:57)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 6, 2021
@christophstrobl
Copy link
Member

Thanks for reporting! We'll have a look.

@christophstrobl christophstrobl added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 13, 2021
@christophstrobl christophstrobl self-assigned this Dec 13, 2021
@christophstrobl
Copy link
Member

I might be missing something here, but I was not able to reproduce the issue. Could you please provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Dec 17, 2021
@caspianb
Copy link
Author

caspianb commented Dec 17, 2021

Thanks for looking into it!

I have attached a sample here:
mongo-index-npe.zip

On 2.5.7 there is no NPE (but I did notice a warning around a cyclic reference inside the underlying javax.measure implementation). However, the only thing actually persisted there is our enum (which is the desired behavior). Everything works fine outside of just the NPE on startup when upgrading to 2.6.1.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 17, 2021
@christophstrobl
Copy link
Member

Thanks for the sample! I can see now that there's a Map structure involved that should not be traversed. There's already a PR (#3915) available that is related to this issue.

@mp911de mp911de changed the title NullPointerException - MongoPersistentEntityIndexResolver.java:338 NullPointerException in MongoPersistentEntityIndexResolver.appendTextIndexInformation(…) Jan 12, 2022
@mp911de mp911de added this to the 3.3.1 (2021.1.1) milestone Jan 12, 2022
mp911de pushed a commit that referenced this issue Jan 12, 2022
This commit makes sure to exclude Map like structures from index inspection unless annotated with WilcardIndexed.

Closes #3914, closes #3901
Original pull request: #3915.
mp911de added a commit that referenced this issue Jan 12, 2022
Reformat code. Tweak documentation wording and callout syntax.

See #3914, see #3901
Original pull request: #3915.
mp911de added a commit that referenced this issue Jan 12, 2022
Reformat code. Tweak documentation wording and callout syntax.

See #3914, see #3901
Original pull request: #3915.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants