Skip to content

Improve API documentation - #3154

Merged
dbwiddis merged 10 commits into
oshi:masterfrom
dbwiddis:api-docs
Apr 13, 2026
Merged

dbwiddis merged 10 commits into
oshi:masterfrom
dbwiddis:api-docs

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 13, 2026 •

Copy link
Copy Markdown
Member

Multiple updates to Javadocs combining information from existing README, FAQ, oshi-demo, oshi-properties comments, and other sources addressing common use cases.

Resolves #2746

Summary by CodeRabbit

  • Documentation

    • Expanded API docs with usage examples, platform notes, cross-references, native‑access guidance, and quick-starts for CPU, memory, virtual memory, disks/partitions, processes, network interfaces, and sensors; updated changelog.
  • Configuration

    • Added and documented many runtime configuration keys; deprecated misspelled aliases.
    • Enabled Javadoc-aware unused-import checking in style checks.
  • Bug Fixes

    • Corrected virtual‑memory doc typo and fixed Windows performance-counter config key names.
  • Tests

    • Adjusted native-comparison test to skip name assertions for certain kernel worker processes.

Document every configuration property constant with descriptions
mirroring oshi.properties comments, including defaults, platform
notes, and cross-references.

Enable checkstyle UnusedImports processJavadoc so imports used
only in @see tags are not flagged as unused.
Add code examples showing both blocking and non-blocking CPU
usage patterns. Document Windows Task Manager discrepancy and
link to GlobalConfig.OSHI_OS_WINDOWS_CPU_UTILITY.
Document process CPU load polling pattern with snapshot map.
Add memory guidance: getPrivateResidentMemory for Task Manager,
getResidentMemory for ps/top. Note Windows CPU scaling.
Add usage example showing how to find the disk and partition for
a file path via mount point correlation. Add @see links between
the hardware and software storage classes.
Add platform-specific notes to each Sensors method regarding
Windows jLibreHardwareMonitor dependency and Linux hwmon config.

Add quick-start code examples to both JNA and FFM SystemInfo
classes. Document platform coverage, memoization behavior, and
cross-reference the alternative entry point.
Add performance guidance to NetworkIF.updateAttributes noting
that re-querying the full list is more efficient for bulk updates.

Add usage example to OperatingSystem.getProcesses showing top-10
by CPU with ProcessFiltering and ProcessSorting constants.

Add usage example to GlobalMemory showing available/used memory
calculation with FormatUtil.
@coderabbitai

coderabbitai Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a42e35f-6423-4b0d-982c-bd9603baddb2

📥 Commits

Reviewing files that changed from the base of the PR and between a37f62b and 8c71296.

📒 Files selected for processing (1)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📜 Recent 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). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-03T18:43:51.290Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:99-100
Timestamp: 2026-04-03T18:43:51.290Z
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-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
🔇 Additional comments (1)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)

499-502: Good targeted flake fix for volatile kworker names.

This conditional exception is appropriately scoped and keeps meaningful validation (startTime) in place while avoiding unstable name checks for dynamically renamed kernel worker threads.


📝 Walkthrough

Walkthrough

Enabled Javadoc-aware unused-import checking and expanded API documentation across many modules; added and corrected numerous GlobalConfig keys (with deprecated aliases), updated CHANGELOG, adjusted Windows perfmon config usage, and a small test assertion exception. No public API signatures or runtime logic were changed.

Changes

