IBM Cloud Docs
Upgrading the Java version for your application

Upgrading the Java version for your application

watsonx Code Assistant Standard plan

To upgrade your Java code, you first build and analyze your application, and then fix any issues that are identified. Depending on the issues, the ability to fix them can be automated, assisted, or self-directed.

Before you begin, set up your enterprise Java environment.

Eclipse IDE only: For best results with a multimodule Java application, ensure that you import the aggregator module and each submodule as separate projects within the Eclipse workspace. Watsonx Code Assistant is unlikely to successfully introspect your project if you import the top-level directory as a single project.

Time required to analyze your code

The amount of time to analyze your application varies. The following times are typical.

Time required to analyze
Time Application details
Seconds to a few minutes Fewer than 100 classes
2 to 10 minutes 20,000 to 50,000 lines of code
10 or more minutes 300,000 lines of code

When watsonx Code Assistant analyzes your application, it excludes some third-party packages from code analysis by default. For more information, see Third-party packages that are excluded from application analysis.

Analyzing your application to upgrade the Java version

The analysis provides you with a list of issues to address. After you fix the issues, the Java version for your application is upgraded.

If you revert the changes to your code, you must click Return to analyze and do a full analysis if you want to do the Java upgrade again.

  1. In your IDE, right-click on any item in the hierarchy in the directory of the application that you want to upgrade, click watsonx Code Assistant, then click Upgrade Java Version.

  2. On your Upgrade <your application name> page, select the analysis parameters, which define the rules that the application is analyzed against.

    1. Optionally change the Java source, which is displayed automatically with a recommended value.

      The Java source version is the Java version that you are upgrading from. Based on the Java version detected in the build configuration, watsonx Code Assistant recommends a Java version to use as the source. You can choose a different Java version from the list of supported Java versions if that is appropriate for your application. The build configuration is in the Maven pom.xml file.

      The Java version that is recommended is either the Java version that is detected in the build configuration, or is the best available Java version given the Java version that was detected. For example, if Java 9, which is not supported, is specified in the build configuration, Java 8 is the recommended Java version. Java 8 is recommended since it is the closest supported Java version for the analysis, and since it is earlier than the detected Java version.

      The minimum-supported Java version is Java 6.

    2. Select the Java target.

      The Java target version is the Java version that you are upgrading your Java application to. The target versions that you can select from are long-term (LTS) Java releases.

    3. Click either Analyze or Build and analyze.

      Application analysis is done on the application binary. The application must be built before analysis begins. You can either automatically or manually build the application.

      • Click Build and analyze to automatically build and analyze the application.
      • Click Analyze after you manually build the application.

      After your application is built and analyzed, the issues to fix or review are displayed. Depending on the issues to fix, the ability to fix them can be automated, assisted, or self-directed. These issues to review don't require a code change to migrate your code. However, they might need to be verified or tested.

      When you click Build and analyze, the application is built at its current Java source version, so it can be analyzed for Java upgrade issues. Make sure to configure the IDE with the Java developer kit of the Java source version, so the IDE can successfully build the application.

      When building and analyzing, if you have issues with a multimodule project that includes a submodule with liberty-assembly packaging, run mvn install at the root level of the project and try again.

Fixing issues and reviewing additional information for your application

The Upgrade <your application name> page lists the following information:

  • The Java version source and the Java version target
  • Links to a technology report, an inventory report, and an analysis report
  • Tabs for issues to fix, which can be automated, assisted, or self-directed fixes, and for additional information

The target Java developer kit is required when you run automated fixes and when you build the application after the Java version target changes are made. Make sure that the target Java developer kit is configured for your IDE.

  • The Eclipse IDE extension automatically tries to find the correct Java developer kit that matches the Java version target from the set of all configured Java developer kits in the IDE.
  • In the Visual Studio Code IDE, you must manually change the Java developer kit configuration.

Completing automated fixes

If you have an Automated fixes tab with one or more fixes, select the tab.

Because watsonx Code Assistant completes the fixes for you, you do not need to make any code changes. The large language model (LLM) is not used for automated fixes.

  1. Expand the Instructions and read them.
  2. Optionally open the issue to review the description of the issue.
  3. Click Run automated fixes.
    • The Automated fixes are fixed.
    • External issues remain in the list until you update the associated dependency.
  4. When Run automated fixes completes, click Rebuild and refresh to update the list of issues.

If the automated fixes fail to run and produce compilation errors in the console output, make sure to update the version of the maven-compiler plug-in to 3.13.0 or newer.

When running automations, if you have issues with a multimodule project that includes a submodule with liberty-assembly packaging, run mvn install at the root level of the project and try again.

Completing assisted fixes

If you have an Assisted fixes tab with one or more fixes, select the tab.

Although you fix your code, watsonx Code Assistant assists you by providing suggestions in the chat on how to change your code.

The level of assistance available varies with the issue. The assisted fixes help you to fix the issue, and sometimes a code suggestion gets you all the way or most the way. Other times, the code suggestion might be as simple as removing an old API to prevent a compilation failure, and no further action is required from you. It is important to follow steps for each assisted fix to understand the value and limitations of each assisted fix. In cases where a complete code suggestion is not provided, you can think of the assisted fix as a conversation starter in the chat. Continue to engage with the chat to build your understanding of the issue and its resolution.

For a list of issues associated with assisted fixes, see the Assisted fixes reference.

To use assisted fixes:

  1. Expand the Instructions and follow the instructions.

  2. For each issue, expand it.

  3. Click Read more to expand the issue.

  4. Click the file that is listed in the issue. The file opens in the editor.

  5. Expand the issue to view the issue details.

  6. If in the details you are directed to select a code snippet, select it.

  7. Click Help me for assistance in fixing the issue.

    If you are using Visual Studio Code, the following restrictions apply:

    • Make sure that you select Java code in only one active editor.
    • Make sure that the active editor in which you selected Java code is in a different editor group than the Modernize to Liberty or Java Upgrade view.
  8. Follow the code suggestions in the chat to modify the code and fix the issue.

    Sometimes, the chat provides an informational response instead of a code suggestion.

  9. As you fix issues, click Rebuild and refresh until all assisted fixes are fixed.

Completing self-directed fixes

If you have a Self-directed fixes tab with one or more fixes, select the tab.

You change the code and determine how to fix the code, but you can get help from the chat.

  1. Expand the Instructions and follow the instructions.
  2. Expand each issue.
  3. Click Read more to expand the issue.
  4. Click the file that is listed in the issue. The file opens in the editor.
  5. Click Start chat, which is displayed for each occurrence of the issue. The chat window opens so you can get help for the occurrence. For example, you can ask the code assistant what the current code does. Or, you can ask if an alternative implementation exists for the problematic code.
  6. As you fix issues, click Rebuild and refresh until all self-directed fixes are fixed.

Addressing additional information

If you have an Additional information tab with a number of one or more on it, select the tab.

The issues listed on the tab are determined the same way that issues on other tabs are determined. Although the additional information issues do not require a change to your code, review the issues so you can ensure that your application is working when your code is migrated.

The additional information might indicate issues, such as minor behavioral changes in an API and what to do about them.

  • Expand the instructions and follow them.

  • Click each issue.

    • Click Read more to expand the issue.
    • Click the link on the file that is listed in the issue to review the code.