Upgrade process from java 8 to java 21

Hello everyone,

I’m opening this thread to suggest a process to upgrade from Java 8 to 21.

@Serrof already started with Introduction of record but i would like to go a step further with this thread.

The idea would be to let Migrate to Java 21 | OpenRewrite Docs do the heavy lifting. It works using “Recipe” which can be group of smaller “Recipes”. We could create a dedicated branch and push a commit for each unitary “Recipe” performed and validated.

Feel free to add any suggestions or say what you think about this approach.

Cheers,
Vincent

Hi Vincent,

thanks for your help with the planning.

If you feel confident with using this tool, go ahead.
I know IntelliJ can already do a lot (run Java langage migration help as code inspection).

After records, one of the big thing is the switches that are much better with 21 w.r.t. 8.
And of course the getFirst and getLast on List.

Anyway, I’ve tried and failed miserably at locally creating a branch running with JDK 21. IntelliJ does not want to compile it. So if you want to do that for issue 1805, please do.

Cheers,
Romain.

+1 for using OpenRewrite @Vincent !

Actually there is another thing we need to talk about. It’s var. I find it very useful to have the code “breathe” a little bit.
I think we should at least use it when declaring variables, as it’s readily available what class the instance is. For Field stuff in particular, it would avoid the long diamond operators.
What do you think?

Cheers,
Romain.

I do agree with this, especially with Field as you mentioned. Java is already verbose enough ! This could be a dedicated commit and i think there is already a Recipe for this in OpenRewrite.

Hello everyone,

This message to let you know that i have started the upgrade process, you can check the progress here : Draft: Resolve "Upgrade to Java 21" (!948) · Merge requests · Orekit / Orekit · GitLab

Feel free to suggest additional modifications.

Cheers,
Vincent

Hi folks,

As I said in another thread, I strongly suggest that we switch to java 21 on the develop branch now that 13.1.5 is out.

Cheers,
Romain.

Hey !

I’m all for it, the process is ready but i did not want to mess with @luc ongoing work ? If you all agree, i can do it tomorrow.

Cheers,
Vincent

Don’t worry about me, I will catch up when I can.

I’ll provide a quick guide to do the heavy lifting using openrecipe :ok_hand:

It crossed my mind that we should have the Orekit tutorials and performance run first in java 21 otherwise the library itself is going to have red pipelines when we switch

I’m (re)starting the migration process to java 21, i’m rebasing the current migation branch on develop because too many changes happened since first experiment (as expected).

Little update everyone, i think i have done most of the work for the migration to Java 21 for both orekit and the tutorials.

I contacted @sdinot to add a new container image for java 21 to the orekit registry and then i’ll be able to test my branches on the repo.

I’ll wrap this up tomorrow morning if that’s alright with you.

EDIT: orekit performances is almost ready as well, waiting for the new image on the registry to be done

Cheers,
Vincent

Ok, so orekit-tutorials and orekit-performances have been upgraded to Java 21. I’m now getting a SonarQube failure due to insufficient coverage on Orekit (93.5% instead of the required 95%), mainly on condition coverage. This might be related to SonarQube behavior rather than an actual regression.

EDIT: Forgot to link the merge request in progress Resolve "Upgrade to Java 21" (!948) · Merge requests · Orekit / Orekit · GitLab

I did a quick spot check and the changes look fine to me. It will take me a bit to get used to the new instanceof and switch statements.

Some of the code had been formatted to look like a table, e.g. UTCScale, and so using getFirst() instead of get(0) makes that line a bit longer. Not a big deal.

Looks like the code coverage issues are legitimate functionality that was not covered by existing unit tests. I’m guessing you’re hitting the Sonar gate because a high percentage of your changes are conditionals, like instanceof and switch.

Regards,
Evan

Thanks for taking a look @evan.ward !

Yes i did not want to force a specific format yet, it can be done in another merge request with a format we agree on.

That is also my thought, i’m wondering if we should merge with current state and then add tests or if we should add more unit tests in this MR specifically.

Cheers
Vincent

I think you should merge, unless you think it’s fast to add the tests, tell us.
We can temporarily downgrade the Sonar gate to 93.5% and add tests afterwards to reach the 95% mark

I can take a look tonight to see if i can add some tests easily but i do think merging this before other merge requests are approved is the best option. Otherwise it will be a neverending nightmare :smiling_face_with_tear:

For what it’s worth, when some code uses both get/add(0), get/add(1) and so on, I don’t really think replacing the (0) part with First is relevant. In my humble opinion, it is worth doing only when we only retrieve the first element (or the last one, of course).

Tonight ? Don’t have time to do this during your workday? That’s too bad, because this migration isn’t just a nice-to-have. It’s really going to benefit everyone. :pleading_face: