Reporting errors about duplicate fields fails with an AssertionFailure when field is declared by a class bridge or class-level @Spatial

Description

Affects 5.6.6 for sure, and probably all 5.x versions after 5.6.0. Does not affect 6.x: fields are contributed differently and we already have a specific test for duplicate fields.

See https://discourse.hibernate.org/t/caused-by-org-hibernate-search-exception-assertionfailure-a-reference-has-been-accessed-before-having-been-initialized/2570

The problem is that, when there is a duplicate field contributed by a class bridge or class-level @Spatial annotation, we call documentFieldMetadata.getSourceType().getType() in org.hibernate.search.engine.metadata.impl.TypeMetadata#buildFieldMetadataMap, which is called in the constructor of TypeMetadata and thus before the back-reference is initialized, so it fails.

We should find another way to get the information than calling documentFieldMetadata.getSourceType().getType().

And yeah... there should be a test.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 Caused by: org.hibernate.search.exception.AssertionFailure: A reference has been accessed before having been initialized. at org.hibernate.search.engine.metadata.impl.BackReference.get(BackReference.java:42) at org.hibernate.search.engine.metadata.impl.DocumentFieldMetadata.getSourceType(DocumentFieldMetadata.java:87) at org.hibernate.search.engine.metadata.impl.TypeMetadata.buildFieldMetadataMap(TypeMetadata.java:445) at org.hibernate.search.engine.metadata.impl.TypeMetadata.<init>(TypeMetadata.java:183) at org.hibernate.search.engine.metadata.impl.TypeMetadata$Builder.build(TypeMetadata.java:655) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.doGetTypeMetadataFor(AnnotationMetadataProvider.java:184) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataForContainedIn(AnnotationMetadataProvider.java:152) at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:346) at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:202) at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:120) at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:75) at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:35) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:540) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:423) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:880) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384) ... 86 more

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Affects versions

5.7.3.Final
5.6.6.Final
5.9.3.Final
5.8.2.Final
5.11.1.Final
5.10.5.Final

Priority

Minor
Configure