Skip to content

Upgrade outdated Java 8 references to Java 21#28

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1773272149-upgrade-java8-to-java21
Open

Upgrade outdated Java 8 references to Java 21#28
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1773272149-upgrade-java8-to-java21

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Mar 11, 2026

Copy link
Copy Markdown

Description of what I changed

Upgraded all remaining Java 8 references across the codebase to align with the project's actual Java 21 compiler target:

  • test-module/pom.xml: Changed javaCompilerVersion from 1.8 to 21 to match the root pom.xml.
  • OpenmrsUtil.java: Rewrote validateJavaVersion() to enforce a Java 21 minimum. The old regex (1\\.[0-7]\\.(.*)) only caught pre-Java-8 versions using the legacy 1.x naming scheme. The new implementation parses the major version from java.version, handling both the old 1.x format and modern x.y.z format, and throws an APIException if the major version is below 21.
  • README.md: Updated the prerequisite JDK version from 8 to 21.
  • test-module/pom.xml: Replaced javax.servlet:javax.servlet-api:4.0.1 with jakarta.servlet:jakarta.servlet-api:6.1.0 (matching the version declared in the root pom.xml). Removed the now-unnecessary javax.servlet:servlet-api exclusion from the openmrs-web dependency.
  • pom.xml: Updated the comment in the java17 profile to reflect that the minimum supported version is now Java 21 instead of referencing the unsupported Java 8.

Things for reviewers to verify

  • validateJavaVersion() parsing logic: The new implementation uses Integer.parseInt which could throw NumberFormatException on truly unexpected java.version strings. The old implementation would silently pass in that case. Verify this tradeoff is acceptable.
  • Removal of javax.servlet:servlet-api exclusion: Confirm that openmrs-web no longer transitively depends on the old javax.servlet:servlet-api artifact, so removing this exclusion won't introduce classpath conflicts.
  • No new tests added for the updated validateJavaVersion() method — existing tests (if any) should still pass since the current JVM is ≥ 21.

Issue I worked on

see https://issues.openmrs.org/browse/TRUNK-

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.
  • I have added tests to cover my changes. (If you refactored existing code that was well tested you do not have to add tests)
  • I ran mvn clean package right before creating this pull request and added all formatting changes to my commit.
  • All new and existing tests passed.
  • My pull request is based on the latest changes of the master branch.

Link to Devin Session: https://app.devin.ai/sessions/fa9e5fc2d2af412bacf2a19359f351e8
Requested by: @dillonvargo


Open with Devin

- Update test-module/pom.xml javaCompilerVersion from 1.8 to 21
- Rewrite validateJavaVersion() in OpenmrsUtil.java to check for Java 21 minimum, handling both old 1.x and modern x.y.z version formats
- Update README.md to reference Java 21 minimum
- Replace javax.servlet:javax.servlet-api with jakarta.servlet:jakarta.servlet-api:6.1.0 in test-module/pom.xml
- Remove obsolete javax.servlet:servlet-api exclusion from test-module/pom.xml
- Update mockito comment in pom.xml to reflect Java 21 minimum

Co-Authored-By: Dillon Vargo <dillonvargo@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment on lines +1083 to +1084
int dotIndex = version.indexOf('.');
majorVersion = Integer.parseInt(dotIndex == -1 ? version : version.substring(0, dotIndex));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 NumberFormatException on Java EA/pre-release version strings without dots

The new version parsing logic at line 1084 fails to handle Java version strings that contain no dot but include non-numeric suffixes such as 21-ea, 21+35, or 21-ea+5-2724. When dotIndex == -1, the entire version string (e.g., "21-ea") is passed to Integer.parseInt(), which throws a NumberFormatException. This crashes the application startup path (called from web/src/main/java/org/openmrs/web/Listener.java). The old regex-based code would simply not match and would not throw on any version format.

Example failing inputs and fix

For version = "21-ea": dotIndex = -1, so it calls Integer.parseInt("21-ea") → throws NumberFormatException.

The fix should also strip the - suffix when there is no dot, e.g.:

int dotIndex = version.indexOf('.');
int dashIndex = version.indexOf('-');
int plusIndex = version.indexOf('+');
int endIndex = dotIndex;
if (endIndex == -1) endIndex = dashIndex;
if (endIndex == -1) endIndex = plusIndex;
majorVersion = Integer.parseInt(endIndex == -1 ? version : version.substring(0, endIndex));
Suggested change
int dotIndex = version.indexOf('.');
majorVersion = Integer.parseInt(dotIndex == -1 ? version : version.substring(0, dotIndex));
int dotIndex = version.indexOf('.');
int dashIndex = version.indexOf('-');
int endIndex = dotIndex != -1 ? dotIndex : dashIndex;
majorVersion = Integer.parseInt(endIndex == -1 ? version : version.substring(0, endIndex));
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant