Skip to content

Compute the Java version once, from the JDK at JAVA_HOME - #901

Closed
mernst wants to merge 7 commits into
codespecs:masterfrom
mernst:java-version-from-java-home
Closed

mernst wants to merge 7 commits into
codespecs:masterfrom
mernst:java-version-from-java-home

Conversation

@mernst

@mernst mernst commented Oct 11, 2026

Copy link
Copy Markdown
Member

Builds on #897; until that is merged, this pull request also shows its changes. The new commit is "Compute the Java version once, from the JDK at JAVA_HOME".

The top-level Makefile, java/Makefile, and tests/Makefile.common each computed the Java version differently, from whichever java or javac was on the PATH. Now java/java-home.mk defines JAVA_VERSION_STRING, JAVA_RELEASE_NUMBER, and the function java_at_least, from the JDK at JAVA_HOME, and all three Makefiles use them.

The version comes from java -version, which works for JDKs that lack a release file (such as Debian and Ubuntu's OpenJDK 8). If JAVA_HOME contains a JDK whose version cannot be determined, make fails.

* On macOS, use $(shell /usr/libexec/java_home); `$(/usr/libexec/java_home)`
  is a reference to an undefined make variable, so JAVA_HOME was empty.
* Compute JAVA_HOME once, with ":=", and locate javac with a single shell
  command.
* tests/Makefile.common sets JAVA_HOME before including Makefile.user, so the
  junit and junit5 Makefile.user files no longer duplicate the detection.
  A missing JDK is reported only when JAVA or JAVAC is expanded, so targets
  such as "clean" work without a JDK.
* java/Makefile fails clearly if no JDK is found.
Detect JAVA_HOME by asking the JVM that runs javac, which handles wrapper
scripts and Homebrew JDKs; fall back to /usr/libexec/java_home on macOS.
Check that JAVA_HOME contains bin/javac.  In the tests, fix the JDK after
Makefile.user is included, use it for the version check, and omit
nonexistent jars from JAVALIB_CLASSPATH.
java/Makefile and tests/Makefile.common include java/java-home.mk, which
asks the JVM that runs javac for its home directory, so that a javac
wrapper script (as used by jenv, asdf, or mise) works.  If the user set
JAVA_HOME, it warns when the javac on the PATH is in a different JDK.
scripts/daikon.bashrc uses the same logic.

In the tests, the Java version check uses the JDK in JAVA_HOME and is
skipped when there is no JDK, so that targets such as "clean" work
without one.  JAVALIB_CLASSPATH contains only jar files that exist.

This incorporates the changes of codespecs#896.
- java-home.mk exports JAVA_HOME, defines CHECKED_JAVA_HOME lazily, and reads
  JAVA_VERSION_STRING and JAVA_RELEASE_NUMBER from $JAVA_HOME/release.
- java/Makefile uses the JDK at JAVA_HOME for java, javac, javadoc, and jar,
  so the version and the --system directory agree with the compiler.
- The PATH-vs-JAVA_HOME warning runs once, after Makefile.user, and only
  when JAVA_HOME contains a JDK.
- tests/Makefile.common includes java-home.mk after Makefile.user and drops
  TESTS_JAVA_HOME.
- daikon.bashrc always exports JAVA_HOME and warns if it is not a JDK.
- The staging target fails if Javadoc was not built.
- java-home.mk falls back to "java -version" when the JDK has no "release"
  file (as in Debian/Ubuntu OpenJDK 8), and fails if a Java installation's
  version cannot be determined, rather than silently treating it as 0.
- java-home.mk defines java_at_least, used by all Makefiles instead of
  repeated shell tests; the major version is computed without a shell.
- JAVA_HOME detection first uses the JDK containing the javac on the PATH,
  and starts a JVM only if that fails.  daikon.bashrc does the same.
- DAIKON_JAVA_HOME snapshots JAVA_HOME, so commands and version variables
  agree even if a Makefile later reassigns JAVA_HOME.
- The PATH-vs-JAVA_HOME check also covers java, recognizes JDKs without a
  "release" file, and reruns when JAVA_HOME or PATH changes.
- The top-level Makefile runs java, javac, and jar from JAVA_HOME.
Simplify the detection: follow the javac on the PATH to its JDK, or use
/usr/libexec/java_home on macOS, without starting a JVM.

Java version computation, using JAVA_HOME's tools, the PATH-vs-JAVA_HOME
warning, and small unrelated fixes move to separate pull requests.
java-home.mk defines JAVA_VERSION_STRING, JAVA_RELEASE_NUMBER, and the
function java_at_least.  They replace the separate version computations in
the top-level Makefile, java/Makefile, and tests/Makefile.common, which used
whichever java or javac was on the PATH.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 7 billable files and costs up to $1.75.

Or wait 7 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: codespecs/daikon/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 2ba0303c-3ddc-41a9-b90c-c875da9742a8

📥 Commits

Reviewing files that changed from the base of the PR and between 779e30d and dc09682.


📒 Files selected for processing (7)
  • Makefile
  • java/Makefile
  • java/java-home.mk
  • scripts/daikon.bashrc
  • tests/Makefile.common
  • tests/daikon-tests/junit/Makefile.user
  • tests/daikon-tests/junit5/Makefile.user

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@mernst

mernst commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

Superseded by #897, which now computes the Java version (once, and cached across recursive makes) from the JDK at JAVA_HOME.

@mernst mernst closed this Oct 11, 2026
@mernst
mernst deleted the java-version-from-java-home branch October 11, 2026 04:22
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