Skip to content

Upgrade minimum Java version requirement from Java 8 to Java 21#24

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1771963277-upgrade-java-21
Open

Upgrade minimum Java version requirement from Java 8 to Java 21#24
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1771963277-upgrade-java-21

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Feb 24, 2026

Copy link
Copy Markdown

Description of what I changed

Upgrades the minimum required Java runtime version from Java 8 to Java 21 across three files:

  1. OpenmrsUtil.java — Rewrote the validateJavaVersion() regex to reject all Java versions below 21. The old check only rejected 1.[0-7].x (Java 7 and below). The new check rejects:
    • All 1.x versions (Java 8 and below, which use the legacy 1.major.minor format)
    • Versions 9 through 20 (which use the modern major.minor.patch format)
  2. pom.xml — Removed the java17 Maven profile that provided mockito-core/byte-buddy overrides for Java 17 compatibility. This profile is no longer needed since Java 17 is below the new minimum. The java21 and java24 profiles remain.
  3. README.md — Updated the documented minimum JDK version from 8 to 21.

⚠️ Key area for review

The version-checking regex in validateJavaVersion() is the most important change. Please verify:

  • It correctly rejects versions 9 through 20 (pattern: (9|1[0-9]|20))
  • It correctly rejects Java 8 and below (pattern: 1\..*)
  • It allows Java 21+ to pass
  • Edge cases like bare version strings ("20"), early access builds ("21-ea"), and future versions (22+) are handled correctly

Issue I worked on

This change was requested directly by the repository owner to align the runtime requirement with the existing compile target (javaCompilerVersion=21 in pom.xml).

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. ⚠️ No new tests added — existing tests for validateJavaVersion() should be reviewed/updated if they exist.
  • I ran mvn clean package right before creating this pull request and added all formatting changes to my commit. ⚠️ Not yet run — will wait for CI.
  • 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/a5be03cbd1a34da49bb4789bfa0bd3c3
Requested by: @dillonvargo


Open with Devin

- Update validateJavaVersion() to reject Java versions below 21
- Remove the java17 Maven profile (no longer needed)
- Update README.md to reflect Java 21 minimum requirement

Co-Authored-By: unknown <>
@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 4 additional findings in Devin Review.

Open in Devin Review

String version = System.getProperty("java.version");
// Reject Java 8 and below (1.x.y format)
// Reject Java 9 through 20 (major version prefix 9. or 1x. or 20.)
if (version.matches("1\\..*") || version.matches("(9|1[0-9]|20)\\..*") || version.matches("(9|1[0-9]|20)")) {

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.

🟡 Version regex fails to reject Java 9-20 early-access/build-suffixed versions without a dot separator

The validateJavaVersion() regex at api/src/main/java/org/openmrs/util/OpenmrsUtil.java:1082 does not reject Java version strings for versions 9-20 that use a hyphen or plus suffix instead of a dot separator (e.g., "9-ea", "20-ea", "20+36").

Root Cause

The three regex patterns are:

  1. version.matches("1\\..*") — catches 1.x.y format (Java ≤8)
  2. version.matches("(9|1[0-9]|20)\\..*") — catches 9.x, 10.x-19.x, 20.x (requires a dot after the major version)
  3. version.matches("(9|1[0-9]|20)") — catches bare major versions like "9", "20"

Per JEP 322, valid java.version strings include formats like "$MAJOR-$PRE" (e.g., "20-ea") and "$MAJOR+$BUILD" (e.g., "20+36"). These strings have no dot after the major version number, so they don't match pattern 2, and they have a suffix, so they don't match pattern 3 either.

Impact: If OpenMRS is started on a pre-release or custom build of Java 9-20 (e.g., "20-ea"), the version check passes silently instead of throwing an APIException. The application would then fail later with a less informative error since it's compiled for Java 21.

Suggested change
if (version.matches("1\\..*") || version.matches("(9|1[0-9]|20)\\..*") || version.matches("(9|1[0-9]|20)")) {
if (version.matches("1\\..*") || version.matches("(9|1[0-9]|20)([^0-9].*)?")) {
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