Cohort / File(s) Summary
Checkstyle
config/checkstyle.xml
Enabled Javadoc processing for UnusedImports (processJavadoc="true").
Module & Package Docs
oshi-common/src/main/java/module-info.java, oshi-core/src/main/java/oshi/package-info.java
Expanded module/package-level Javadoc with architecture overview, native-access (JEP 472) guidance, and instructions for native-free oshi-common implementations.
Global Configuration
oshi-common/src/main/java/oshi/util/GlobalConfig.java
Added/expanded many public config keys, corrected misspelled Windows PERF keys, introduced @Deprecated aliases for old names, and added/expanded Javadoc for keys.
Windows Perfmon Usage
oshi-core/src/main/java/oshi/driver/windows/perfmon/PerfmonDisabled.java
Updated initialization to read corrected GlobalConfig keys (fixed PERF key constants); behavior unchanged aside from key name corrections.
Core Entry Points Javadoc
oshi-core/src/main/java/oshi/SystemInfo.java, oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
Expanded quick-start examples, memoization/caching notes, platform support and native-access (JEP 472) guidance, and contrasts between JNA and FFM entry points.
CPU & Memory Javadoc
oshi-common/src/main/java/oshi/hardware/CentralProcessor.java, oshi-common/src/main/java/oshi/hardware/GlobalMemory.java, oshi-common/src/main/java/oshi/hardware/VirtualMemory.java
Added CPU usage calculation examples, blocking vs non-blocking guidance, and expanded cross-OS virtual memory semantics; corrected a typo.
Disk / FileStore Correlation
oshi-common/src/main/java/oshi/hardware/HWDiskStore.java, oshi-common/src/main/java/oshi/hardware/HardwareAbstractionLayer.java, oshi-common/src/main/java/oshi/software/os/OSFileStore.java
Documented correlating HWPartition mount points with OSFileStore#getMount() and added cross-references and example lookup code.
Sensors, Network & Processes Javadoc
oshi-common/src/main/java/oshi/hardware/Sensors.java, oshi-common/src/main/java/oshi/hardware/NetworkIF.java, oshi-common/src/main/java/oshi/software/os/OSProcess.java, oshi-common/src/main/java/oshi/software/os/OperatingSystem.java
Clarified sensor availability checks and platform dependencies, clarified NetworkIF#updateAttributes() usage, added per-process CPU snapshot examples and fixed typos.
Tests
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
Skipped name-equality assertion for processes whose JNA name starts with kworker/ when comparing JNA vs FFM process lists.
Changelog
CHANGELOG.md
Added entries for FFM network-stats fix and API documentation improvements (PR references).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 In my burrow I polished each doc line,
Keys aligned like carrots rowed in time,
Ticks, mounts, and mem — all neatly paired,
Old names deprecated, new constants declared,
Hopping happily as the API feels fine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes out-of-scope changes beyond documentation improvements: renamed Windows Perf configuration keys in GlobalConfig, added deprecated aliases, and updated PerfmonDisabled.java to use corrected keys. Separate configuration key corrections and their usages into a distinct PR focused on bug fixes, keeping this PR limited to pure documentation enhancements only.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve API documentation' accurately describes the main focus of this PR, which comprehensively updates Javadocs across multiple files with examples and clarifications.
Linked Issues check ✅ Passed The PR fulfills all coding objectives from issue #2746: expands API documentation with comprehensive details, adds practical code examples for common use cases, clarifies method parameters and return values, includes platform-specific notes, and demonstrates practical usage patterns.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ 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.

@codecov

codecov Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.12%. Comparing base (fee7f6c) to head (8c71296).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3154      +/-   ##
============================================
+ Coverage     61.91%   62.12%   +0.21%     
  Complexity       12       12              
============================================
  Files            39       39              
  Lines          2329     2329              
  Branches        407      407              
============================================
+ Hits           1442     1447       +5     
+ Misses          777      771       -6     
- Partials        110      111       +1     

☔ 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.

@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: 4

🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/util/GlobalConfig.java (1)

154-173: Fix the DIABLED typo before these constants spread.

The new identifiers OSHI_OS_WINDOWS_PERFDISK_DIABLED, OSHI_OS_WINDOWS_PERFOS_DIABLED, and OSHI_OS_WINDOWS_PERFPROC_DIABLED bake a spelling mistake into the constant names. Even though the property values are correct, leaving the typo here makes the API/docs harder to use and creates cleanup debt immediately.

