Skip to content

java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Optional(java.lang.Object) accessible: module java.base does not "opens java.util" to unnamed module @16f7c8c1 #2706

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
martinchen911 opened this issue Sep 22, 2023 · 3 comments · Fixed by #2707
Labels
type: bug A general bug

Comments

@martinchen911
Copy link

martinchen911 commented Sep 22, 2023

When I try to save object List<Range> using ElasticSearch, I get the following error, but there is no problem saving object Range

java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Optional(java.lang.Object) accessible: module java.base does not "opens java.util" to unnamed module @16f7c8c1
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188)
	at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181)
	at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:201)
	at org.springframework.data.mapping.PreferredConstructor.<init>(PreferredConstructor.java:53)
	at org.springframework.data.mapping.model.PreferredConstructorDiscoverer$Discoverers.buildPreferredConstructor(PreferredConstructorDiscoverer.java:250)
	at org.springframework.data.mapping.model.PreferredConstructorDiscoverer$Discoverers$1.discover(PreferredConstructorDiscoverer.java:137)
	at org.springframework.data.mapping.model.PreferredConstructorDiscoverer.discover(PreferredConstructorDiscoverer.java:82)
	at org.springframework.data.mapping.model.InstanceCreatorMetadataDiscoverer.discover(InstanceCreatorMetadataDiscoverer.java:81)
	at org.springframework.data.mapping.model.BasicPersistentEntity.<init>(BasicPersistentEntity.java:113)
	at org.springframework.data.mapping.model.BasicPersistentEntity.<init>(BasicPersistentEntity.java:94)
	at org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchPersistentEntity.<init>(SimpleElasticsearchPersistentEntity.java:88)
	at org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext.createPersistentEntity(SimpleElasticsearchMappingContext.java:70)
	at org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext.createPersistentEntity(SimpleElasticsearchMappingContext.java:34)
	at org.springframework.data.mapping.context.AbstractMappingContext.doAddPersistentEntity(AbstractMappingContext.java:403)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:379)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:280)
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:92)
	at org.springframework.data.mapping.context.MappingContext.getRequiredPersistentEntity(MappingContext.java:114)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeProperty(MappingElasticsearchConverter.java:1022)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeProperties(MappingElasticsearchConverter.java:975)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeInternal(MappingElasticsearchConverter.java:837)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeProperty(MappingElasticsearchConverter.java:1029)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeProperties(MappingElasticsearchConverter.java:975)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeInternal(MappingElasticsearchConverter.java:837)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeInternal(MappingElasticsearchConverter.java:815)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeCollectionInternal(MappingElasticsearchConverter.java:929)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.createCollection(MappingElasticsearchConverter.java:1149)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeProperty(MappingElasticsearchConverter.java:1000)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeProperties(MappingElasticsearchConverter.java:975)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeInternal(MappingElasticsearchConverter.java:837)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.writeInternal(MappingElasticsearchConverter.java:815)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter$Writer.write(MappingElasticsearchConverter.java:773)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.write(MappingElasticsearchConverter.java:180)
	at org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter.write(MappingElasticsearchConverter.java:93)
	at org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter.mapObject(ElasticsearchConverter.java:87)
	at org.springframework.data.elasticsearch.client.elc.RequestConverter.documentIndexRequest(RequestConverter.java:466)
	at org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate.doIndex(ElasticsearchTemplate.java:211)
	at org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate.save(AbstractElasticsearchTemplate.java:204)
	at org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate.save(AbstractElasticsearchTemplate.java:192)```



Operating environment:
Java 17
spring boot 3.0.4
spring-data-elasticsearch 5.0.3
spring-boot-starter-data-elasticsearch 3.0.4

`@Field(type = FieldType.Date_Range, format = DateFormat.hour_minute)
private Range<LocalTime> openingHourList;`

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 22, 2023
@sothawo
Copy link
Collaborator

sothawo commented Sep 22, 2023

Please provide a minimal reproducer project that shows this error.

@martinchen911
Copy link
Author

请提供一个显示此错误的最小重现器项目。

https://github.com/martinchen911/spring-date-elasticsearch-exception-demo

@sothawo
Copy link
Collaborator

sothawo commented Sep 22, 2023

Thank you.
This seems to be a bug in analyzing the entity's properties. The Range type is not detected correctly, as it is wrapped in a List. This then causes the Range not being converted correctly into the Elasticsearch representation.

@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 22, 2023
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Sep 22, 2023
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Sep 23, 2023
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Sep 23, 2023
sothawo added a commit that referenced this issue Sep 23, 2023
Original Pull Request #2707
Closes #2706
@sothawo sothawo added this to the 5.2 RC1 (2023.1.0) milestone Sep 23, 2023
sothawo added a commit that referenced this issue Sep 23, 2023
Original Pull Request #2707
Closes #2706

(cherry picked from commit 3330d65)
sothawo added a commit that referenced this issue Sep 23, 2023
Original Pull Request #2707
Closes #2706

(cherry picked from commit 3330d65)
(cherry picked from commit d26d01b)
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.

3 participants