Skip to content

Cache installed applications once, unmodifiable, in AbstractOperatingSystem - #3898

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:installed-apps-caching
Nov 14, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:installed-apps-caching

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #3895's review: centralize the installed-applications cache.

Changes

  • Every platform memoized getInstalledApplications() itself. Linux, AIX and Windows (JNA and FFM) returned the cached ArrayList directly, so a caller that filtered or cleared it changed what every later caller saw until the cache expired. macOS, the BSDs and Solaris already cached an unmodifiable list.
  • AbstractOperatingSystem now owns the cache (installedAppsExpiration()) and wraps the result with Collections.unmodifiableList. Its getInstalledApplications() is final, so a platform cannot bypass the cache.
  • Each platform overrides only protected List<ApplicationInfo> queryInstalledApps(), which defaults to an empty list. The per-platform supplier fields and getters are removed from Linux, macOS, AIX, Solaris, the BSD base, and both Windows backends.

Behavior: on Linux, AIX and Windows, modifying the returned list now throws UnsupportedOperationException. The returned list was never meant to be mutable, so this has no CHANGELOG entry.

Verification

  • New tests in AbstractOperatingSystemTest cover the default empty list, unmodifiability, and that the list is queried once while cached.
  • Full gate with -Perror-prone -Paggregate-coverage and tests: all modules pass, comparison tests included.

Summary by CodeRabbit

  • Improvements
    • Installed-application results are now cached consistently across supported operating systems and returned as an unmodifiable list.
  • Changes
    • Installed-application listings are no longer provided on BSD.

…System

Every platform memoized getInstalledApplications() itself, and Linux, AIX and
Windows (JNA and FFM) handed out the cached ArrayList, so a caller that
filtered or cleared it changed what every later caller saw until the cache
expired. AbstractOperatingSystem now owns the cache and wraps it in an
unmodifiable list behind a final getter; each platform overrides only
queryInstalledApps(), which defaults to an empty list. A caller that modified
the returned list now gets UnsupportedOperationException, as on macOS.
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Installed-application caching moves to AbstractOperatingSystem, which provides a cached, unmodifiable accessor and a default query hook. Platform classes now implement the hook by delegating to platform-specific queries, while tests cover the shared behavior.

Changes: Installed-application retrieval

Layer / File(s) Summary
Shared accessor, cache, and tests
oshi-common/src/main/java/oshi/software/common/AbstractOperatingSystem.java, oshi-common/src/test/java/oshi/software/common/AbstractOperatingSystemTest.java
AbstractOperatingSystem adds a cached, unmodifiable installed-application accessor and a query hook that defaults to an empty list. Tests check the default, immutability, cache identity, and single query execution.
Platform query hooks
oshi-common/src/main/java/oshi/software/common/os/{linux,mac}/..., oshi-common/src/main/java/oshi/software/common/os/unix/{aix,bsd,solaris}/..., oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java, oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
Linux, macOS, AIX, Solaris, and Windows delegate their query hooks to platform-specific implementations. BsdOperatingSystem removes its installed-application accessor and query hook.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Suggested reviewers: rohan-coder02

Merge Risk: Minimal · up to 16efe

This change centralizes installed-application caching and makes the returned list unmodifiable on every platform. Callers that mutate the returned list on Linux, AIX, or Windows will now get an UnsupportedOperationException, which is the stated intent. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: installed applications are now cached once, in AbstractOperatingSystem, and the cached list is unmodifiable. The raw summary and objectives confirm that getInstalledAp…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: installed applications are now cached once, in AbstractOperatingSystem, and the cached list is unmodifiable. The raw summary and objectives confirm that getInstalledApplications() becomes final, wraps the cached result with Collections.unmodifiableList, and adds the queryInstalledApps() extension point. Per-platform suppliers and getters are removed in the Linux, Mac, AIX, BSD, Solaris, and Windows classes. The title is specific and concise, and it matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the cached list,
Then hops along with queries swift.
The shared hook keeps results in place,
Unmodifiable, same on each new case.
One tiny thump: the tests confirm the trace.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9058b35-e650-49c3-95c5-79dd7aadf769
Commits

Reviewing files that changed from the base of the PR and between 5e219c5 and 16efe7a.

Files selected for processing: 9

  • oshi-common/src/main/java/oshi/software/common/AbstractOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
  • oshi-common/src/test/java/oshi/software/common/AbstractOperatingSystemTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java
Files with no reviewable changes: 1

  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 15

  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, DragonFly BSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: CodeRabbit
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Test JDK 25, ubuntu-latest
Additional context used

Code guidelines: 2

FAQ.md — auto-discovered
AGENTS.md — auto-discovered
Path-based instructions: 4

Applicability reference: AGENTS.md: # AGENTS.md **API compatibility.**

CodeRabbit inference engine (FAQ.md)

Files:

  • oshi-common/src/main/java/oshi/software/common/AbstractOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
  • oshi-common/src/test/java/oshi/software/common/AbstractOperatingSystemTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-core-ffm` may not reference `com.sun.jna.**`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/oshi/software/common/AbstractOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
  • oshi-common/src/test/java/oshi/software/common/AbstractOperatingSystemTest.java
Source excerpt: **Language level.**

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/oshi/software/common/AbstractOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java
Learnings: 1

Learning: 2026-04-06T04:45:51.516Z

Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java

@dbwiddis
dbwiddis merged commit 4076376 into oshi:master Nov 14, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the installed-apps-caching branch November 14, 2026 19:49
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