Suggested rename
-    public static final String OSHI_OS_WINDOWS_PERFDISK_DIABLED = "oshi.os.windows.perfdisk.disabled";
+    public static final String OSHI_OS_WINDOWS_PERFDISK_DISABLED = "oshi.os.windows.perfdisk.disabled";
...
-    public static final String OSHI_OS_WINDOWS_PERFOS_DIABLED = "oshi.os.windows.perfos.disabled";
+    public static final String OSHI_OS_WINDOWS_PERFOS_DISABLED = "oshi.os.windows.perfos.disabled";
...
-    public static final String OSHI_OS_WINDOWS_PERFPROC_DIABLED = "oshi.os.windows.perfproc.disabled";
+    public static final String OSHI_OS_WINDOWS_PERFPROC_DISABLED = "oshi.os.windows.perfproc.disabled";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/main/java/oshi/util/GlobalConfig.java` around lines 154 -
173, The three public constant names in
GlobalConfig—OSHI_OS_WINDOWS_PERFDISK_DIABLED, OSHI_OS_WINDOWS_PERFOS_DIABLED,
and OSHI_OS_WINDOWS_PERFPROC_DIABLED—contain a spelling mistake ("DIABLED");
rename them to OSHI_OS_WINDOWS_PERFDISK_DISABLED,
OSHI_OS_WINDOWS_PERFOS_DISABLED, and OSHI_OS_WINDOWS_PERFPROC_DISABLED
respectively, update any Javadoc references and all usages across the codebase
to the new identifiers, and keep the property string values unchanged (they are
already correct) to preserve runtime behavior and compatibility.
🤖 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-common/src/main/java/module-info.java`:
- Around line 11-13: Doc comment incorrectly instructs implementers to override
query*() methods for hardware subclasses; update the text to state that
subclasses of the abstract base classes in oshi.hardware.common (notably
AbstractHardwareAbstractionLayer) should extend via create*() factory methods,
while platform-specific logic remains in the protected abstract query*() methods
on software-side or specific components; change the sentence referencing
"override the {`@code` protected abstract query*()} methods" to explicitly mention
"override the {`@code` create*()} factory methods in
AbstractHardwareAbstractionLayer and override the {`@code` protected abstract
query*()} methods where applicable (e.g., software or component-level
implementations)" so implementers can find the correct hooks.

In `@oshi-common/src/main/java/oshi/hardware/CentralProcessor.java`:
- Around line 153-164: The example initializes prevTicks to zeros which causes
the first getSystemCpuLoadBetweenTicks(prevTicks) sample to be incorrect; change
the sample code in the Javadoc to seed prevTicks with a real snapshot by calling
cpu.getSystemCpuLoadTicks() once before entering the loop (use the
CentralProcessor instance referenced as cpu), then call
getSystemCpuLoadBetweenTicks(prevTicks) inside the loop and update prevTicks
from getSystemCpuLoadTicks() each iteration so the first reported sample
reflects the interval rather than cumulative boot ticks.

In `@oshi-common/src/main/java/oshi/util/GlobalConfig.java`:
- Around line 214-225: The Javadoc security example currently splits the path
across lines to avoid the comment terminator, which prevents the literal
`/proc/*/environ` from rendering; update the Javadoc in GlobalConfig (near the
OSHI_OS_LINUX_PRIVILEGED_PREFIX constant) to use a Javadoc inline tag such as
{`@code` /proc/*/environ} or {`@literal` /proc/*/environ} so the full literal path
appears correctly in generated docs and remove the line split that produces the
broken display.

In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Around line 53-56: Update the class Javadoc for SystemInfo to explicitly
include Android in the supported-platform list (add "Android" alongside Windows,
macOS, Linux, FreeBSD, OpenBSD, Solaris, AIX) and, if helpful for clarity,
mention that PlatformEnum.ANDROID is currently routed through the Linux JNA
implementations used by createOperatingSystem() and createHardware(); reference
SystemInfo, createOperatingSystem(), createHardware(), and PlatformEnum.ANDROID
so readers understand the existing Android routing behavior.

---

Nitpick comments:
In `@oshi-common/src/main/java/oshi/util/GlobalConfig.java`:
- Around line 154-173: The three public constant names in
GlobalConfig—OSHI_OS_WINDOWS_PERFDISK_DIABLED, OSHI_OS_WINDOWS_PERFOS_DIABLED,
and OSHI_OS_WINDOWS_PERFPROC_DIABLED—contain a spelling mistake ("DIABLED");
rename them to OSHI_OS_WINDOWS_PERFDISK_DISABLED,
OSHI_OS_WINDOWS_PERFOS_DISABLED, and OSHI_OS_WINDOWS_PERFPROC_DISABLED
respectively, update any Javadoc references and all usages across the codebase
to the new identifiers, and keep the property string values unchanged (they are
already correct) to preserve runtime behavior and compatibility.
🪄 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: 196e2a1d-d029-4205-81e8-e8fc78b9a90c

