-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Document with LocalDateTime field doesn't work in Java 17 #4237
Comments
I might be missing something here. A fresh boot |
Hi @christophstrobl , |
@vikas-singh-maersk do you have a minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem at hand? |
Hi @christophstrobl , |
Hi, @christophstrobl I also faced the kind of issue reported in this ticket, when trying to update a project to Spring Boot 3+. Here is a minimal sample to reproduce the crash: https://github.com/christophe-michard/MongoSetAccessibleIssue. Important part: @SpringBootApplication
public class MongoSetAccessibleIssueApplication {
public static void main(String[] args) {
SpringApplication.run(MongoSetAccessibleIssueApplication.class, args);
}
public MongoSetAccessibleIssueApplication() {
// Create a custom mongoTemplate
// Crash happens only if we create a template with the mappingMongoConverter as second argument
MongoDatabaseFactory mongoDbFactory = new SimpleMongoClientDatabaseFactory(MongoClients.create(), "db");
MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), new MongoMappingContext());
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, mappingMongoConverter);
// Crash happens when this line is executed
mongoTemplate.save(new MongoEntity());
}
}
class MongoEntity {
// We need a field that is a class from java.time package, for instance Instant, to provoke a crash.
// Background: https://mail.openjdk.org/pipermail/jdk9-dev/2016-November/005276.html
// Crash sample:
// Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make private java.time.Instant(long,int) accessible: module java.base does not "opens java.time" to unnamed module @1afd44cb
// at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
// at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
// at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188) ~[na:na]
// at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181) ~[na:na]
// at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:201) ~[spring-core-6.0.9.jar:6.0.9]
// at org.springframework.data.mapping.PreferredConstructor.<init>(PreferredConstructor.java:56) ~[spring-data-commons-3.1.0.jar:3.1.0]
public Instant createdDateTime;
} Is it enough for you to be able to investigate on the issue? 😃 |
@christophe-michard thanks for the reproducer! |
@christophstrobl We are using this kind of configuration to remove the autogenerated _class field, and automatically create indexes on application start. |
I need to revisit |
@christophe-michard you may also want to try it this way: MongoMappingContext mappingContext = new MongoMappingContext();
MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), mappingContext);
mappingContext.setSimpleTypeHolder(mappingMongoConverter.getCustomConversions().getSimpleTypeHolder());
mappingContext.afterPropertiesSet();
mappingMongoConverter.afterPropertiesSet(); |
@christophstrobl Thank you very much! 😄 mappingContext.setAutoIndexCreation(true);
mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null)); Now, the application stops at Solr initialization, so I will need to update solr-solrj library, and replace spring-data-solr by a custom bootstrap I guess, since it won't support Spring Boot 3 due to end of life reached. |
We have the same issue
hence all java.time.* classes |
@christophstrobl's snippet did resolve my problem. |
Hello, we also ran into this issue. We configure 2 instances of The solutions we followed led us to this issue, and @christophstrobl's snippet seems to have resolved our issue as well. It seems this issue is > 1 year old now, is there any other more updated fix? edit: Sorry, after commenting I see maybe a linked issue (spring-projects/spring-data-keyvalue#569) is waiting to be picked up and related. |
Follow-up from last year: our system has been updated successfully, and has been working fine since. |
Migrated very simple java application from Java 11 to Java 17. Have singe Document
And getting issue on start up
Obviously related to this change - https://openjdk.org/jeps/396
If I remove LocalDateTime field - it starts without issue.
The text was updated successfully, but these errors were encountered: