Illegal access on Instant field
See original GitHub issueHi
So basically I have an entity, which in turn has a field of type java.time.Instant.
Morphia has a converter for this type, xyz.morphia.converters.InstantConverter
.
When running the app in Java9+ (11 to be precise) with --illegal-access=deny
, the app crashes, because during discovery performed by Datastore.ensureIndexes(EntityWithInstantField.class)
, in xyz.morphia.mapping.MappedClass#discover
Morphia tries to set internal field (seconds) of Instant to be accessible.
In the new module philosophy, this is deprecated and AFAICT will be removed in the future, to have nice and clean cross-module dependencies.
The exact exception is:
An exception was caught and reported. Message: java.lang.reflect.InaccessibleObjectException: Unable to make field private final long java.time.Instant.seconds accessible: module java.base does not "opens java.time" to unnamed module @2617f816
So, if there’s a registered codec for a class from an external module of which we don’t have control, shouldn’t Morphia skip discovering/accessing it using reflection?
BTW. I don’t think any advice like “just permit the access” will hold in the future. While it works now, it may stop working in the future. (Mind that Thread.stop()
finally got removed, just as EE modules.)
Any hints how this could be implemented, so I could give it a try?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (11 by maintainers)
good to know. i have a 2.x branch already reasonably modernized. I’m working on removing warts from morphia’s API atm to make it easier to maintain going forward. I’m hoping i’ll be done before 2019H2 😃
Hey Justin,
Regarding Java 8 vs 11 as a minimum requirement, I’d lean towards 8. External surveys and our own (MongoDB’s) data show that Java 8 is still the most widely adopted version, and Java 8 will be the minimum requirement for the upcoming 4.0 Java driver.
Regards, Jeff Yemin
On Wed, Dec 19, 2018 at 7:57 AM pioorg notifications@github.com wrote: