Skip to content

fix: reuse cached and 0.3.0 Java installs (offline and on upgrade) - #111

Open
e-kotov wants to merge 5 commits into
mainfrom
fix/offline-cached-java
Open

e-kotov wants to merge 5 commits into
mainfrom
fix/offline-cached-java

Conversation

@e-kotov

@e-kotov e-kotov commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

  1. Offline: use_java(21), the java_resolve() family and java_quick_install() contacted the vendor API, and failed or warned, even when Java 21 was already cached.
  2. Upgrading from 0.3.0: 0.4.0 listed 0.3.0 installs (installed/<os>/<arch>/<version>) as unknown/unknown but never reused them. It also never reused 0.3.0 archives. So every JDK was downloaded and unpacked a second time. In a real 0.3.0 → 0.4.0 test with Java 17 and 21, the cache grew from 1.1 GB to 2.1 GB.

Changes

  • Reusing 0.3.0 installs (internal java_installed_matching() / java_find_installed(), used by use_java(), java_resolve() and java_quick_install()):
    • A 0.3.0-layout install satisfies a Corretto/native request, ranked after exact matches.
    • Only if the JDK identifies itself as Corretto: its release file names Corretto, or it ships Corretto's version.txt and commitId.txt. The second case covers Corretto 8, whose release file is missing on Linux and macOS and doesn't name the vendor on Windows; Temurin and Zulu ship neither file.
    • 0.3.0's java_unpack() accepted any archive, so a non-Corretto JDK could end up in that layout.
  • java_quick_install() links an already installed Java into the project instead of downloading it.
    • The project-link step of java_install() moved to java_link_project().
    • The link mirrors the install's folder layout. java_install() output is unchanged.
  • Cached-archive fallback in java_download() — used only when the vendor API cannot be reached:
    • What counts: no response at all (offline, DNS, proxy, timeout), or HTTP 5xx. These fail with class rJavaEnv_network_error, which the Corretto/Temurin/Zulu resolvers keep when they re-raise.
    • Then it reuses a matching archive in distrib/. For Corretto that is the newest cached build of the requested version, including 0.3.0 archive names. Temurin and Zulu names are fixed by the request.
    • Other errors (e.g. "version not available") are raised as before, as is the original error when nothing matches or force = TRUE.
  • use_java() skips the online version check when the archive is cached. Offline, that check otherwise warns for Temurin.
  • java_clear_distrib() looked for <archive>md5 instead of <archive>.md5, so it left 0.3.0 checksum files behind.
  • Docs and NEWS: java_download() docs describe when cached archives are used. 0.4.0 hasn't gone to CRAN, so the NEWS is folded into the 0.4.0 entry, which now also explains how to reset the cache. The version stays 0.4.0.

Testing

  • Unit tests: tests/testthat/test-offline_cache.R (13 tests) covers:
    • network-error tagging, and non-network errors not using the cache;
    • recognising Corretto JDKs among 0.3.0 installs, including the Windows Corretto 8 release file;
    • link layout.
  • Full suite: passes except test-java_env_session.R, which needs rJava. That test fails the same way on main.
  • Upgrade, end-to-end:
    • Steps: CRAN 0.3.0 runs use_java(21) and java_quick_install(17, project) (and separately use_java(8)); then this branch runs the same steps on that cache.
    • Result: nothing is downloaded and the cache size is unchanged.
  • Offline, end-to-end (network cut with unshare -n):
    • Functions: use_java(), java_resolve(), java_ensure(), local_java_env(), with_java_env() and java_quick_install().
    • Cache states: new layout (three variants), 0.3.0 layout, archive only, 0.3.0-named archive only, and Temurin.
    • Result: all 48 combinations succeed with no warnings.
  • Review reproductions:
    • Online java_download("21.0.9") with a cached 21.0.9 archive raises "not available", as on main; offline it uses the cache.
    • A Temurin JDK unpacked by 0.3.0 into the legacy layout is not used for use_java(21).
  • Corretto 8 file layout: checked by listing the real Corretto 8 archives for Linux, macOS (x64 and aarch64) and Windows, and the Temurin 8 and Zulu 8 archives for Linux.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JknUFhxmgsHgeuv1PDNmUW

use_java(), java_resolve() and everything built on them (java_ensure(),
local_java_env(), with_java_env()) plus java_quick_install() failed or
warned without network access even when the requested Java was cached:

- Installs in the 0.3.0 layout (<platform>/<arch>/<version>) are listed
  with distribution/backend "unknown" and never matched a Corretto/native
  request, so the network was queried. They are now treated as Corretto
  native installs, after exact matches.
- java_download() always resolved metadata online first. When that fails
  it now reuses a matching archive from the distrib cache (newest cached
  Corretto build, deterministic Temurin/Zulu names, 0.3.0 Corretto names),
  and re-raises the original error when nothing matches.
- use_java() skips the online version check when the archive is cached,
  avoiding noisy Temurin probe warnings offline.
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.17073% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.07%. Comparing base (c2c19b1) to head (1eab5eb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
R/java_quick_install.R 85.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   91.76%   92.07%   +0.31%     
==========================================
  Files          27       27              
  Lines        3025     3131     +106     
==========================================
+ Hits         2776     2883     +107     
+ Misses        249      248       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…files

- java_quick_install() links an already installed Java (either cache
  layout, including 0.3.0 installs) into the project instead of
  downloading and unpacking it again. The project-link step of
  java_install() moves to java_link_project(), which mirrors the cache
  layout of the install it links.
- use_java() and java_quick_install() share java_find_installed(), which
  also drops the "No Java distributions have been installed yet" alert
  from these lookups.
- java_clear_distrib() deleted "<archive>md5" instead of "<archive>.md5",
  leaving checksum files of 0.3.0 archives behind.
- 0.4.0 has not been released to CRAN, so the NEWS for this work moves
  into the 0.4.0 entry (with a note on resetting the cache) and the
  version stays 0.4.0.
@e-kotov e-kotov changed the title fix: use cached Java when offline fix: reuse cached and 0.3.0 Java installs (offline and on upgrade) Oct 23, 2026
…o installs

Addresses review of #111:

- java_download() fell back to a cached archive on any metadata error,
  so online a version the vendor no longer serves silently succeeded
  from cache. Requests that get no response (and HTTP 5xx in
  read_json_url()) now fail with class rJavaEnv_network_error, the
  Corretto/Temurin/Zulu resolvers keep that class when re-raising, and
  only those errors trigger the fallback.
- 0.3.0's java_unpack() accepted any archive, so a legacy-layout install
  is only reused for Corretto requests if the JDK identifies itself as
  Corretto (release file, or version.txt for Corretto 8).
- java_quick_install() takes the project link layout from the install's
  folder depth rather than its distribution label.
- java_download() docs and NEWS describe when cached archives are used.
- The use_java() test checks that version validation is not called,
  instead of mocking it to fail.
Windows Corretto 8 ships a release file that does not name the vendor,
so java_home_is_corretto() rejected it and a 0.3.0 install would be
downloaded again. Corretto (8 on Linux, macOS and Windows, and 11+)
ships version.txt and commitId.txt, which Temurin and Zulu do not, so
accept that pair whether or not a release file exists.

This branch has not been deployed

No deployments
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.

2 participants