We're updating the issue view to help you get more done. 

Mapping with @Field @IndexedEmbedded Integer[] field throws InaccessibleObjectException

Description

When we find an @IndexedEmbedded, we use introspection to find out exactly what is "embedded". This makes sense, since @IndexedEmbedded is about embedding stuff, right?
Well, not always. The @IndexedEmbedded annotation has another meaning: when there is a @Field on the annotated property, we actually use it to tell Hibernate Search to wrap the field bridge in a "container" field bridge (see ). This is especially useful when one wants to index a list or array of simple values, such as String or Integer for instance.
Since we cannot distinguish between the two use cases, we end up always using introspection on the element type, even if the element type is something like java.lang.Integer.

This is fine in JDK8 and below, but starting from JDK9 such things are prevented by module isolation: you can't use setAccessible outside of your own module unless explicitly allowed to, and thus you can't inspect private members by default.

Stack trace:

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 40 41 42 Tests run: 12, Failures: 0, Errors: 12, Skipped: 0, Time elapsed: 0.169 sec <<< FAILURE! - in org.hibernate.search.test.sorting.SortingTest testSortingOnNumericInt(org.hibernate.search.test.sorting.SortingTest) Time elapsed: 0.053 sec <<< ERROR! java.lang.reflect.InaccessibleObjectException: Unable to make field private final int java.lang.Integer.value accessible: module java.base does not "opens java.lang" to unnamed module @7d1f3fe9 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:335) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:278) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:175) at java.base/java.lang.reflect.Field.setAccessible(Field.java:169) at org.hibernate.annotations.common.reflection.java.JavaXMember.setAccessible(JavaXMember.java:121) at org.hibernate.search.util.impl.ReflectionHelper.setAccessible(ReflectionHelper.java:59) at org.hibernate.search.engine.metadata.impl.PropertyMetadata$Builder.<init>(PropertyMetadata.java:129) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:1022) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:600) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.checkForIndexedEmbedded(AnnotationMetadataProvider.java:1847) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeMemberLevelAnnotations(AnnotationMetadataProvider.java:1040) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.initializeClass(AnnotationMetadataProvider.java:600) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.doGetTypeMetadataFor(AnnotationMetadataProvider.java:174) at org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.getTypeMetadataFor(AnnotationMetadataProvider.java:164) at org.hibernate.search.spi.SearchIntegratorBuilder.initDocumentBuilders(SearchIntegratorBuilder.java:441) at org.hibernate.search.spi.SearchIntegratorBuilder.createNewFactoryState(SearchIntegratorBuilder.java:237) at org.hibernate.search.spi.SearchIntegratorBuilder.buildNewSearchFactory(SearchIntegratorBuilder.java:193) at org.hibernate.search.spi.SearchIntegratorBuilder.buildSearchIntegrator(SearchIntegratorBuilder.java:122) at org.hibernate.search.testsupport.junit.SearchFactoryHolder.createSearchFactory(SearchFactoryHolder.java:92) at org.hibernate.search.testsupport.junit.SearchFactoryHolder.before(SearchFactoryHolder.java:73) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46) at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

Environment

JDK 9

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Affects versions

5.8.0.Beta1

Priority

Major