Skip to content

Triage Error Prone EnumOrdinal warnings - #3598

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:triage-enum-ordinal-warnings
Aug 12, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:triage-enum-ordinal-warnings

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • AixCentralProcessor.ticksFromRow used TickType.ordinal() where TickType.getIndex() (already used everywhere else, e.g. CpuStat) is the intended stable index — real fix, no behavior change since the values are currently identical by construction.
  • The remaining EnumOrdinal findings are self-contained lookup tables (UdevStat, ProcPidStat, ThreadPidStat — private enums whose ordinal only indexes a same-sized array built by the same class) or documented native-order contracts (PlatformEnum's declaration order matching JNA's Platform.getOSType(), PdhCounterWildcardProperty's "first enum element is the instance filter" contract, ProcessorCache.Type's declaration-order sort weight). Suppressed with @SuppressWarnings("EnumOrdinal") plus a one-line comment explaining why, scoped to the narrowest enclosing method (two static-initializer sites were refactored into small private builder methods since a static block can't itself carry an annotation).
  • Found and fixed a latent bug along the way: LogicalProcessorInformation (JNA) indexed ProcessorCache.Type with Type.values()[cache.type] and no bounds check, so an unexpected native cache-type value would throw ArrayIndexOutOfBoundsException. Its FFM twin already guards this with a bounds check + UNIFIED fallback; brought JNA in line with it.

Test plan

  • ./mvnw clean install -Perror-prone -DskipTests: 0 ERROR, EnumOrdinal findings 39 → 0, total WARNING count 223 → 184 (matches)
  • ./mvnw -pl oshi-common,oshi-core,oshi-core-ffm -am test: 0 tests failed
  • ./mvnw checkstyle:check, forbiddenapis:check, javadoc:javadoc: all pass

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows cache detection by safely handling invalid cache type values, preventing processing failures.
    • Preserved accurate CPU tick calculations on AIX systems.
  • Refactor

    • Improved internal platform statistics mapping and validation without changing expected behavior.
  • Documentation

    • Added clarifying documentation for platform-specific hardware and performance counter mappings.

AixCentralProcessor's ticksFromRow used TickType.ordinal() where the
existing TickType.getIndex() is the intended stable index. Fixed.

The rest are self-contained lookup tables or documented native-order
contracts (PlatformEnum matching JNA's Platform.getOSType(), PDH
property enums' first-element-is-instance-filter convention, cache
Type sort weighting) where declaration order is intentional; suppressed
with a comment explaining why.

Also fixed a latent bug found along the way: LogicalProcessorInformation
(JNA) indexed ProcessorCache.Type by a raw native cache-type int with no
bounds check, unlike its FFM twin which already guards it with a
fallback to UNIFIED.
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e3fc757-dd73-4972-a755-42748f1497c5

📥 Commits

Reviewing files that changed from the base of the PR and between 31efc66 and 472e65d.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (11)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
🧰 Additional context used
📓 Path-based instructions (9)
oshi-common/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-common/src/main/java/**/*.java: Keep oshi-common pure Java 8: do not reference JNA, FFM, System.load, or System.loadLibrary; shared parsing, conversion, filtering, caching, and sentinel/range logic belongs here.
Before adding a parsing helper, check oshi.util.ParseUtil; put reusable number, size, frequency, hexadecimal, delimited-field, and date parsing there.
Do not import com.sun.jna, java.lang.foreign, or use System.load/System.loadLibrary in oshi-common.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/*.java: Do not use banned numeric parsing APIs such as Integer.parseInt, Long.parseLong, Double.parseDouble, or Integer.decode; use the appropriate oshi.util.ParseUtil method.
New classes should declare an appropriate concurrency annotation such as @ThreadSafe, @Immutable, @NotThreadSafe, or @GuardedBy, matching the modeled class where applicable.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
**/*.{java,md}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{java,md}: When changing a JNA or FFM implementation, apply the equivalent behavior change to its counterpart, or document why the implementations intentionally differ; prefer hoisting non-native-specific logic into oshi-common.
Use current-year-only copyright headers for new files (Copyright 2026 The OSHI Project Contributors and SPDX-License-Identifier: MIT); do not commit generated output, target/, or IDE files.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
**/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/main/java/**/*.java: Every public and protected type and method needs valid Javadoc; use imported simple class names rather than fully qualified names, including in {@link} tags.
Memoize constant or expensive, slowly changing native-call results using oshi.util.Memoizer, following the surrounding class and defaultExpiration() conventions.
Prefer native calls for system information; on Linux prefer FileUtil for /proc and /sys, while ExecutingCommand is acceptable on other platforms when native APIs do not expose the data.
Verify native struct offsets, field widths, and sysctl/ioctl constants against the target OS and architecture; do not infer them from another operating system.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
**/*.{java,xml}

📄 CodeRabbit inference engine (AGENTS.md)

Do not add line-range Checkstyle suppressions. Prefer declaration-level @SuppressWarnings, scoped Checkstyle comments, or file/package suppressions without line ranges; use Sonar @SuppressWarnings("java:Sxxxx") where possible and keep statement-level suppression comments short and justified.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
oshi-core/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

Use Java 8-compatible language features in oshi-core; do not use var, List.of, records, switch expressions, text blocks, or Stream.toList().

Files:

  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
oshi-core-ffm/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

Do not reference com.sun.jna from oshi-core-ffm.

Files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
**/src/test/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

Write tests against parsing methods that accept fixture data such as List<String> or String, rather than requiring native calls or file/command acquisition.

Files:

  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
**/src/test/java/**/*Test.java

📄 CodeRabbit inference engine (AGENTS.md)

Tests must assert invariants such as non-null values, types, ordering, and plausible ranges rather than hardware-specific values; zero and empty results are valid, and timing-sensitive live readings should not be compared directly.

Files:

  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
🧠 Learnings (27)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:48.200Z
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-07-28T18:20:41.673Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 0
File: :0-0
Timestamp: 2026-07-28T18:20:41.673Z
Learning: In `oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java`, `MacCentralProcessor.initProcessorCounts()` constructs every `PhysicalProcessor` with a non-null ID string: an absent IORegistry `compatible` property is normalized to `""`. Therefore, the production call `MacCentralProcessor.deriveMicroarchitecture(getPhysicalProcessors())` may safely call `PhysicalProcessor#getIdString()` without a null guard.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
📚 Learning: 2026-07-26T23:06:49.011Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3530
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:43-48
Timestamp: 2026-07-26T23:06:49.011Z
Learning: In the oshi/oshi repository, `oshi.util.ExceptionUtil` is intentionally outside the binary-compatibility surface: japicmp enforces compatibility only for types annotated `oshi.annotation.PublicApi`, and `ExceptionUtil` is not annotated. Therefore, do not flag in-place public method descriptor changes in `ExceptionUtil` merely because precompiled third-party callers could receive `NoSuchMethodError`; source compatibility and lockstep module releases are the applicable expectations. If this guarantee is desired later, annotating `ExceptionUtil` with `PublicApi` is the policy mechanism rather than adding numerous forwarding overloads.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 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/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.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: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
📚 Learning: 2026-04-03T18:44:48.200Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:48.200Z
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-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.java
📚 Learning: 2026-08-05T23:44:09.936Z
Learnt from: CR
Repo: oshi/oshi PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-08-05T23:44:09.936Z
Learning: Applies to **/*.{java,md} : When changing a JNA or FFM implementation, apply the equivalent behavior change to its counterpart, or document why the implementations intentionally differ; prefer hoisting non-native-specific logic into `oshi-common`.

Applied to files:

  • oshi-common/src/main/java/oshi/util/PlatformEnum.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-common/src/main/java/oshi/util/PlatformEnum.java
  • oshi-common/src/test/java/oshi/util/PlatformEnumTest.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/util/PlatformEnum.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
📚 Learning: 2026-04-18T22:53:56.149Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:56.149Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 Learning: 2026-04-12T19:34:59.050Z
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:59.050Z
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-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
📚 Learning: 2026-04-17T23:56:46.416Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:46.416Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 Learning: 2026-04-17T23:43:35.860Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:35.860Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.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-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 Learning: 2026-04-18T23:21:43.993Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:43.993Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
📚 Learning: 2026-05-04T04:58:36.843Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3227
File: oshi-metrics/src/main/java/oshi/metrics/OshiMetrics.java:35-48
Timestamp: 2026-05-04T04:58:36.843Z
Learning: In `oshi-metrics/src/main/java/oshi/metrics/OshiMetrics.java`, the `private final OperatingSystem os` field is intentionally stored in the constructor even though it is not yet used. It is a placeholder for future OS-level metrics (e.g., process metrics) that will be added incrementally. Do not flag it as dead code.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
📚 Learning: 2026-05-31T04:49:19.668Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3310
File: oshi-core/src/main/java/oshi/software/os/unix/netbsd/NetBsdOperatingSystem.java:164-166
Timestamp: 2026-05-31T04:49:19.668Z
Learning: In the oshi/oshi project, the NetBSD platform intentionally removes all JNA/native library dependencies (PR `#3310`). `NetBsdOperatingSystem.getThreadId()` uses `(int) Thread.currentThread().getId()` rather than `NetBsdLibc._lwp_self()` because the JNA native library is not bundled with the Maven dependency for the NetBSD platform. The mismatch between Java thread ids and kernel LWP ids is an accepted trade-off. Do not suggest reintroducing JNA-based calls (such as `NetBsdLibc._lwp_self()`) in NetBSD platform code.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
📚 Learning: 2026-06-26T09:54:54.556Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3410
File: oshi-common/src/main/java/oshi/software/common/os/linux/LinuxFileSystem.java:293-297
Timestamp: 2026-06-26T09:54:54.556Z
Learning: In `oshi-common/src/main/java/oshi/software/common/os/linux/LinuxFileSystem.java`, for the NFS reachability pre-probe added in PR `#3410`, a fixed thread-pool cap of 16 is considered a sane limit and does not warrant a stronger refactor solely to guarantee a universal 2-second bound. Future reviews should focus on keeping the Javadoc/comments aligned with the actual bounded-parallel behavior rather than insisting on an unbounded-concurrency implementation.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.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-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
📚 Learning: 2026-04-05T05:39:21.126Z
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:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
🔇 Additional comments (10)
oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java (1)

79-82: LGTM!

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

412-413: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java (1)

281-288: LGTM!

oshi-common/src/main/java/oshi/util/PlatformEnum.java (1)

142-144: LGTM!

oshi-common/src/test/java/oshi/util/PlatformEnumTest.java (1)

40-41: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java (1)

131-133: LGTM!

oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java (1)

237-239: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java (1)

78-87: LGTM!

Also applies to: 143-144

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

58-69: LGTM!

Also applies to: 332-333

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

24-35: LGTM!

Also applies to: 54-56


📝 Walkthrough

Walkthrough

The changes document intentional enum ordinal usage, replace AIX ordinal lookups with explicit indexes, centralize Linux lookup-table construction, and add fallback handling for invalid Windows cache type values.

Changes

Ordinal indexing and cache validation

Layer / File(s) Summary
Enum index contracts and mappings
oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java, oshi-common/src/main/java/oshi/util/PlatformEnum.java, oshi-common/src/test/java/oshi/util/PlatformEnumTest.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfCounterWildcardQueryFFM.java, oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java
Intentional ordinal usage is documented and suppressed. AIX tick mapping uses TickType.getIndex().
Linux lookup-table builders
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java, oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSThread.java
Linux statistic lookup arrays are built by helper methods. Ordinal-based parsed-array access is documented and suppressed.
Windows cache type validation
oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java
Invalid native cache type indexes now use Type.UNIFIED instead of causing an array-index failure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to 472e6

The changes address enum-index warnings and add a defensive native-value fallback, with the listed validation checks passing; no actionable merge-blocking risk remains beyond normal checks and review.

Possibly related PRs

  • oshi/oshi#3595: Addresses related Error Prone suppressions and enum ordinal indexing findings.

Poem

A bunny checks each enum line,
Keeps ordinal paths in order fine.
Linux tables bloom from builders neat,
AIX ticks find indexes sweet.
Bad cache types choose unified cheer—
Clean warnings hop away from here! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: triaging Error Prone EnumOrdinal warnings.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.81%. Comparing base (31efc66) to head (472e65d).

Files with missing lines Patch % Lines
.../common/platform/unix/aix/AixCentralProcessor.java 0.00% 7 Missing ⚠️
...hi/driver/windows/LogicalProcessorInformation.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3598      +/-   ##
============================================
- Coverage     79.90%   79.81%   -0.09%     
+ Complexity     3864      217    -3647     
============================================
  Files           710      710              
  Lines         24249    24256       +7     
  Branches       4056     4057       +1     
============================================
- Hits          19376    19361      -15     
- Misses         2715     2734      +19     
- Partials       2158     2161       +3     
Flag Coverage Δ
freebsd 33.46% <0.00%> (-0.02%) ⬇️
linux 37.57% <59.09%> (+0.02%) ⬆️
macos 38.38% <0.00%> (-0.05%) ⬇️
openbsd 32.64% <0.00%> (-0.01%) ⬇️
solaris 34.12% <0.00%> (-0.02%) ⬇️
windows 45.35% <4.54%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

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

@dbwiddis
dbwiddis merged commit df19c9e into oshi:master Aug 12, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the triage-enum-ordinal-warnings branch August 12, 2026 22:14
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