question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Illegal access on Instant field

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
evanchoolycommented, Dec 19, 2018

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 😃

1reaction
jyemincommented, Dec 19, 2018

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:

Well, IMHO the Morphia should work with Java8 for time being, I think the migration to post8 will take some time here and there. However, it’d be a real pity if in the future modern Morphia wouldn’t work… It should be no big deal for 12, but let’s see what comes next 😉

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MorphiaOrg/morphia/issues/1305#issuecomment-448587625, or mute the thread https://github.com/notifications/unsubscribe-auth/ABD1-tWi_dW2xqNf_vTXIhi7Yk62-BMzks5u6jeugaJpZM4ZaDrC .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Illegal access in Java 16 A.K.A. 'My program crashes!'
The same applies to Instant : IMHO it shouldn't be persisted by walking one private field after another private field. Instead, the code...
Read more >
IllegalAccessError in Java - Baeldung
An IllegalAccessError is thrown when an application attempts to access a field or invoke a method that is inaccessible.
Read more >
classloader - java.lang.IllegalAccessError: tried to access field ...
IllegalAccessError : tried to access field ConcreteEntity.instance from class Entity. Ok so here is the deal. I am trying to access ...
Read more >
IllegalAccessException (Java SE 16 & JDK 16)
An IllegalAccessException is thrown when an application tries to reflectively create an instance (other than an array), set or get a field, ...
Read more >
Illegal warning when starting portal instance on jdk11
Actual result: WARNING: An illegal reflective access operation has ... Field.modifiers WARNING: Please consider reporting this to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found