Skip to content

Error in running the zerocode tests in JDK23/21 #704

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

Open
mailtoach79 opened this issue Apr 8, 2025 · 8 comments
Open

Error in running the zerocode tests in JDK23/21 #704

mailtoach79 opened this issue Apr 8, 2025 · 8 comments

Comments

@mailtoach79
Copy link

mailtoach79 commented Apr 8, 2025

Observed the following error in running the tests in higher version of JDK(21.0.6 and JDK(23.0.1).

Appreciate if anyone can provide the fix.

Image

@thanasissot
Copy link
Collaborator

thanasissot commented Apr 20, 2025

first timer trying to work on contributing. can I get the assignment?

can I get more info?

Tests are failing with JDK21,23 when lower JDKs are all successful?

@authorjapps
Copy link
Owner

authorjapps commented Apr 20, 2025

Tests are failing with JDK21,23 when lower JDKs are all successful?

@thanasissot , lower lower JDKs are all successful. This is very much evident from the latest CI builds.

You can have a look at the last CI runs here.
Also have a look at the POM file here (Line No. 100 and 101).

<java-compiler-source.version>1.8</java-compiler-source.version>
<java-compiler-target.version>1.8</java-compiler-target.version>

Let me know if you think you can still proceed with the fix, then we can assign the issue to you.

@rkampani
Copy link
Collaborator

Is anyone currently working on this issue? If not, I'd be happy to take it on

@authorjapps
Copy link
Owner

Is anyone currently working on this issue? If not, I'd be happy to take it on

Hello @rkampani , noone seems picked up yet.

Thanks for your interest. Assigned to you now. You can proceed please.

My suggestion would be to try it locally first, once you get an idea of the problem and the fix, then raise a PR with changing the Java version here(Line No.20).

@thanasissot
Copy link
Collaborator

@rkampani I tried messing around a little bit, but eventually never replied in the thread.

One thing I found trying to research on a random error from using JDK 21 and running mvn test is that it comes from mockito-core which is used by the juckito dependency for tests.

I tried updating mockito-core through dependency management and the specific error I was looking into was fixed.
(juckito has no more releases so an upgrade not possible)
The problem with this approach was that I noticed not all tests run with the previous mockito-core version was executed using the latest version. This complicates things (a lot I guess)?.

I assume the requirement is to only use a newer JDK to build, run and pass all tests - don't update the projects source code version used aka 1.8 -> 21.

@authorjapps I would love some info/discussion/feedback on this - even a short answer. This is a valuable experience for me even If I don't get to practically contribute.

@rkampani Does my approach sound a good start? What is your strategy for approaching this issue? Again I would appreciate knowledge sharing for experience.

@authorjapps
Copy link
Owner

Thanks @thanasissot, Great findings.

(juckito has no more releases so an upgrade not possible)

This is interesting. Can we use another library?
Then get rid of "juckito"!

We should have the Test coverage, than using "juckito" :)

rkampani added a commit to rkampani/zerocode that referenced this issue Apr 28, 2025
@rkampani
Copy link
Collaborator

rkampani commented Apr 28, 2025

Hey @thanasissot, thanks! AFAIK, You were spot on —The issue stems from changes introduced newer JDK , where Java has tightened encapsulation and access control on internal fields of platform classes such as java.util.Optional. Specifically, we're seeing the error: Failed making field 'java.util.Optional#value' accessible when running tests using Jukito — a testing framework that combines JUnit and Guice — on JDK 21.0.6 or 23.0.1. This problem is triggered by Gson attempting to reflectively access the private value field inside Optional, which is now restricted by newer JDK versions. However, Jukito’s reliance on an older version of Mockito added some additional complexity.

To address this, we had a few options:

  • Option1: Add a custom TypeAdapter.
  • Option2: Use the --add-opens JVM option in pom .( This is a quick hacky workaround that violates Java’s encapsulation)
  • Option3: Migrate to a different library or JAR. as @authorjapps mentioned..

I went with Option 1 (custom TypeAdapter),— which provides as it offers a clean solution with minimal code refactoring : ) . I also made sure to exclude any conflicting mockito dependencies to avoid potential version issues.

I've opened a draft PR for now ——I remember you had shown interest in this request earlier, so if you'd like, feel free to take a look and build on top of it. Once you’ve pushed the final changes, we can go ahead and clean up the draft. Don’t hesitate to reach out if you need any support — I’m happy to help!

@authorjapps
Copy link
Owner

Both @rkampani and @thanasissot have been added as collaborators here:
#713 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants