Upgrade minimum Java version requirement from Java 8 to Java 21#24
Upgrade minimum Java version requirement from Java 8 to Java 21#24devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- 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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| 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)")) { |
There was a problem hiding this comment.
🟡 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:
version.matches("1\\..*")— catches1.x.yformat (Java ≤8)version.matches("(9|1[0-9]|20)\\..*")— catches9.x,10.x-19.x,20.x(requires a dot after the major version)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.
| 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].*)?")) { |
Was this helpful? React with 👍 or 👎 to provide feedback.
Description of what I changed
Upgrades the minimum required Java runtime version from Java 8 to Java 21 across three files:
OpenmrsUtil.java— Rewrote thevalidateJavaVersion()regex to reject all Java versions below 21. The old check only rejected1.[0-7].x(Java 7 and below). The new check rejects:1.xversions (Java 8 and below, which use the legacy1.major.minorformat)9through20(which use the modernmajor.minor.patchformat)pom.xml— Removed thejava17Maven 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. Thejava21andjava24profiles remain.README.md— Updated the documented minimum JDK version from 8 to 21.The version-checking regex in
validateJavaVersion()is the most important change. Please verify:(9|1[0-9]|20))1\..*)Issue I worked on
This change was requested directly by the repository owner to align the runtime requirement with the existing compile target (
javaCompilerVersion=21in pom.xml).Checklist: I completed these to help reviewers :)
validateJavaVersion()should be reviewed/updated if they exist.mvn clean packageright before creating this pull request and added all formatting changes to my commit.Link to Devin run: https://app.devin.ai/sessions/a5be03cbd1a34da49bb4789bfa0bd3c3
Requested by: @dillonvargo