📥 Commits

Reviewing files that changed from the base of the PR and between fee7f6c and ea8d11f.

📒 Files selected for processing (16)
  • config/checkstyle.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/hardware/CentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/GlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/HWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/HardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/hardware/NetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/Sensors.java
  • oshi-common/src/main/java/oshi/hardware/VirtualMemory.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/software/os/OSProcess.java
  • oshi-common/src/main/java/oshi/software/os/OperatingSystem.java
  • oshi-common/src/main/java/oshi/util/GlobalConfig.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/package-info.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). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

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

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/HardwareAbstractionLayer.java
  • oshi-common/src/main/java/oshi/software/os/OSProcess.java
  • oshi-common/src/main/java/oshi/hardware/VirtualMemory.java
  • oshi-core/src/main/java/oshi/package-info.java
  • oshi-common/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-common/src/main/java/oshi/hardware/CentralProcessor.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/util/GlobalConfig.java
📚 Learning: 2026-04-05T15:37:17.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:17.867Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/HardwareAbstractionLayer.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/HardwareAbstractionLayer.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/src/main/java/oshi/package-info.java
  • oshi-common/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: The counterintuitive naming of `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` in OSHI (where a higher value means MORE performance and LESS efficiency, so P-cores get higher values than E-cores) is intentionally inherited from Microsoft's `PROCESSOR_RELATIONSHIP.EfficiencyClass` Win32 API: "A core with a higher value for the efficiency class has intrinsically greater performance and less efficiency." OSHI follows this same convention for cross-platform consistency. Do not flag P-cores being assigned higher efficiency values as a bug.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/CentralProcessor.java
🔇 Additional comments (7)
config/checkstyle.xml (1)

48-48: Good checkstyle alignment for Javadoc-heavy changes.

Line [48] correctly enables processJavadoc, which keeps Javadoc @link/@see imports from being treated as unused during this doc-focused PR.

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

299-303: Nice performance guidance for polling patterns.

Lines [299]-[303] clearly distinguish single-interface refresh from multi-interface polling and set the right expectation about full-list queries on many platforms.

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

48-50: Good cross-linking between hardware partitions and file stores.

Lines [48]-[50] improve discoverability of the disk-partition-to-filesystem mapping workflow.

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

10-40: Solid documentation expansion with actionable example.

Lines [18]-[40] give a clear partition-to-mount correlation path, and Line [10] correctly supports the new OSFileStore references.

oshi-common/src/main/java/oshi/software/os/OperatingSystem.java (1)

163-168: Good API docs update for process filtering/sorting usage.

Lines [163]-[168] provide a practical snippet, and Line [171] now points to the correct ProcessFiltering constants.

Also applies to: 171-171, 175-175

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

10-29: Great cross-platform clarification of virtual-memory semantics.

Lines [10]-[29] set correct expectations for interpreting getVirtualMax() and getVirtualInUse() across OSes.

oshi-common/src/main/java/oshi/software/os/OSFileStore.java (1)

8-9: Nice bidirectional doc linkage for storage mapping.

Lines [15]-[21] clearly connect OSFileStore#getMount() with HWPartition#getMountPoint(), and Lines [8]-[9] correctly support those references.

Also applies to: 15-21

Comment on lines +153 to +164
* This is the recommended approach for non-blocking periodic monitoring. Store the tick array from one call and
* pass it on the next iteration:
*
* <pre>{@code
* long[] prevTicks = new long[TickType.values().length];
* while (monitoring) {
* double load = cpu.getSystemCpuLoadBetweenTicks(prevTicks);
* prevTicks = cpu.getSystemCpuLoadTicks();
* System.out.printf("CPU: %.1f%%%n", load * 100);
* Thread.sleep(1000);
* }
* }</pre>

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.

⚠️ Potential issue | 🟡 Minor

Seed prevTicks with a real snapshot before the loop.

Lines 157-160 initialize prevTicks to zeros, so the first call returns a cumulative value from boot/current ticks rather than usage over the sampling interval this example is describing. That makes the copy-paste example produce a bogus first sample.

