WebSphere Application Server & Liberty

 View Only

Migrating to Java SE 17 with the WebSphere Application Migration Toolkit

By Ralph Sanders posted Tue November 30, 2021 06:25 PM

Java SE 17 was released this past September, and this is an important Java release due to its status as a Long-Term-Support release.  Support for Java SE 17 migrations has just been introduced in the release of the WebSphere Application Migration Toolkit, and now our tools now allow you to scan your application for Java SE 17 compatibility impacts.  IBM WebSphere Liberty currently supports Java SE 17 as well.

The Java release cadence
Long-Term-Support (LTS) releases can receive up to eight years of product support, and a new LTS version of Java SE will be released every two years.  Between LTS releases, a non-LTS version of Java SE will be released every six months. Non-LTS releases are only supported for six months until the next LTS or non-LTS release is available.  Here you can view the details of Oracle’s Java SE Support Roadmap.
How can the migration tools help you when moving to Java SE 17?
With our latest release, both the Migration Toolkit for Application Binaries (binary scanner) and the WebSphere Application Server Migration Toolkit (source scanner) can now assist you with your migration to Java SE 17.
Binary Scanner:
The binary scanner can be used to evaluate your binary Java EE archive files.   To migrate to Java SE 17 using the binary scanner, use the new --targetJava=java17 option.  Below you can see an example of this option being used in a Liberty migration from Java SE 11 to Java SE 17.
java -jar binaryAppScanner.jar testDeprecatedSocketImplementationFactoryMechanism.war --sourceJava=java11 --targetJava=java17 --sourceAppServer=liberty --targetAppServer=liberty
This is a portion of the resulting report that shows what changes need to be made to migrate to Java SE 17.
Binary Scanner Report
Source Scanner:
The source scanner allows you to analyze your source code directly with an Eclipse plug-in.  This is an example of how the source scanner can also be used for your migration.  In this example Liberty migration, you can see the new target Java option of Java 17.
Source Scanner Options
After running the analysis in the source scanner, you will be presented with a list of the changes that are necessary for your application to migrate to Java SE 17.
Source Scanner Results
IBM Cloud Transformation Advisor:
Transformation Advisor (TA) can also assist with your Java migrations.  With TA you have the ability to configure the target Java SE for Liberty analysis.  To do this, edit the TA Data Collector conf/customCmd.properties file to change the targetJava property.  This file will allow you to customize your migration scenario.  TA defaults to a Java SE 8 migration, so overriding the targetJava property with a more recent Java version will result in TA reporting additional development effort.  Currently, TA 2.5 supports migrations up to Java SE 16.

Issues with migrating to Java SE 17
Since Java SE 11, there have been many deprecations and removals.  You can view the WebSphere Application Migration Toolkit documentation to see the full list of changes that we detect.  

One of the most challenging aspects of migrating to Java SE 17 is the new strong encapsulation of the JDK internals.  Aside from a short list of critical internal APIs, including sun.misc.unsafe, JDK internals will no longer be accessible.  Java SE 17 no longer allows the user to relax this encapsulation, and the --illegal-access option from Java SE 11 was removed.  This comes as part of a push to encourage developers to use standard APIs instead of JDK internals.  See Strongly Encapsulate JDK Internals for more information about this issue.

Running the source scanner or binary scanner against your application is an easy way to check if you are using features or APIs that are no longer available.  For further guidance on the migration to Java SE 17, see the Oracle JDK Migration Guide.

The benefits and new features of Java 17
Aside from the benefit of the extended support, upgrading to Java SE 17 will also give you access to new language features.  Here are some features that have been added since Java SE 11.

Text blocks:
Java SE 17 now allows for multi-line strings called text blocks, which can be used in the same way as traditional strings.  Text blocks are defined with three double-quote characters at the beginning and end of the multi-line string. They can be used to improve the readability of your code by replacing multi-line strings created using newline characters.  For more information on how to use text blocks, you can view the Programmer's Guide to Text Blocks.

Sealed classes:
A sealed class or interface can only be extended or implemented by another class or interface if given explicit permission.  When creating a sealed class, you can use the permits clause to list the classes which are permitted to extend that class.  Similarly, when creating a sealed interface, you can use the permits clause to list which classes are permitted to implement that interface and which interfaces are permitted to extend it.  By using sealed classes you can control how your classes and interfaces are extended and implemented.  More information about sealed classes can be found in Oracle's Sealed Classes documentation.

Switch expressions:
Switch expressions are a new feature that makes switches more readable and concise in Java SE 17.  The new case labels allow for the use of multiple constants per case and for the use of pattern matching.  Also, with the new case labels, you no longer need to add break statements after each case. More information about switch expressions can be found in Oracle's Switch Expressions documentation.

Record classes:
Record classes are a new feature that allows you to concisely declare a class with fields to store information.  Once you have declared a record class, the methods equals, hashCode, toString, and the accessor methods for each of your fields are generated automatically for that class.  More information about record classes can be found in Oracle's Record Class documentation.

IBM Semeru runtimes
The IBM Semeru runtimes leverage the power of Eclipse OpenJ9 to provide a no-cost Java environment with increased performance and a smaller memory footprint.  Runtimes are currently available for Java SE 8 and Java SE 11.  Visit the IBM Semeru website for downloads and additional information.  You can also view this IBM Expert TV session on Modernizing Java Runtimes for a detailed explanation of the advantages of Semeru runtimes and a walk-through on how to use the migration toolkit.