Skip to content

Move platform detection into PlatformEnum; introduce oshi.ffm.SystemInfo - #3112

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:no-jna
Apr 3, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:no-jna

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 3, 2026 •

Copy link
Copy Markdown
Member

This PR moves OS platform detection out of SystemInfo and into PlatformEnum itself, making it available without loading JNA, and introduces oshi.ffm.SystemInfo as the canonical entry point for the FFM module.

Platform detection (oshi-core)

  • PlatformEnum gains a CURRENT_PLATFORM static initializer and getCurrentPlatform() using os.name/java.vm.name; no JNA dependency
  • SystemInfo.getCurrentPlatform() is deprecated, delegating to PlatformEnum.getCurrentPlatform()
  • All callers across oshi-core and oshi-demo updated to call PlatformEnum.getCurrentPlatform() directly

New FFM entry point (oshi-core-java25)

  • oshi.ffm.SystemInfo is the new canonical class: MACOS → FFM implementations, LINUX → JNA fallback (until ported), WINDOWS → FFM/JNA mix
    -SystemInfoFFM reduced to a deprecated shell extending oshi.ffm.SystemInfo
  • PlatformEnumFFM deprecated entirely; detection delegates to PlatformEnum via switch
  • module-info.java exports oshi.ffm; module-info.test opens it to JUnit

Tests

  • oshi.SystemInfoFFMTest moved and renamed to oshi.ffm.SystemInfoTest, using oshi.ffm.SystemInfo and PlatformEnum
  • GlobalMemoryFFMTest, VirtualMemoryFFMTest, OperatingSystemFFMTest updated to use oshi.ffm.SystemInfo

Summary by CodeRabbit

  • New Features

    • Centralized platform detection with a stable public getter.
    • New FFM SystemInfo entry point for FFM-based OS and hardware access.
    • Added DragonFly BSD platform detection.
    • Improved macOS FFM framework resolution and mac-specific FFM helpers.
    • FFM package now exported for module consumers.
  • Deprecations

    • Legacy platform adapters and older FFM compatibility wrappers marked deprecated; migrate to the new FFM entry point.

@coderabbitai