Suggested doc fix
- * long[] prevTicks = new long[TickType.values().length];
- * while (monitoring) {
- *     double load = cpu.getSystemCpuLoadBetweenTicks(prevTicks);
- *     prevTicks = cpu.getSystemCpuLoadTicks();
+ * long[] prevTicks = cpu.getSystemCpuLoadTicks();
+ * while (monitoring) {
+ *     Thread.sleep(1000);
+ *     long[] ticks = cpu.getSystemCpuLoadTicks();
+ *     double load = cpu.getSystemCpuLoadBetweenTicks(prevTicks, ticks);
+ *     prevTicks = ticks;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/main/java/oshi/hardware/CentralProcessor.java` around lines
153 - 164, The example initializes prevTicks to zeros which causes the first
getSystemCpuLoadBetweenTicks(prevTicks) sample to be incorrect; change the
sample code in the Javadoc to seed prevTicks with a real snapshot by calling
cpu.getSystemCpuLoadTicks() once before entering the loop (use the
CentralProcessor instance referenced as cpu), then call
getSystemCpuLoadBetweenTicks(prevTicks) inside the loop and update prevTicks
from getSystemCpuLoadTicks() each iteration so the first reported sample
reflects the interval rather than cumulative boot ticks.

Comment on lines +214 to +225
* A comma-separated list of file paths eligible for privileged read via {@code sudo cat} fallback on Linux when
* normal file read fails due to permissions. Supports Java glob patterns ({@code *}, {@code ?}, {@code [abc]}).
* <p>
* <b>Security warning:</b> Take care when adding paths. Allowing privileged reads of sensitive files such as
* {@code /proc/*
/
environ} can expose credentials to unprivileged users. Default is the empty
*
* string (no files allowed).
*
* @see #OSHI_OS_LINUX_PRIVILEGED_PREFIX
*/

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.

⚠️ Potential issue | 🟡 Minor

Render /proc/*/environ as the literal path in the warning.

Splitting the example path across lines avoids the */ terminator in source, but it also means the generated Javadoc will not show the actual /proc/*/environ path cleanly. For a security warning, that makes the example less clear than it should be.

Suggested Javadoc-safe formatting
-     * <b>Security warning:</b> Take care when adding paths. Allowing privileged reads of sensitive files such as
-     * {`@code` /proc/*
-     /
-    environ} can expose credentials to unprivileged users. Default is the empty
-     *
-     * string (no files allowed).
+     * <b>Security warning:</b> Take care when adding paths. Allowing privileged reads of sensitive files such as
+     * {`@code` /proc/}{`@literal` *}{`@code` /environ} can expose credentials to unprivileged users. Default is the empty
+     * string (no files allowed).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* A comma-separated list of file paths eligible for privileged read via {@code sudo cat} fallback on Linux when
* normal file read fails due to permissions. Supports Java glob patterns ({@code *}, {@code ?}, {@code [abc]}).
* <p>
* <b>Security warning:</b> Take care when adding paths. Allowing privileged reads of sensitive files such as
* {@code /proc/*
/
environ} can expose credentials to unprivileged users. Default is the empty
*
* string (no files allowed).
*
* @see #OSHI_OS_LINUX_PRIVILEGED_PREFIX
*/
* A comma-separated list of file paths eligible for privileged read via {`@code` sudo cat} fallback on Linux when
* normal file read fails due to permissions. Supports Java glob patterns ({`@code` *}, {`@code` ?}, {`@code` [abc]}).
* <p>
* <b>Security warning:</b> Take care when adding paths. Allowing privileged reads of sensitive files such as
* {`@code` /proc/}{`@literal` *}{`@code` /environ} can expose credentials to unprivileged users. Default is the empty
* string (no files allowed).
*
* `@see` `#OSHI_OS_LINUX_PRIVILEGED_PREFIX`
*/
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/main/java/oshi/util/GlobalConfig.java` around lines 214 -
225, The Javadoc security example currently splits the path across lines to
avoid the comment terminator, which prevents the literal `/proc/*/environ` from
rendering; update the Javadoc in GlobalConfig (near the
OSHI_OS_LINUX_PRIVILEGED_PREFIX constant) to use a Javadoc inline tag such as
{`@code` /proc/*/environ} or {`@literal` /proc/*/environ} so the full literal path
appears correctly in generated docs and remove the line split that produces the
broken display.

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.

Improvement of API Documentation

1 participant