Skip to content

Upgrade Java 17 references to Java 21#21

Open
dillonvargo wants to merge 1 commit into
masterfrom
devin/1771891137-upgrade-java17-to-java21
Open

Upgrade Java 17 references to Java 21#21
dillonvargo wants to merge 1 commit into
masterfrom
devin/1771891137-upgrade-java17-to-java21

Conversation

@dillonvargo

@dillonvargo dillonvargo commented Feb 24, 2026

Copy link
Copy Markdown
Owner

Description of what I changed

Updated all references to Java 17 (and legacy Java 8) to reflect Java 21 as the minimum required Java version:

  1. pom.xml: Removed the java17 Maven profile. Since Java 21 is now the minimum supported version, the Java 17–specific profile (which overrode mockito-core and byte-buddy versions) is no longer needed. The java21 and java24 profiles remain.

  2. api/src/main/java/org/openmrs/util/OpenmrsUtil.java: Rewrote validateJavaVersion() to enforce Java 21 as the minimum. The old implementation used a regex (1\\.[0-7]\\.(.*)) that only caught pre-Java 8 legacy version strings. The new implementation parses the major version number from java.version and rejects anything below 21.

  3. README.md: Updated the prerequisites section to state Java 21 as the minimum JDK version (was Java 8).

Reviewer notes

  • Silent skip on unparseable version: The new validateJavaVersion() returns silently if java.version cannot be parsed (catches NumberFormatException). Consider whether this should throw an error instead.
  • No null guard: System.getProperty("java.version") is assumed non-null. This is standard JVM behavior but worth noting.
  • Test coverage: The existing JavaVersionTest only tests the happy path (current JVM >= 21 passes). No negative-path tests (e.g., mocking a version string like "17.0.1") were added.

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 run: https://app.devin.ai/sessions/36cfa93e393c4a90a23eee6bcb245bdf
Requested by: @dillonvargo


Open with Devin

- Remove Java 17 Maven profile from pom.xml (no longer needed since Java 21 is minimum)
- Update validateJavaVersion() in OpenmrsUtil.java to check for Java 21 minimum
- Update README.md to reflect Java 21 as minimum required version

Co-Authored-By: unknown <>
@devin-ai-integration

Copy link
Copy Markdown

🤖 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

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 +1082 to +1086
String majorStr = version.contains(".") ? version.substring(0, version.indexOf('.')) : version;
majorVersion = Integer.parseInt(majorStr);
} catch (NumberFormatException e) {
// If we can't parse the version, skip validation
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Version validation bypassed for EA/pre-release Java versions due to hyphen in version string

When java.version is a pre-release string without a dot (e.g., "21-ea", "17-ea+25"), the code at line 1082 takes the else branch (version has no .), setting majorStr to the full string "21-ea". Integer.parseInt("21-ea") then throws NumberFormatException, and the catch block at line 1084-1086 silently returns, skipping validation entirely.

Root Cause and Impact

The parsing logic only splits on . but does not account for the - separator used in early-access and pre-release Java version strings (e.g., "17-ea", "21-ea+25").

For a version like "17-ea" (which should be rejected since 17 < 21), the flow is:

  1. version.contains(".")false
  2. majorStr = version"17-ea"
  3. Integer.parseInt("17-ea") → throws NumberFormatException
  4. Catch block returns without throwing → validation skipped

This means an unsupported Java version like 17-ea would pass the check, potentially leading to runtime failures later. The fix should strip the pre-release suffix before parsing, e.g.:

String majorStr = version.split("[.\\-+]"​)[0];
Suggested change
String majorStr = version.contains(".") ? version.substring(0, version.indexOf('.')) : version;
majorVersion = Integer.parseInt(majorStr);
} catch (NumberFormatException e) {
// If we can't parse the version, skip validation
return;
String majorStr = version.split("[.\\-+]")[0];
majorVersion = Integer.parseInt(majorStr);
} catch (NumberFormatException e) {
// If we can't parse the version, skip validation
return;
}
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