coderabbitai Bot commented Apr 3, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Centralized platform detection in PlatformEnum, added public FFM entrypoint oshi.ffm.SystemInfo with memoized platform-specific OS/HAL creation, deprecated legacy FFM adapters (PlatformEnumFFM, SystemInfoFFM), extracted macOS framework lookup into MacForeignFunctions and updated mac FFM classes, switched callsites/tests to use PlatformEnum, and exported oshi.ffm.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Documented new FFM entrypoint and platform-detection relocation; noted deprecations (PR #3112).
Platform core
oshi-core/src/main/java/oshi/PlatformEnum.java, oshi-core/src/main/java/oshi/SystemInfo.java
Added PlatformEnum.getCurrentPlatform() (cached); deprecated SystemInfo.getCurrentPlatform() and switched internal dispatches to PlatformEnum.
New FFM public entrypoint
oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java, oshi-core-java25/src/main/java/module-info.java
Added public oshi.ffm.SystemInfo with memoized suppliers for OS/HAL; exported oshi.ffm in module descriptor.
Deprecated FFM adapters
oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java, oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
Marked deprecated; PlatformEnumFFM delegates to PlatformEnum; SystemInfoFFM now subclasses oshi.ffm.SystemInfo and removed prior factory logic.
Mac FFM helper & hierarchy
oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java, .../mac/MacForeignFunctions.java, .../mac/*Functions.java
Extracted macOS framework lookup into new MacForeignFunctions; removed framework lookup from generic ForeignFunctions; updated mac FFM classes to extend MacForeignFunctions.
FFM internals & docs
oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
Removed mac frameworkLookup from generic class; added/expanded Javadocs for pointer/errno helpers.
Callsite updates
oshi-core/src/main/java/... (e.g., AbstractCentralProcessor.java, AbstractPowerSource.java, PrivilegedUtil.java)
Replaced SystemInfo.getCurrentPlatform() with PlatformEnum.getCurrentPlatform() and updated imports/messages.
Demo & JMX
oshi-demo/src/main/java/... (FileStorePanel.java, ProcessPanel.java, JMXOshiAgentServer.java)
Platform checks updated to use PlatformEnum.getCurrentPlatform(); behavior unchanged otherwise.
Tests — core & java25/FFM
oshi-core/src/test/..., oshi-core-java25/src/test/...
Tests updated to use PlatformEnum.getCurrentPlatform(); FFM tests moved/renamed to oshi.ffm package and instantiate oshi.ffm.SystemInfo; test module open updated.
Minor fixes/logging
oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
Improved SLF4J logging to include throwable in thread-count failure path.
sequenceDiagram
    participant Client as Client
    participant PE as PlatformEnum
    participant FFMSys as oshi.ffm.SystemInfo
    participant OSImpl as Platform-specific OS/HAL

    Client->>PE: getCurrentPlatform()
    PE->>PE: read system properties
    PE-->>Client: PlatformEnum

    Client->>FFMSys: new SystemInfo()
    FFMSys->>FFMSys: prepare memoized suppliers

    Client->>FFMSys: getOperatingSystem()
    FFMSys->>PE: getCurrentPlatform()
    PE-->>FFMSys: PlatformEnum
    FFMSys->>OSImpl: instantiate platform-specific OS/HAL
    OSImpl-->>FFMSys: instance
    FFMSys-->>Client: OperatingSystem / HardwareAbstractionLayer
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • mprins

Poem

🐇 I hopped through enums at break of day,

One platform rule now lights the way.
A tidy FFM door swung open wide—
OS and HAL step out, side by side.
I nibble new code carrots with pride.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: moving platform detection into PlatformEnum and introducing oshi.ffm.SystemInfo as the canonical FFM entry point.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
oshi-core/src/main/java/oshi/SystemInfo.java (2)

89-89: ⚠️ Potential issue | 🔴 Critical

Compilation error: CURRENT_PLATFORM is not defined in this class.

The CURRENT_PLATFORM field was removed from SystemInfo as part of this refactoring, but this line still references it. This is causing the pipeline build failure.

🐛 Proposed fix
             default:
-                throw new UnsupportedOperationException(NOT_SUPPORTED + CURRENT_PLATFORM.getName());
+                throw new UnsupportedOperationException(NOT_SUPPORTED + PlatformEnum.getCurrentPlatform().getName());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/SystemInfo.java` at line 89, The throw
references a removed symbol CURRENT_PLATFORM; replace that reference with a call
to the current-platform accessor available in this refactor (e.g.,
Platform.getCurrentPlatform() or getCurrentPlatform()) so the exception reads
like: throw new UnsupportedOperationException(NOT_SUPPORTED +
<current-platform-accessor>().getName()); update the code to use the actual
method name present in this class or its imports (search for getCurrentPlatform,
Platform.getCurrentPlatform, or PLATFORM) to locate the correct replacement for
CURRENT_PLATFORM.

118-118: ⚠️ Potential issue | 🔴 Critical

Compilation error: CURRENT_PLATFORM is not defined in this class.

Same issue as line 89 - CURRENT_PLATFORM no longer exists in SystemInfo.

🐛 Proposed fix
             default:
-                throw new UnsupportedOperationException(NOT_SUPPORTED + CURRENT_PLATFORM.getName());
+                throw new UnsupportedOperationException(NOT_SUPPORTED + PlatformEnum.getCurrentPlatform().getName());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/SystemInfo.java` at line 118, The thrown
UnsupportedOperationException references a removed symbol CURRENT_PLATFORM;
update the message to use the existing accessor instead—replace
CURRENT_PLATFORM.getName() with getCurrentPlatform().getName() (or
getCurrentPlatform().name() if getName() isn't available) in the SystemInfo
class so the exception builds from the current platform accessor rather than the
deleted constant.
oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java (1)

33-45: ⚠️ Potential issue | 🟠 Major

Add Linux dispatch support in FFM or prevent Linux detection.

PlatformEnumFFM.getCurrentPlatform() can return LINUX on Linux systems, but createOperatingSystem() and createHardware() lack handlers for the LINUX case, causing a runtime exception. Either implement LinuxOperatingSystemFFM and LinuxHardwareAbstractionLayerFFM, or ensure PlatformEnumFFM returns UNSUPPORTED on Linux if FFM does not support it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java` around lines 33 - 45,
createOperatingSystem() and createHardware() call
PlatformEnumFFM.getCurrentPlatform() but do not handle the LINUX case, causing
runtime UnsupportedOperationException on Linux; either add a LINUX branch in
both methods to return new LinuxOperatingSystemFFM() and new
LinuxHardwareAbstractionLayerFFM() (implement those classes), or modify
PlatformEnumFFM.getCurrentPlatform() to map Linux to UNSUPPORTED so these
factories never see LINUX; update the switch statements in createOperatingSystem
and createHardware (and implement the corresponding Linux* classes if choosing
the former) to resolve the missing-case issue.
🧹 Nitpick comments (3)
oshi-core/src/test/java/oshi/software/os/FileSystemTest.java (1)

49-53: Optional: cache the current platform once outside the file-store loop.

This avoids repeated static lookups and makes the condition blocks easier to read.

♻️ Proposed small refactor
+        PlatformEnum currentPlatform = PlatformEnum.getCurrentPlatform();
         for (OSFileStore store : filesystem.getFileStores()) {
             ...
-            if (PlatformEnum.getCurrentPlatform() != PlatformEnum.WINDOWS) {
+            if (currentPlatform != PlatformEnum.WINDOWS) {
                 ...
-                if (PlatformEnum.getCurrentPlatform() != PlatformEnum.SOLARIS) {
+                if (currentPlatform != PlatformEnum.SOLARIS) {
                     ...
                 }
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/test/java/oshi/software/os/FileSystemTest.java` around lines 49
- 53, Cache the current platform once before iterating file stores to avoid
repeated PlatformEnum.getCurrentPlatform() calls and simplify the conditional
checks inside the loop; e.g., call PlatformEnum.getCurrentPlatform() into a
local variable (e.g., currentPlatform) before the file-store loop and then use
currentPlatform in the existing conditions that reference
PlatformEnum.getCurrentPlatform() when asserting store.getFreeInodes() and the
Solaris-specific branch.
oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java (1)

136-173: Optional readability cleanup: evaluate platform once before the loop.

This keeps assertions identical but reduces repetition in the hot loop.

♻️ Proposed small refactor
+        PlatformEnum currentPlatform = PlatformEnum.getCurrentPlatform();
         for (int lp = 0; lp < p.getLogicalProcessorCount(); lp++) {
             ...
-            switch (PlatformEnum.getCurrentPlatform()) {
+            switch (currentPlatform) {
                 case WINDOWS:
                     ...
             }
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java` around lines
136 - 173, The test repeatedly calls PlatformEnum.getCurrentPlatform() inside a
hot loop; compute PlatformEnum current = PlatformEnum.getCurrentPlatform() once
before iterating and use that value (or precompute expected behaviors/flags) in
the switch so the loop body only accesses
p.getLogicalProcessors().get(lp).getProcessorGroup() and getNumaNode(); update
CentralProcessorTest.java to replace repeated calls to
PlatformEnum.getCurrentPlatform() with the single local variable and keep the
existing assertions for each case (WINDOWS, LINUX, MACOS, SOLARIS, FREEBSD,
AIX).
oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java (1)

131-131: Cache platform once before iterating processes.

At Line 131, platform is checked on every loop iteration. Hoisting this into a local boolean isWindows will simplify the condition and avoid repeated calls.

Suggested refactor
-        for (OSProcess p : list) {
+        boolean isWindows = PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS);
+        for (OSProcess p : list) {
             int pid = p.getProcessID();
             // Ignore the Idle process on Windows
-            if (pid > 0 || !PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) {
+            if (pid > 0 || !isWindows) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java` at line 131, The
loop currently calls
PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS) on every
iteration; cache the platform once before iterating by creating a local boolean
(e.g., isWindows =
PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) and then replace
the condition if (pid > 0 ||
!PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) with if (pid >
0 || !isWindows) in ProcessPanel.java to avoid repeated platform lookups.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java`:
- Around line 37-43: Platform detection in PlatformEnumFFM incorrectly treats
Android/Dalvik and Windows CE as supported; update the osName checks so
Android/Dalvik and Windows CE map to UNSUPPORTED. Concretely, in the block that
sets CURRENT_PLATFORM (look for the osName variable and CURRENT_PLATFORM
assignments), change the Linux branch to first detect Android/Dalvik (e.g.,
check System.getProperty("java.vm.name") and/or osName.contains("Android") or
"Dalvik") and set CURRENT_PLATFORM = UNSUPPORTED for those runtimes, otherwise
set CURRENT_PLATFORM = LINUX; and change the Windows branch to treat
osName.startsWith("Windows CE") as UNSUPPORTED before falling back to
CURRENT_PLATFORM = WINDOWS; leave the MACOS handling as-is.

In `@oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java`:
- Line 20: The default branches in SystemInfo.java's createOperatingSystem() and
createHardware() reference an undefined CURRENT_PLATFORM.getName(); update both
to call PlatformEnum.getCurrentPlatform().getName() (matching the pattern used
elsewhere) so the default UnsupportedOperationException message compiles; locate
the DEFAULT cases in the createOperatingSystem() and createHardware() methods
and replace CURRENT_PLATFORM.getName() with
PlatformEnum.getCurrentPlatform().getName().

In `@oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java`:
- Around line 76-79: In ProcessPanel, the Windows branch of the
PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS) check is empty so
no radio is selected; explicitly set the default for Windows by selecting the
system-mode radio and clearing per-process (e.g., call
systemProc.setSelected(true) and ensure perProc.setSelected(false)) so the UI
matches the table behavior; update the Windows branch where
PlatformEnum.getCurrentPlatform() is checked and touch the perProc and
systemProc radio variables accordingly.

---

Outside diff comments:
In `@oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java`:
- Around line 33-45: createOperatingSystem() and createHardware() call
PlatformEnumFFM.getCurrentPlatform() but do not handle the LINUX case, causing
runtime UnsupportedOperationException on Linux; either add a LINUX branch in
both methods to return new LinuxOperatingSystemFFM() and new
LinuxHardwareAbstractionLayerFFM() (implement those classes), or modify
PlatformEnumFFM.getCurrentPlatform() to map Linux to UNSUPPORTED so these
factories never see LINUX; update the switch statements in createOperatingSystem
and createHardware (and implement the corresponding Linux* classes if choosing
the former) to resolve the missing-case issue.

In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Line 89: The throw references a removed symbol CURRENT_PLATFORM; replace that
reference with a call to the current-platform accessor available in this
refactor (e.g., Platform.getCurrentPlatform() or getCurrentPlatform()) so the
exception reads like: throw new UnsupportedOperationException(NOT_SUPPORTED +
<current-platform-accessor>().getName()); update the code to use the actual
method name present in this class or its imports (search for getCurrentPlatform,
Platform.getCurrentPlatform, or PLATFORM) to locate the correct replacement for
CURRENT_PLATFORM.
- Line 118: The thrown UnsupportedOperationException references a removed symbol
CURRENT_PLATFORM; update the message to use the existing accessor
instead—replace CURRENT_PLATFORM.getName() with getCurrentPlatform().getName()
(or getCurrentPlatform().name() if getName() isn't available) in the SystemInfo
class so the exception builds from the current platform accessor rather than the
deleted constant.

---

Nitpick comments:
In `@oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java`:
- Around line 136-173: The test repeatedly calls
PlatformEnum.getCurrentPlatform() inside a hot loop; compute PlatformEnum
current = PlatformEnum.getCurrentPlatform() once before iterating and use that
value (or precompute expected behaviors/flags) in the switch so the loop body
only accesses p.getLogicalProcessors().get(lp).getProcessorGroup() and
getNumaNode(); update CentralProcessorTest.java to replace repeated calls to
PlatformEnum.getCurrentPlatform() with the single local variable and keep the
existing assertions for each case (WINDOWS, LINUX, MACOS, SOLARIS, FREEBSD,
AIX).

In `@oshi-core/src/test/java/oshi/software/os/FileSystemTest.java`:
- Around line 49-53: Cache the current platform once before iterating file
stores to avoid repeated PlatformEnum.getCurrentPlatform() calls and simplify
the conditional checks inside the loop; e.g., call
PlatformEnum.getCurrentPlatform() into a local variable (e.g., currentPlatform)
before the file-store loop and then use currentPlatform in the existing
conditions that reference PlatformEnum.getCurrentPlatform() when asserting
store.getFreeInodes() and the Solaris-specific branch.

In `@oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java`:
- Line 131: The loop currently calls
PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS) on every
iteration; cache the platform once before iterating by creating a local boolean
(e.g., isWindows =
PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) and then replace
the condition if (pid > 0 ||
!PlatformEnum.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) with if (pid >
0 || !isWindows) in ProcessPanel.java to avoid repeated platform lookups.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f23bf73-3771-4b49-946d-0782f8e0a4c7

📥 Commits

Reviewing files that changed from the base of the PR and between 23cdc1f and 9c94449.

📒 Files selected for processing (18)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-core-java25/src/test/java/oshi/SystemInfoFFMTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core-java25/src/test/java/oshi/SystemInfoFFMTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
🪛 GitHub Actions: Pull Request CI
oshi-core/src/test/java/oshi/SystemInfoTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core-java25/src/test/java/oshi/SystemInfoFFMTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/test/java/oshi/software/os/FileSystemTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/main/java/oshi/util/PrivilegedUtil.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/test/java/oshi/util/FstatUtilTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/main/java/oshi/PlatformEnum.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java

[error] 1-1: Command failed: ./mvnw test -B. Maven compilation failed in goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) due to errors in SystemInfo.java.

oshi-core/src/main/java/oshi/SystemInfo.java

[error] 89-89: Maven compiler error: cannot find symbol 'CURRENT_PLATFORM' in class oshi.SystemInfo.


[error] 118-118: Maven compiler error: cannot find symbol 'CURRENT_PLATFORM' in class oshi.SystemInfo.

🔇 Additional comments (17)
CHANGELOG.md (1)

10-10: LGTM!

The changelog entry accurately documents the new PlatformEnum.getCurrentPlatform() and PlatformEnumFFM.getCurrentPlatform() APIs along with the deprecation of the corresponding SystemInfo methods.

oshi-core/src/main/java/oshi/PlatformEnum.java (2)

70-98: LGTM! Platform detection logic is well-implemented.

The static initializer correctly replicates JNA's platform detection logic:

  • Proper ordering (Windows CE before Windows to handle prefix matching correctly)
  • Android detection via java.vm.name equals "dalvik" on Linux
  • Safe fallback to UNKNOWN for unrecognized platforms
  • Thread-safe since CURRENT_PLATFORM is a final constant initialized at class load time

137-145: LGTM!

The new getCurrentPlatform() method provides a clean API for accessing the detected platform without loading JNA.

oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java (1)

303-305: LGTM!

The platform check correctly uses PlatformEnum.getCurrentPlatform() to gate the Linux-specific Auxv.queryAuxv() call.

oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java (1)

217-234: LGTM!

The platform dispatch correctly uses PlatformEnum.getCurrentPlatform() for the switch statement and error message.

oshi-core/src/main/java/oshi/util/PrivilegedUtil.java (1)

129-154: LGTM!

All three platform-conditional methods (queryPrefix, queryCommandAllowlist, queryFileAllowlist) correctly use PlatformEnum.getCurrentPlatform() for platform detection.

oshi-core/src/main/java/oshi/SystemInfo.java (1)

57-62: LGTM for the deprecation pattern.

The @Deprecated annotation and delegation to PlatformEnum.getCurrentPlatform() correctly implement the deprecation strategy.

oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java (1)

31-33: LGTM!

The test correctly uses PlatformEnum.getCurrentPlatform() for platform-specific echo command selection.

oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java (1)

101-103: LGTM!

The demo GUI correctly uses PlatformEnum.getCurrentPlatform() for the Windows-specific label display.

oshi-core/src/test/java/oshi/SystemInfoTest.java (1)

77-77: Good migration to enum-owned platform detection.

This keeps the same assertion behavior while avoiding the deprecated SystemInfo.getCurrentPlatform() path.

oshi-core-java25/src/test/java/oshi/SystemInfoFFMTest.java (2)

39-39: FFM test now correctly targets the new enum API.

The assertion remains valid and aligned with the deprecation plan.


46-46: Direct enum lookup in platform test looks correct.

Nice cleanup away from the deprecated SystemInfoFFM platform accessor.

oshi-core/src/test/java/oshi/util/FstatUtilTest.java (1)

27-27: Platform gate migration is correct here.

This preserves the OpenBSD-only test behavior while removing deprecated API usage.

oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java (1)

27-27: Looks good: FreeBSD condition now uses the new platform API.

Behavior is preserved and aligned with the PR’s deprecation path.

oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java (1)

105-113: Platform strategy switch update is consistent and safe.

The migration keeps existing behavior while removing dependency on deprecated platform detection entry points.

oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java (1)

63-65: getCurrentPlatform() accessor is a good API addition.

Returning a cached static platform is clean and predictable.

oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java (1)

52-57: Deprecation forwarder is clean and consistent.

The @Deprecated annotation and direct delegation to PlatformEnumFFM.getCurrentPlatform() are correct and keep API compatibility.

@dbwiddis dbwiddis changed the title Move platform detection out of SystemInfo into PlatformEnum Move platform detection into PlatformEnum; introduce oshi.ffm.SystemInfo Apr 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core/src/main/java/oshi/SystemInfo.java (1)

74-89: ⚠️ Potential issue | 🔴 Critical

Restore the Windows branches in both factories.

PlatformEnum.getCurrentPlatform() can still return WINDOWS and WINDOWSCE, but both switches now fall straight into default. On any Windows JVM, new SystemInfo().getOperatingSystem() and getHardware() will now throw UnsupportedOperationException even though the Windows implementations still exist.

Suggested fix
+import oshi.hardware.platform.windows.WindowsHardwareAbstractionLayer;
...
+import oshi.software.os.windows.WindowsOperatingSystem;
...
     private static OperatingSystem createOperatingSystem() {
         switch (PlatformEnum.getCurrentPlatform()) {
+            case WINDOWS:
+            case WINDOWSCE:
+                return new WindowsOperatingSystem();
             case LINUX:
             case ANDROID:
                 return new LinuxOperatingSystem();
             case MACOS:
                 return new MacOperatingSystemJNA();
@@
     private static HardwareAbstractionLayer createHardware() {
         switch (PlatformEnum.getCurrentPlatform()) {
+            case WINDOWS:
+            case WINDOWSCE:
+                return new WindowsHardwareAbstractionLayer();
             case LINUX:
             case ANDROID:
                 return new LinuxHardwareAbstractionLayer();
             case MACOS:
                 return new MacHardwareAbstractionLayerJNA();

Also applies to: 103-118

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/SystemInfo.java` around lines 74 - 89, The
switch in SystemInfo (PlatformEnum.getCurrentPlatform()) removed the WINDOWS and
WINDOWSCE cases causing getOperatingSystem() and getHardware() to throw
UnsupportedOperationException on Windows; restore explicit cases for
PlatformEnum.WINDOWS and PlatformEnum.WINDOWSCE in the switch inside
SystemInfo.getOperatingSystem() to return the Windows implementation (e.g., new
WindowsOperatingSystem()) and similarly restore the Windows branches in the
other factory switch (the getHardware() factory around the other diff) to return
the appropriate Windows hardware implementation classes (e.g., new
WindowsHardware/... classes) so Windows platforms are handled instead of falling
to default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java`:
- Around line 25-33: The deprecation Javadoc for
SystemInfoFFM.getCurrentPlatform() incorrectly points callers to
PlatformEnum.getCurrentPlatform() which changes the return type and semantics;
update the `@deprecated` tag and descriptive text to reference
PlatformEnumFFM.getCurrentPlatform() instead so the Javadoc matches the actual
return type and preserves FFM-specific UNSUPPORTED semantics for callers (i.e.,
change the `@deprecated` link and any sentence recommending the alternative to
PlatformEnumFFM.getCurrentPlatform()).

In `@oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java`:
- Around line 24-47: The tests currently assert against PlatformEnum which is
too broad; update both testPlatformEnum() and testGetCurrentPlatform() to use
PlatformEnumFFM: call PlatformEnumFFM.getCurrentPlatform() instead of
PlatformEnum.getCurrentPlatform() and assert it is not
PlatformEnumFFM.UNSUPPORTED (and not null) so the test enforces FFM-supported
platforms (Windows/macOS/Linux); ensure any necessary import for PlatformEnumFFM
is added and replace the UNKNOWN comparisons with PlatformEnumFFM.UNSUPPORTED.

---

Outside diff comments:
In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Around line 74-89: The switch in SystemInfo
(PlatformEnum.getCurrentPlatform()) removed the WINDOWS and WINDOWSCE cases
causing getOperatingSystem() and getHardware() to throw
UnsupportedOperationException on Windows; restore explicit cases for
PlatformEnum.WINDOWS and PlatformEnum.WINDOWSCE in the switch inside
SystemInfo.getOperatingSystem() to return the Windows implementation (e.g., new
WindowsOperatingSystem()) and similarly restore the Windows branches in the
other factory switch (the getHardware() factory around the other diff) to return
the appropriate Windows hardware implementation classes (e.g., new
WindowsHardware/... classes) so Windows platforms are handled instead of falling
to default.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c4afa90b-ff3b-4d5d-854d-dcd975589dc0

📥 Commits

Reviewing files that changed from the base of the PR and between 9c94449 and e1d1e9f.

📒 Files selected for processing (24)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/GlobalMemoryFFMTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java
  • oshi-core-java25/src/test/java/oshi/software/os/OperatingSystemFFMTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
✅ Files skipped from review due to trivial changes (12)
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core-java25/src/test/java/oshi/hardware/GlobalMemoryFFMTest.java
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core-java25/src/test/java/oshi/software/os/OperatingSystemFFMTest.java
  • oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, macos-latest
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
🔇 Additional comments (7)
oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java (2)

40-41: Platform detection import/update is correctly applied.

Using PlatformEnum here is the right migration target, and keeping SystemInfo is still valid since it’s used for MBean registration input.


105-112: Platform selection migration looks good and behavior is preserved.

Switching to PlatformEnum.getCurrentPlatform() matches the new entry point while keeping the same WINDOWS/default control flow.

oshi-core/src/test/java/oshi/util/FstatUtilTest.java (2)

2-2: Copyright header update is clean.

No issues with the year range update.


16-27: Platform gating change matches the refactor intent.

Switching the test guard to PlatformEnum.getCurrentPlatform() is consistent with the platform-detection centralization and keeps the OpenBSD-only behavior intact.

oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java (3)

2-2: Copyright header update looks correct.

Year range update is consistent and clean.


24-25: Platform import update is correct.

Using PlatformEnum directly aligns with the PR objective while keeping SystemInfo import valid for setUp().


136-172: Platform switch migration is correctly applied.

Switching to PlatformEnum.getCurrentPlatform() preserves test intent and avoids deprecated access via SystemInfo.

@codecov

codecov Bot commented Apr 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.50000% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.91%. Comparing base (23cdc1f) to head (7e26462).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
oshi-core/src/main/java/oshi/PlatformEnum.java 23.33% 17 Missing and 6 partials ⚠️
oshi-core/src/main/java/oshi/SystemInfo.java 28.57% 3 Missing and 2 partials ⚠️
...i-core/src/main/java/oshi/util/PrivilegedUtil.java 0.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3112      +/-   ##
==========================================
+ Coverage   67.65%   67.91%   +0.26%     
==========================================
  Files          37       37              
  Lines        1994     2023      +29     
  Branches      323      336      +13     
==========================================
+ Hits         1349     1374      +25     
+ Misses        535      534       -1     
- Partials      110      115       +5     

☔ View full report in Codecov by Sentry.
📢 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.

- Add CURRENT_PLATFORM static initializer and getCurrentPlatform() to
  PlatformEnum (oshi-core), using os.name/java.vm.name detection without
  loading JNA
- Deprecate SystemInfo.getCurrentPlatform(), delegating to
  PlatformEnum.getCurrentPlatform()
- Fix default branches in SystemInfo.createOperatingSystem() and
  createHardware() to call PlatformEnum.getCurrentPlatform().getName()
  instead of removed CURRENT_PLATFORM field
- Update all callers in oshi-core (AbstractCentralProcessor,
  AbstractPowerSource, PrivilegedUtil, SystemInfoTest,
  CentralProcessorTest, FileSystemTest, ExecutingCommandTest,
  FstatUtilTest, ProcstatUtilTest) to use
PlatformEnum.getCurrentPlatform()
  directly; remove now-unused SystemInfo imports
- Update oshi-demo callers (ProcessPanel, FileStorePanel,
  JMXOshiAgentServer) to use PlatformEnum.getCurrentPlatform();

- Create oshi.ffm.SystemInfo as the canonical FFM entry point, switching
  on PlatformEnum.getCurrentPlatform(): MACOS uses MacOperatingSystemFFM
/
  MacHardwareAbstractionLayerFFM, LINUX falls back to JNA
  LinuxOperatingSystem / LinuxHardwareAbstractionLayer, WINDOWS uses
  WindowsOperatingSystemFFM / WindowsHardwareAbstractionLayer
- Deprecate SystemInfoFFM, reducing it to a shell extending
  oshi.ffm.SystemInfo; deprecate SystemInfoFFM.getCurrentPlatform()
- Deprecate PlatformEnumFFM entirely; remove name field and constructor;
  static initializer delegates to PlatformEnum via switch; deprecate
  getName() and getCurrentPlatform()
- Export oshi.ffm from module-info.java; add --add-opens for oshi.ffm in
  module-info.test so JUnit can access test classes in that package

- Create oshi.ffm.SystemInfoTest (moved/renamed from
oshi.SystemInfoFFMTest),
  extending oshi.SystemInfoTest, using oshi.ffm.SystemInfo and
PlatformEnum
- Delete oshi.SystemInfoFFMTest
- Update GlobalMemoryFFMTest, VirtualMemoryFFMTest,
OperatingSystemFFMTest
  to use oshi.ffm.SystemInfo instead of SystemInfoFFM

- Update CHANGELOG.md for PR #3112

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java`:
- Around line 57-60: getName() currently returns
PlatformEnum.getCurrentPlatform().getName(), which returns the runtime platform
rather than the enum constant's name; change getName() in PlatformEnumFFM to
return the enum constant's own name (e.g., use this.name() or equivalent) so
PlatformEnumFFM.LINUX.getName() returns "LINUX" (or the intended constant name)
instead of the current platform's name while keeping the method deprecated for
backward compatibility.

In `@oshi-core/src/main/java/oshi/PlatformEnum.java`:
- Around line 63-66: The DRAGONFLYBSD enum constant was added but not supported
by platform-specific factories, causing UnsupportedOperationException from
PlatformEnum.getCurrentPlatform() consumers; either remove DRAGONFLYBSD from
PlatformEnum or fully add DragonFly support: implement DragonFly-specific
OS/Hardware/PowerSource classes and add DRAGONFLYBSD switch branches where
platforms are dispatched (notably in SystemInfo.createOperatingSystem(),
SystemInfo.createHardware(), and AbstractPowerSource.getPowerSources()), ensure
PlatformEnum.getCurrentPlatform() maps correctly, and update the README
supported platforms list to reflect the chosen decision.
- Around line 99-100: The osName check in PlatformEnum's static platform
detection uses osName.equalsIgnoreCase("dragonflybsd") which fails for real OS
names like "DragonFly BSD"; update the condition that sets CURRENT_PLATFORM to
DRAGONFLYBSD to use osName.startsWith("DragonFly") instead (match the style used
for other BSD checks) so the DRAGONFLYBSD constant is correctly selected during
initialization.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 918644fc-9db0-41db-ae9a-87981f1c6a8e

📥 Commits

Reviewing files that changed from the base of the PR and between 26a0b96 and 82bd4ba.

📒 Files selected for processing (24)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/GlobalMemoryFFMTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java
  • oshi-core-java25/src/test/java/oshi/software/os/OperatingSystemFFMTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
✅ Files skipped from review due to trivial changes (12)
  • oshi-core-java25/src/test/java/oshi/software/os/OperatingSystemFFMTest.java
  • oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/GlobalMemoryFFMTest.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
🔇 Additional comments (10)
oshi-core/src/main/java/oshi/PlatformEnum.java (2)

72-104: LGTM on the static initializer structure.

The platform detection logic is well-organized with clear precedence (Windows CE before Windows, etc.). Using Locale.ROOT for case-insensitive comparisons is correct for system property values.


143-151: LGTM on the new getCurrentPlatform() method.

Clean implementation returning the pre-computed platform value. This enables JNA-free platform detection as intended by the PR.

oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java (1)

40-40: LGTM on the migration to PlatformEnum.getCurrentPlatform().

The switch statement correctly delegates to PlatformEnum.getCurrentPlatform() instead of the now-deprecated SystemInfo.getCurrentPlatform(). The demo's Windows-only support is preserved.

Also applies to: 105-113

oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java (2)

28-66: LGTM on the new FFM entry point implementation.

The class correctly restricts platform support to macOS, Linux, and Windows as per the FFM module's design constraints. The memoization pattern ensures lazy initialization with proper caching. Based on learnings, the FFM implementation intentionally only supports these three platforms.


68-84: LGTM on the public API.

The getters properly delegate to the memoized suppliers, providing clean lazy-initialized access to the platform-specific implementations.

oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java (2)

35-49: LGTM on the static initializer delegation.

The switch correctly maps from PlatformEnum to PlatformEnumFFM, with all unsupported platforms (including Android, Windows CE, and others) falling through to UNSUPPORTED. This addresses the previous review concern about platform over-classification.


62-71: LGTM on the deprecated getCurrentPlatform() method.

Properly marked deprecated with guidance to use PlatformEnum.getCurrentPlatform() instead.

oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java (1)

7-34: LGTM on the deprecated wrapper implementation.

The class correctly extends oshi.ffm.SystemInfo to inherit the FFM functionality while maintaining backward compatibility. The deprecation notices appropriately guide users to the new canonical entry points.

oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java (2)

28-51: LGTM on the FFM-specific platform tests.

The tests correctly use PlatformEnumFFM.getCurrentPlatform() to verify FFM platform support, distinct from the base class's PlatformEnum tests. The @EnabledForJreRange(min = JRE.JAVA_25) ensures these tests only run on Java 25+ where FFM is available, complementing the parent class's max = JRE.JAVA_25 constraint.


53-78: LGTM on the test methods using oshi.ffm.SystemInfo.

The tests correctly instantiate the new canonical FFM entry point and exercise the getOperatingSystem() and getHardware() methods.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java (1)

22-27: Use the shared framework resolver here too.

This class inherits MacForeignFunctions but still bypasses the shared resolver with a hard-coded framework path. All other wrappers in this package use frameworkLookup(), so switching here maintains consistency.

♻️ Suggested change
-    private static final SymbolLookup CORE_GRAPHICS = lib("CoreGraphics.framework/CoreGraphics");
+    private static final SymbolLookup CORE_GRAPHICS = frameworkLookup("CoreGraphics");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java`
around lines 22 - 27, Replace the hard-coded SymbolLookup assignment for
CORE_GRAPHICS that uses lib("CoreGraphics.framework/CoreGraphics") with the
shared framework resolver used by MacForeignFunctions; locate
CoreGraphicsFunctions and change the initialization of the CORE_GRAPHICS
constant to use frameworkLookup().lookup("CoreGraphics") (i.e., obtain the
CoreGraphics lookup via the frameworkLookup helper) so it follows the same
resolver pattern as other wrappers.
oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java (1)

16-25: Consider using an immutable list for defensive coding.

The String[] array is mutable even though the reference is final. For a constant, using List.of(...) would prevent accidental modification by subclasses. This is a minor consideration given the internal API nature.

♻️ Optional: Use immutable List
+import java.util.List;
+
 import java.lang.foreign.SymbolLookup;
-    protected static final String[] FRAMEWORK_SEARCH_PATHS = { "/System/Library/Frameworks", "/Library/Frameworks" };
+    protected static final List<String> FRAMEWORK_SEARCH_PATHS = List.of("/System/Library/Frameworks", "/Library/Frameworks");

Then update frameworkLookup:

-        for (String base : FRAMEWORK_SEARCH_PATHS) {
+        for (String base : FRAMEWORK_SEARCH_PATHS) {  // No change needed - List is iterable
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java` around
lines 16 - 25, FRAMEWORK_SEARCH_PATHS is a mutable String[] constant; replace it
with an immutable List<String> created via List.of(...) (e.g., protected static
final List<String> FRAMEWORK_SEARCH_PATHS =
List.of("/System/Library/Frameworks","/Library/Frameworks")) and update usages
such as frameworkLookup to accept/iterate a List<String> (or call
FRAMEWORK_SEARCH_PATHS.toArray(new String[0]) where an array is required) so the
constant cannot be modified by subclasses.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java`:
- Around line 22-27: Replace the hard-coded SymbolLookup assignment for
CORE_GRAPHICS that uses lib("CoreGraphics.framework/CoreGraphics") with the
shared framework resolver used by MacForeignFunctions; locate
CoreGraphicsFunctions and change the initialization of the CORE_GRAPHICS
constant to use frameworkLookup().lookup("CoreGraphics") (i.e., obtain the
CoreGraphics lookup via the frameworkLookup helper) so it follows the same
resolver pattern as other wrappers.

In `@oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java`:
- Around line 16-25: FRAMEWORK_SEARCH_PATHS is a mutable String[] constant;
replace it with an immutable List<String> created via List.of(...) (e.g.,
protected static final List<String> FRAMEWORK_SEARCH_PATHS =
List.of("/System/Library/Frameworks","/Library/Frameworks")) and update usages
such as frameworkLookup to accept/iterate a List<String> (or call
FRAMEWORK_SEARCH_PATHS.toArray(new String[0]) where an array is required) so the
constant cannot be modified by subclasses.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5bd06385-e458-424f-8392-12a66e957e6d

📥 Commits

Reviewing files that changed from the base of the PR and between 82bd4ba and e00b61d.

📒 Files selected for processing (10)
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/SystemConfigurationFunctions.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:46.910Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:99-100
Timestamp: 2026-04-03T18:43:50.370Z
Learning: In oshi/oshi PlatformEnum.java, the DragonFly BSD detection uses `osName.equalsIgnoreCase("dragonflybsd")` intentionally, mirroring the exact same check in JNA's `Platform.java` source. Java's `os.name` property on DragonFly BSD is "dragonflybsd" (no space), so `startsWith("DragonFly")` is NOT the correct pattern here. Do not suggest changing it to `startsWith`.
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/SystemConfigurationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java
🔇 Additional comments (11)
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java (1)

162-162: Good logging fix for failure diagnostics.

Line 162 now includes the throwable object, so failures in getThreadCount() keep stack traces for troubleshooting.

oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.java (1)

18-23: Nice superclass extraction.

The existing CoreFoundation lookup now depends only on the mac-specific base, which matches the refactor cleanly.

oshi-core-java25/src/main/java/oshi/ffm/mac/SystemConfigurationFunctions.java (1)

14-19: Nice boundary cleanup.

SystemConfigurationFunctions now picks up its lookup behavior from the mac-only base, which is the right abstraction boundary.

oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java (1)

18-23: Consistent with the mac wrapper refactor.

This keeps IOKitFunctions on the same abstraction as the other framework-backed mac classes.

oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java (1)

24-37: Preserves the custom load path.

Moving the class to MacForeignFunctions without disturbing tryLoad() looks right.

oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java (1)

20-25: Hierarchy looks consistent.

Keeping the mac wrappers on the same base class simplifies the split between shared and mac-only helpers.

oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java (1)

14-19: This fits the rest of the refactor.

The framework-backed wrapper now depends on the mac-only base instead of the shared one.

oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java (1)

20-25: The helper contracts are much clearer now.

The expanded Javadocs make the shared base easier to consume after the mac-specific lookup code moved out.

Also applies to: 41-48, 67-89, 127-143

oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java (3)

1-14: Well-structured class hierarchy for macOS FFM support.

The extraction of macOS-specific framework lookup functionality into a dedicated base class is a clean design. The Javadoc clearly explains the relationship to ForeignFunctions and the purpose of this class.


27-29: LGTM!

Protected constructor is appropriate for an abstract class not intended for direct instantiation.


38-48: LGTM!

The framework lookup implementation is correct:

  • Path format %s/%s.framework/%s correctly reflects macOS framework bundle structure
  • IllegalArgumentException is the appropriate exception thrown by SymbolLookup.libraryLookup() when a library isn't found
  • The fallback logic to try each search path is clean
  • Good use of ignored variable name to indicate intentional suppression

- Add class-level and member javadocs to ForeignFunctions for all public
  and protected fields and methods
- Extract macOS-specific FRAMEWORK_SEARCH_PATHS and frameworkLookup into
  a new MacForeignFunctions base class in oshi.ffm.mac; both are protected
  so subclasses can reference them and javadoc can link to them
- Update all Mac FFM classes to extend MacForeignFunctions instead of
  ForeignFunctions directly; remove now-redundant ForeignFunctions imports
- Fix LOG.warn in MacOperatingSystemFFM to use SLF4J parameterization and
  pass the exception as the final argument to preserve the stack trace
@dbwiddis

dbwiddis commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java (1)

82-97: ⚠️ Potential issue | 🟡 Minor

Validate length before narrowing it to int.

Lines 95–96 cast the native length parameter to int twice without validation. When length exceeds Integer.MAX_VALUE, the narrowing cast discards the high 32 bits, resulting in a negative value that throws NegativeArraySizeException at runtime. Values between Integer.MAX_VALUE and 2^32-1 silently overflow. Add an explicit boundary check with a clear error message:

Suggested fix
 public static byte[] getByteArrayFromNativePointer(MemorySegment pointer, long length, Arena arena) {
     if (pointer == null || pointer.equals(MemorySegment.NULL)) {
         return null;
     }
+    if (length < 0 || length > Integer.MAX_VALUE) {
+        throw new IllegalArgumentException("length out of range for byte[]: " + length);
+    }
     MemorySegment bytesSegment = MemorySegment.ofAddress(pointer.address()).reinterpret(length, arena, null);
-    byte[] result = new byte[(int) length];
-    MemorySegment.copy(bytesSegment, JAVA_BYTE, 0, result, 0, (int) length);
+    int size = (int) length;
+    byte[] result = new byte[size];
+    MemorySegment.copy(bytesSegment, JAVA_BYTE, 0, result, 0, size);
     return result;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java` around lines
82 - 97, The method getByteArrayFromNativePointer narrows the long parameter
length to int without validation which can overflow and cause
NegativeArraySizeException or silent truncation; before allocating result and
copying, validate that length is non-negative and <= Integer.MAX_VALUE (and not
greater than available segment size if applicable), and throw a clear
IllegalArgumentException (or similar) with a descriptive message referencing
length when the check fails so the cast (int) length and new byte[(int) length]
are safe.
♻️ Duplicate comments (1)
oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java (1)

57-60: ⚠️ Potential issue | 🟡 Minor

getName() now reflects runtime platform, not the enum constant.

Line 59 makes PlatformEnumFFM.LINUX.getName() depend on the host OS instead of returning the LINUX label. Even deprecated, this is a behavioral mismatch for existing enum-instance callers.

Suggested compatibility-safe fix
 `@Deprecated`
 public String getName() {
-    return PlatformEnum.getCurrentPlatform().getName();
+    switch (this) {
+    case MACOS:
+        return PlatformEnum.MACOS.getName();
+    case LINUX:
+        return PlatformEnum.LINUX.getName();
+    case WINDOWS:
+        return PlatformEnum.WINDOWS.getName();
+    default:
+        return "Unsupported";
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java` around lines 57 -
60, PlatformEnumFFM.getName() currently calls
PlatformEnum.getCurrentPlatform().getName(), causing calls like
PlatformEnumFFM.LINUX.getName() to return the runtime host OS rather than the
enum constant label; change getName() to return the enum constant's own name
(e.g., via this.name() or equivalent) so PlatformEnumFFM.getName() reflects the
enum instance (preserving behavior for callers) while keeping the method
deprecated.
🧹 Nitpick comments (3)
oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java (1)

30-30: Consider overriding inherited testPlatformEnum() to avoid JNA code path.

This class extends oshi.SystemInfoTest, which has a testPlatformEnum() method that calls the base class's static main(null) (exercising the JNA code path and logging "Using JNA"). Since static methods aren't polymorphic, the inherited test will run the JNA demo rather than the FFM demo during FFM test execution.

If the intent is purely FFM testing, you could override testPlatformEnum() to either call the FFM main(null) or mark it with @Disabled to skip. Alternatively, if running both JNA and FFM paths is acceptable for coverage, this is fine as-is.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java` at line 30, The
inherited testPlatformEnum() from oshi.SystemInfoTest triggers the base class's
static main(null) (running the JNA demo) instead of the FFM demo; to fix,
override testPlatformEnum() in this SystemInfoTest class and either (a) call the
FFM demo main(null) explicitly (the FFM entrypoint used elsewhere in this
module) or (b) annotate the override with `@Disabled` to skip it—implement the
override method named testPlatformEnum() in the subclass to ensure the intended
FFM behavior or to disable the JNA path.
oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java (1)

41-50: Preserve the last load failure in exception chaining for diagnostic clarity.

The method currently discards intermediate IllegalArgumentException errors from each load attempt and replaces them with a generic final message. Since SymbolLookup.libraryLookup(...) can throw IllegalArgumentException for various failures—architecture mismatches, missing dependencies, and other loader errors—preserving the last exception as a cause enables developers to diagnose real issues.

♻️ Suggested refactor
     protected static SymbolLookup frameworkLookup(String frameworkName) {
+        IllegalArgumentException lastError = null;
         for (String base : FRAMEWORK_SEARCH_PATHS) {
             try {
                 return SymbolLookup.libraryLookup(
                         String.format("%s/%s.framework/%s", base, frameworkName, frameworkName), LIBRARY_ARENA);
-            } catch (IllegalArgumentException ignored) {
+            } catch (IllegalArgumentException e) {
+                lastError = e;
                 // Not found in this directory, try the next one
             }
         }
-        throw new IllegalArgumentException("Framework not found: " + frameworkName);
+        throw new IllegalArgumentException("Framework not found: " + frameworkName, lastError);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java` around
lines 41 - 50, The loop in frameworkLookup currently swallows each
IllegalArgumentException from SymbolLookup.libraryLookup and throws a generic
IllegalArgumentException at the end; change it to capture the last caught
IllegalArgumentException (e.g., lastEx) during iteration and when throwing the
final IllegalArgumentException("Framework not found: " + frameworkName) pass
lastEx as the cause (using the constructor that accepts a Throwable) so the
underlying loader error is preserved for diagnostics while keeping the existing
message.
oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java (1)

67-79: Make the maximum C-string size explicit.

Line 79 reinterprets a fixed 1024-byte window. If a null-terminated string exceeds this size, getString(0) will throw IndexOutOfBoundsException when it scans beyond the segment bounds without finding the terminating NUL byte. The Javadoc implies this is a generic null-terminated string reader, but the implementation has an implicit 1 KiB ceiling. Either accept a maxLength parameter or document the 1024-byte limit in the contract so callers understand when this method fails.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java` around lines
67 - 79, The method getStringFromNativePointer currently reinterprets a fixed
1024-byte segment (MemorySegment.reinterpret(1024,...)) which can cause
IndexOutOfBoundsException for longer C-strings; change the API to accept an
explicit maxLength parameter (e.g., getStringFromNativePointer(MemorySegment
pointer, Arena arena, long maxLength)), validate maxLength > 0, replace the
hardcoded 1024 with the passed maxLength when calling reinterpret, and update
the Javadoc for getStringFromNativePointer to document the meaning and
requirement of maxLength (that the native string must be NUL-terminated within
maxLength bytes).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core/src/test/java/oshi/SystemInfoTest.java`:
- Around line 77-79: The test guard currently only excludes PlatformEnum.UNKNOWN
but PlatformEnum.getCurrentPlatform() can return DRAGONFLYBSD which has no
backend; update the guard in SystemInfoTest so it also treats DRAGONFLYBSD as
unsupported before calling main(null) or constructing new SystemInfo().
Concretely, change the assertion or add a conditional to skip/exclude
PlatformEnum.DRAGONFLYBSD (in addition to PlatformEnum.UNKNOWN) when checking
PlatformEnum.getCurrentPlatform() so the test does not exercise new SystemInfo()
on DragonFly BSD.

---

Outside diff comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java`:
- Around line 82-97: The method getByteArrayFromNativePointer narrows the long
parameter length to int without validation which can overflow and cause
NegativeArraySizeException or silent truncation; before allocating result and
copying, validate that length is non-negative and <= Integer.MAX_VALUE (and not
greater than available segment size if applicable), and throw a clear
IllegalArgumentException (or similar) with a descriptive message referencing
length when the check fails so the cast (int) length and new byte[(int) length]
are safe.

---

Duplicate comments:
In `@oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java`:
- Around line 57-60: PlatformEnumFFM.getName() currently calls
PlatformEnum.getCurrentPlatform().getName(), causing calls like
PlatformEnumFFM.LINUX.getName() to return the runtime host OS rather than the
enum constant label; change getName() to return the enum constant's own name
(e.g., via this.name() or equivalent) so PlatformEnumFFM.getName() reflects the
enum instance (preserving behavior for callers) while keeping the method
deprecated.

---

Nitpick comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java`:
- Around line 67-79: The method getStringFromNativePointer currently
reinterprets a fixed 1024-byte segment (MemorySegment.reinterpret(1024,...))
which can cause IndexOutOfBoundsException for longer C-strings; change the API
to accept an explicit maxLength parameter (e.g.,
getStringFromNativePointer(MemorySegment pointer, Arena arena, long maxLength)),
validate maxLength > 0, replace the hardcoded 1024 with the passed maxLength
when calling reinterpret, and update the Javadoc for getStringFromNativePointer
to document the meaning and requirement of maxLength (that the native string
must be NUL-terminated within maxLength bytes).

In `@oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java`:
- Around line 41-50: The loop in frameworkLookup currently swallows each
IllegalArgumentException from SymbolLookup.libraryLookup and throws a generic
IllegalArgumentException at the end; change it to capture the last caught
IllegalArgumentException (e.g., lastEx) during iteration and when throwing the
final IllegalArgumentException("Framework not found: " + frameworkName) pass
lastEx as the cause (using the constructor that accepts a Throwable) so the
underlying loader error is preserved for diagnostics while keeping the existing
message.

In `@oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java`:
- Line 30: The inherited testPlatformEnum() from oshi.SystemInfoTest triggers
the base class's static main(null) (running the JNA demo) instead of the FFM
demo; to fix, override testPlatformEnum() in this SystemInfoTest class and
either (a) call the FFM demo main(null) explicitly (the FFM entrypoint used
elsewhere in this module) or (b) annotate the override with `@Disabled` to skip
it—implement the override method named testPlatformEnum() in the subclass to
ensure the intended FFM behavior or to disable the JNA path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35407b31-e9a6-4f3a-a111-c7d3e11807c6

📥 Commits

Reviewing files that changed from the base of the PR and between 23cdc1f and 7e26462.

📒 Files selected for processing (34)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/CoreFoundationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/SystemConfigurationFunctions.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/GlobalMemoryFFMTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java
  • oshi-core-java25/src/test/java/oshi/software/os/OperatingSystemFFMTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core/src/test/java/oshi/util/ExecutingCommandTest.java
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java
  • oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, windows-latest
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:46.910Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/test/java/module-info.test
  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core-java25/src/test/java/oshi/hardware/GlobalMemoryFFMTest.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core-java25/src/test/java/oshi/software/os/OperatingSystemFFMTest.java
  • oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java
  • oshi-core/src/test/java/oshi/software/os/FileSystemTest.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacSystemFunctions.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
  • oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/SystemConfigurationFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/MacForeignFunctions.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-03-29T20:01:01.877Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:01.877Z
Learning: In this repo’s `module-info.java` files, keep exports aligned with which platform implementations are actually supported by the current FFM (Foreign Function & Memory) backend. Do not export FreeBSD, OpenBSD, or Solaris packages (e.g., `oshi.util.platform.unix.freebsd|openbsd|solaris`) in modules where the FFM implementation only supports Windows/macOS/Linux; this asymmetry vs older Java targets (e.g., the java11 module-info that exports all Unix packages) is intentional and should not be flagged as an omission unless the underlying support changes.

Applied to files:

  • oshi-core-java25/src/main/java/module-info.java
📚 Learning: 2026-04-03T18:44:46.910Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:46.910Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.

Applied to files:

  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java
  • oshi-core/src/test/java/oshi/SystemInfoTest.java
  • oshi-core/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-04-03T18:43:50.370Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:99-100
Timestamp: 2026-04-03T18:43:50.370Z
Learning: In oshi/oshi PlatformEnum.java, the DragonFly BSD detection uses `osName.equalsIgnoreCase("dragonflybsd")` intentionally, mirroring the exact same check in JNA's `Platform.java` source. Java's `os.name` property on DragonFly BSD is "dragonflybsd" (no space), so `startsWith("DragonFly")` is NOT the correct pattern here. Do not suggest changing it to `startsWith`.

Applied to files:

  • oshi-core/src/test/java/oshi/util/FstatUtilTest.java
  • oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java
  • oshi-core/src/main/java/oshi/PlatformEnum.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/PlatformEnumFFM.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOKitFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/IOReportFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java
  • oshi-core-java25/src/main/java/oshi/SystemInfoFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java
🔇 Additional comments (21)
CHANGELOG.md (1)

10-10: Changelog entry is clear and release-appropriate.

The new entry correctly captures the platform-detection move and FFM entry-point/deprecation changes.

oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java (1)

162-162: Logging improvement looks good.

Line 162 now preserves the stack trace while still including the message context.

oshi-core/src/main/java/oshi/PlatformEnum.java (1)

72-104: Platform detection centralization is solid.

The static detection flow and getCurrentPlatform() API are clean and align well with the migration away from SystemInfo.getCurrentPlatform().

Also applies to: 144-151

oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java (1)

42-66: Factory dispatch logic is correct for FFM scope.

OS/HAL creation is consistent, memoized, and properly fails fast for unsupported platforms.

oshi-core-java25/src/main/java/module-info.java (1)

7-7: oshi.ffm export is the right module-surface change.

This cleanly exposes the new FFM entry point without widening unrelated exports.

oshi-core-java25/src/test/java/module-info.test (1)

3-4: Test module openness update is appropriate.

Opening oshi.ffm to JUnit is consistent with the new test entry points.

oshi-core/src/main/java/oshi/SystemInfo.java (1)

61-64: Deprecation bridge and platform dispatch updates look correct.

The delegation path remains backward-compatible while moving callers to PlatformEnum.getCurrentPlatform().

Also applies to: 76-94, 107-125

oshi-core/src/main/java/oshi/hardware/common/AbstractPowerSource.java (1)

218-233: Platform dispatch migration looks correct.

Switching to PlatformEnum.getCurrentPlatform() here keeps behavior intact and aligns with the deprecation path cleanly.

oshi-core-java25/src/test/java/oshi/hardware/VirtualMemoryFFMTest.java (1)

10-19: FFM test entrypoint update is clean.

Using oshi.ffm.SystemInfo in this test is the right migration and keeps the test intent unchanged.

oshi-demo/src/main/java/oshi/demo/gui/ProcessPanel.java (2)

76-80: Windows default CPU mode selection is now explicit and correct.

Nice fix: UI state now matches the underlying default behavior on Windows.


132-133: Idle-process filter migration is correct.

Switching this guard to PlatformEnum.getCurrentPlatform() preserves behavior and removes deprecated API usage.

oshi-core/src/test/java/oshi/util/ProcstatUtilTest.java (1)

27-28: FreeBSD test guard update is straightforward and safe.

The switch from deprecated platform lookup to PlatformEnum is correct here.

oshi-core/src/main/java/oshi/util/PrivilegedUtil.java (1)

130-153: Privileged config dispatch migration is correct.

All three platform checks were updated consistently without changing Linux/default behavior.

oshi-demo/src/main/java/oshi/demo/jmx/JMXOshiAgentServer.java (1)

105-113: JMX platform strategy selection migration looks good.

Using PlatformEnum.getCurrentPlatform() here is consistent with the rest of the PR and keeps existing behavior intact.

oshi-demo/src/main/java/oshi/demo/gui/FileStorePanel.java (1)

101-103: Windows label guard update is correct.

This is a clean platform-API migration with no logic drift.

oshi-core/src/test/java/oshi/hardware/CentralProcessorTest.java (1)

136-173: Platform-specific assertion dispatch update is solid.

The move to PlatformEnum.getCurrentPlatform() is consistent, and the test expectations remain intact across OS cases.

oshi-core-java25/src/test/java/oshi/ffm/SystemInfoTest.java (3)

37-51: LGTM! Previous review concern addressed.

The tests now correctly use PlatformEnumFFM.getCurrentPlatform() and assert against PlatformEnumFFM.UNSUPPORTED, ensuring that the FFM-supported platform contract (Windows/macOS/Linux) is validated. The @SuppressWarnings("deprecation") annotations are appropriate since PlatformEnumFFM is deprecated per this PR.


53-65: LGTM!

Both testGetOperatingSystem() and testGetHardware() correctly instantiate oshi.ffm.SystemInfo (resolved from the current package) and verify the FFM implementations are properly wired.


72-78: LGTM!

The main() method correctly logs "Using FFM" and instantiates oshi.ffm.SystemInfo, ensuring this demo exercises the FFM code path rather than JNA.

oshi-core-java25/src/main/java/oshi/ffm/mac/CoreGraphicsFunctions.java (1)

22-27: Nice cleanup of framework resolution.

Moving this binding onto MacForeignFunctions and frameworkLookup("CoreGraphics") keeps the macOS wrappers consistent and removes the hardcoded framework path from the class.

oshi-core-java25/src/main/java/oshi/ffm/mac/DiskArbitrationFunctions.java (1)

14-14: Base-class switch to MacForeignFunctions looks good.

Line 14 aligns this class with the macOS framework-lookup path while preserving the existing downcall wrapper surface.

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