Skip to content

Fix all Error Prone StringSplitter findings, fix silent -Xmaxwarns truncation - #3597

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:triage-error-prone-warnings
Aug 12, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:triage-error-prone-warnings

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-on to #3594/#3595/#3596 (Error Prone groundwork). Requested triage of the WARNING-severity backlog by category, starting with the two the user specifically flagged: javadoc (MissingSummary, deferred to a follow-on PR) and StringSplitter (this PR).

Important correction discovered while gathering baseline numbers: javac defaults -Xmaxwarns to 100 per module. Error Prone's findings are javac warnings, so oshi-common (117+ findings) was silently truncating everything past the 100th with no indication anything was dropped. Every category count from the original triage was an undercount because of this - StringSplitter alone was 142 findings, not the 55 originally visible. Set -Xmaxwarns to a large value in the error-prone profile so the full picture is always visible going forward; this also revealed two previously-invisible categories (EffectivelyPrivate, InvalidInlineTag) and grew others substantially (OperatorPrecedence 4→29, EnumOrdinal 17→39, MissingSummary 33→41).

StringSplitter (142/142 fixed)

Most sites are String.split(regex) with no explicit limit, which silently drops trailing empty strings - passing -1 preserves them, satisfying the check. Each site was reviewed individually rather than applying -1 uniformly, since -1 is not a universally-safe substitute for the implicit 0 limit when a caller indexes the split result from the end or checks an exact length:

  • Sites indexing the first element ([0]) or the element right after a marker ([1]) are unaffected by -1, or in the marker case actively benefit: a marker as the very last text on a line no longer throws ArrayIndexOutOfBoundsException, it now returns an empty string.
  • Sites indexing from the end (length-1, length==N checks) only get -1 where the input was already trimmed first or had an explicit isEmpty() guard, eliminating the trailing-whitespace case -1 would otherwise affect.
  • Four sites (LinuxOSProcess.parseAffinityMask, AixFileSystem's inode parsing, SolarisOSProcess's affinity parsing, and the shared ParseUtil.parseLastString) needed an explicit .trim() added alongside -1, since blindly adding -1 there would have silently turned a correctly-parsed value into a wrong default (0) on trailing whitespace - exactly the regression risk with treating -1 as a universal fix.
  • A handful of == 2 exact-length checks (AbstractGlobalMemory, MacGlobalMemory, ProcUtil.parseStatistics) now capture a key with an explicit empty value instead of silently dropping the line, matching existing precedent elsewhere in the codebase for this shape.

JNA/FFM twins (SolarisCentralProcessor, MacOperatingSystem, MacOSProcess, WindowsFileSystem) were fixed identically on both sides.

No CHANGELOG entry for the lint-motivated changes; the ArrayIndexOutOfBoundsException-prevention and ParseUtil.parseLastString hardening are edge-case fixes on malformed native output, not something normal use should encounter.

Next steps (not this PR)

  • Triage the remaining WARNING categories (MissingSummary, EnumOrdinal, OperatorPrecedence, MixedMutabilityReturnType, etc.) now that the true counts are visible.

Test plan

  • ./mvnw clean install -DskipTests -Perror-prone: StringSplitter count 142 → 0, BUILD SUCCESS
  • ./mvnw test (whole reactor): 1558 tests, 0 failures
  • ./mvnw clean spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check javadoc:javadoc: full gate clean, no reformatting needed beyond spotless's own line-wrapping of a few added -1 arguments

Summary by CodeRabbit

  • Bug Fixes
    • Improved system, hardware, network, storage, process, and filesystem information parsing across Linux, BSD, Solaris, AIX, macOS, and Windows.
    • Correctly handles missing values, trailing whitespace, empty fields, repeated delimiters, and values containing additional separators.
    • Improved reliability when reading operating-system command output and system configuration data.
  • Tests
    • Added regression coverage for trailing whitespace and incomplete parsed values.
  • Chores
    • Expanded compiler analysis limits so more warnings are reported during builds.

…rest

javac defaults -Xmaxwarns to 100 per module; Error Prone's findings are
javac warnings, so oshi-common (117+ findings) was silently truncating
everything past the 100th with no indication anything was dropped. Every
category count from the prior triage was an undercount because of this -
StringSplitter alone was 142 findings, not the 55 originally visible.
Set -Xmaxwarns to a large value in the error-prone profile so the full
picture is always visible going forward.

Fixes all 142 StringSplitter findings. Most are String.split(regex) with
no explicit limit, which silently drops trailing empty strings - passing
-1 preserves them, satisfying the check. Reviewed each site individually
rather than applying -1 uniformly:

- Sites indexing the first element ([0]) or the element right after a
  marker ([1]) are unaffected, or in the marker case actively benefit:
  a marker as the very last text on a line no longer throws
  ArrayIndexOutOfBoundsException, it now returns an empty string.
- Sites indexing from the end (length-1, length==N checks) only get -1
  where the input was already trimmed first or had an explicit isEmpty()
  guard, eliminating the trailing-whitespace case -1 would otherwise
  affect. Three sites (LinuxOSProcess.parseAffinityMask,
  AixFileSystem's inode parsing, SolarisOSProcess's affinity parsing,
  and the shared ParseUtil.parseLastString) needed an explicit .trim()
  added alongside -1, since blindly adding -1 there would have silently
  turned a correctly-parsed value into a wrong default on trailing
  whitespace - exactly the regression risk with treating -1 as a
  universal fix.
- A handful of "== 2" exact-length checks (AbstractGlobalMemory,
  MacGlobalMemory, ProcUtil.parseStatistics) now capture a key with an
  explicit empty value instead of silently dropping the line, matching
  existing precedent elsewhere in the codebase for this shape.

No CHANGELOG entry for the lint-motivated changes; the AIOOBE-prevention
and ParseUtil.parseLastString hardening are edge-case fixes on malformed
native output, not something normal use should encounter.
@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: 0cc07a31-e6e1-42d3-aa2c-a0a4b31a019a

📥 Commits

Reviewing files that changed from the base of the PR and between c3d9bf1 and 3eb2e07.

📒 Files selected for processing (2)
  • oshi-common/src/main/java/oshi/util/ProcUtil.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
🧰 Additional context used
📓 Path-based instructions (5)
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/util/ProcUtil.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/util/ProcUtil.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/util/ProcUtil.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/util/ProcUtil.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/util/ProcUtil.java
🧠 Learnings (6)
📚 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 oshi-common/src/main/java/**/*.java : Before adding a parsing helper, check `oshi.util.ParseUtil`; put reusable number, size, frequency, hexadecimal, delimited-field, and date parsing there.

Applied to files:

  • oshi-common/src/main/java/oshi/util/ProcUtil.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 : 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.

Applied to files:

  • oshi-common/src/main/java/oshi/util/ProcUtil.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/util/ProcUtil.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/util/ProcUtil.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/util/ProcUtil.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/util/ProcUtil.java
🔇 Additional comments (1)
oshi-common/src/main/java/oshi/util/ProcUtil.java (1)

129-143: LGTM!


📝 Walkthrough

Walkthrough

The change updates split operations across OS-specific drivers, hardware and software parsers, shared utilities, native bindings, tests, and build configuration. Most splits now preserve trailing empty fields. Some metadata parsers split only at the first delimiter.

Changes

Split preservation

Layer / File(s) Summary
Platform driver and hardware parsers
oshi-common/src/main/java/oshi/driver/..., oshi-common/src/main/java/oshi/hardware/common/...
Driver and hardware parsers preserve trailing fields and values after delimiters.
Operating-system parser updates
oshi-common/src/main/java/oshi/software/common/...
Network, cgroup, filesystem, process, service, route, and metric parsers retain empty fields.
Shared utility and proc parsing
oshi-common/src/main/java/oshi/util/...
Shared utilities and procfs parsers preserve empty split results. ProcUtil adds list-based parsing.
Bindings and validation
oshi-core*/src/main/java/..., pom.xml, oshi-common/src/test/...
FFM and JNA parsers preserve split fields. Windows provider parsing handles trailing separators. Tests cover trailing whitespace. The Error Prone profile raises the javac warning limit.

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

Poem

A rabbit checks each split with care,
Empty fields remain there.
Colons stop where values end,
Trailing spaces now behave as planned.
Across each platform, tokens align—
Small parser changes, clean and fine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.81% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly summarizes both primary changes: fixing StringSplitter findings and increasing the warning limit to prevent truncation.
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 81.39535% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.78%. Comparing base (c4a278c) to head (3eb2e07).

Files with missing lines Patch % Lines
...main/java/oshi/util/driver/linux/proc/CpuStat.java 61.53% 0 Missing and 5 partials ⚠️
...oshi/software/os/windows/WindowsFileSystemFFM.java 0.00% 5 Missing ⚠️
...oshi/software/os/windows/WindowsFileSystemJNA.java 0.00% 5 Missing ⚠️
...c/main/java/oshi/driver/common/unix/aix/Lscfg.java 40.00% 3 Missing ⚠️
...e/common/os/unix/netbsd/NetBsdOperatingSystem.java 0.00% 3 Missing ⚠️
...va/oshi/software/os/mac/MacOperatingSystemJNA.java 0.00% 3 Missing ⚠️
...common/platform/unix/netbsd/NetBsdHWDiskStore.java 0.00% 2 Missing ⚠️
...e/common/platform/unix/netbsd/NetBsdNetworkIF.java 0.00% 2 Missing ⚠️
...on/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java 0.00% 2 Missing ⚠️
...e/common/platform/linux/LinuxCentralProcessor.java 90.00% 1 Missing ⚠️
... and 9 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3597      +/-   ##
============================================
- Coverage     79.92%   79.78%   -0.15%     
- Complexity     3870     4214     +344     
============================================
  Files           710      710              
  Lines         24242    24249       +7     
  Branches       4052     4056       +4     
============================================
- Hits          19376    19347      -29     
- Misses         2711     2742      +31     
- Partials       2155     2160       +5     
Flag Coverage Δ
freebsd 33.47% <63.72%> (-0.03%) ⬇️
linux 37.56% <67.90%> (-0.06%) ⬇️
macos 38.39% <57.67%> (-0.09%) ⬇️
openbsd 32.66% <59.53%> (-0.01%) ⬇️
solaris 34.13% <58.13%> (-0.04%) ⬇️
windows 45.34% <56.27%> (-0.07%) ⬇️

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.

@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 (2)
oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuStat.java (1)

51-59: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Rework length checks after preserving trailing fields.

split(..., -1) preserves trailing empty tokens. In parseSystemCpuLoadTicks and parseProcessorCpuLoadTicks, "cpu 1 2 " passes the current guard although the required IDLE value is missing. Validate the required numeric token and allow an optional trailing empty token.

In parseContextSwitches, "ctxt 987654 " has three tokens and fails == 2. Validate token 1 and ignore trailing empty tokens.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuStat.java` around
lines 51 - 59, Update parseSystemCpuLoadTicks and parseProcessorCpuLoadTicks to
validate that the token at TickType.IDLE is a valid required numeric value,
while permitting one trailing empty token from split(..., -1). Update
parseContextSwitches to validate token 1 and ignore trailing empty tokens
instead of requiring exactly two tokens.
oshi-common/src/main/java/oshi/util/ProcUtil.java (1)

132-140: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Trim statistics lines before splitting.

When a statistics line ends with whitespace, separator.split(line, -1) adds an empty field, so the parts.length == 2 check discards the record. Trim line before splitting and add a trailing-whitespace test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/util/ProcUtil.java` around lines 132 - 140,
Update the statistics-line parsing around separator.split in ProcUtil to trim
trailing whitespace from line before splitting, and add a test covering a line
with trailing whitespace to ensure it still produces exactly two fields and is
stored in result.
🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java (1)

256-256: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update the token-count comment for split("\\D+", -1).

A nonnumeric final limit now produces a trailing empty token. It does not produce fewer tokens. Update the comment so it matches the implementation and keeps the parseLongOrDefault fallback clear.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java`
at line 256, Update the comment adjacent to the split call in SolarisOSProcess
so it accurately states that a nonnumeric final limit creates a trailing empty
token rather than reducing the token count, and clarify how this supports the
parseLongOrDefault fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxFirmware.java`:
- Line 134: Update the copyright parsing in LinuxFirmware to trim trailing
whitespace from vcgencmd.get(1) before splitting, ensuring the final token
contains the manufacturer instead of an empty value. Add a trailing-whitespace
fixture in LinuxFirmwareTest covering this case.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGlobalMemory.java`:
- Around line 96-97: Update both key/value parsers in MacGlobalMemory to use a
bounded split with a maximum of two parts when parsing system_profiler lines.
Preserve values containing additional colons by splitting only at the first
colon, and keep the existing split.length == 2 handling.

In
`@oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java`:
- Around line 291-294: Update the provider-path parsing in
WindowsFileSystemFFM.java lines 291-294 and WindowsFileSystemJNA.java lines
239-242 to select the last non-empty component of volume, including when
PROVIDERNAME ends with a backslash. Preserve the existing description update
behavior while ignoring trailing empty split tokens in both implementations.

---

Outside diff comments:
In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuStat.java`:
- Around line 51-59: Update parseSystemCpuLoadTicks and
parseProcessorCpuLoadTicks to validate that the token at TickType.IDLE is a
valid required numeric value, while permitting one trailing empty token from
split(..., -1). Update parseContextSwitches to validate token 1 and ignore
trailing empty tokens instead of requiring exactly two tokens.

In `@oshi-common/src/main/java/oshi/util/ProcUtil.java`:
- Around line 132-140: Update the statistics-line parsing around separator.split
in ProcUtil to trim trailing whitespace from line before splitting, and add a
test covering a line with trailing whitespace to ensure it still produces
exactly two fields and is stored in result.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java`:
- Line 256: Update the comment adjacent to the split call in SolarisOSProcess so
it accurately states that a nonnumeric final limit creates a trailing empty
token rather than reducing the token count, and clarify how this supports the
parseLongOrDefault fallback.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c912e86-0451-42e6-abd9-6f9185bc1ece

📥 Commits

Reviewing files that changed from the base of the PR and between c4a278c and db7e2a6.

📒 Files selected for processing (93)
  • oshi-common/src/main/java/oshi/driver/common/unix/aix/Lscfg.java
  • oshi-common/src/main/java/oshi/driver/common/unix/aix/Lspv.java
  • oshi-common/src/main/java/oshi/driver/common/unix/bsd/Systat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/bsd/disk/Disklabel.java
  • oshi-common/src/main/java/oshi/driver/common/unix/freebsd/disk/GeomDiskList.java
  • oshi-common/src/main/java/oshi/driver/common/unix/freebsd/disk/GeomPartList.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Iostat.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxLogicalVolumeGroup.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdUsbDevice.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/CupsPrinter.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixComputerSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdComputerSystem.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdGraphicsCard.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdVirtualMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroup.java
  • oshi-common/src/main/java/oshi/software/common/AbstractNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxInternetProtocolStats.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/aix/AixOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/util/EdidUtil.java
  • oshi-common/src/main/java/oshi/util/FileSystemUtil.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/util/PrivilegedUtil.java
  • oshi-common/src/main/java/oshi/util/ProcUtil.java
  • oshi-common/src/main/java/oshi/util/UserGroupInfo.java
  • oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/dragonflybsd/ProcstatUtil.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/netbsd/FstatUtil.java
  • oshi-common/src/main/java/oshi/util/driver/linux/Dmidecode.java
  • oshi-common/src/main/java/oshi/util/driver/linux/Lshw.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuInfo.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuStat.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/DiskStats.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/ProcessStat.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Xwininfo.java
  • oshi-common/src/test/java/oshi/driver/common/unix/bsd/disk/DisklabelTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/solaris/SolarisCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • pom.xml

Addresses CodeRabbit findings on the StringSplitter fix, all confirmed
against current code before changing anything:

- LinuxFirmware.queryVcGenCmd: trim the copyright line before splitting,
  so a trailing-whitespace line finds the real manufacturer token
  instead of falling back to UNKNOWN via the isEmpty() guard.
- AbstractGlobalMemory/MacGlobalMemory: bound the key/value split to 2
  parts instead of unlimited, so a value containing a colon (e.g. a hex
  serial number) isn't split further and silently dropped by the
  length==2 check.
- WindowsFileSystemFFM/JNA: search backward for the last non-empty
  volume-path component instead of only checking the absolute last
  element, so a trailing backslash in PROVIDERNAME doesn't leave the
  description unset.
- CpuStat: the length<=IDLE.getIndex() guards (both tick-parsing
  methods) discount a trailing empty token before checking, so a
  genuinely truncated line (missing real fields) can't have a phantom
  empty token count as one, which previously caused a partially
  fabricated tick array instead of the safe all-zero fallback.
  parseContextSwitches loosened length==2 to >=2 for the same reason,
  without the fabrication risk since it only reads index 1.
- ProcUtil.parseStatistics: trim the line before splitting, so a
  trailing-whitespace line still produces exactly two fields instead of
  being silently dropped entirely by the length==2 check.
- SolarisOSProcess: corrected a comment that described the wrong
  mechanism (said "fewer tokens", actually produces a trailing empty
  token that parseLongOrDefault gracefully defaults on).

Given how many of these turned out to be real, did a systematic re-audit
of every touched file rather than trusting the original per-site review:
grepped for every exact length==N check, every length threshold check
paired with an independently-bounded loop (the CpuStat shape), and every
length-1 end-index, then verified each against its actual input (trimmed
already? guarded already? exception-caught?). Found and fixed the above;
confirmed the remainder fall into one of: already trimmed before the
split, already guarded, exception-caught with an identical outcome
either way, or unrelated to this change (native arrays, byte arrays,
untouched pre-existing code with an explicit positive limit already).

Added a trailing-whitespace fixture to LinuxFirmwareTest and a new
ProcUtilsTest covering the same for parseStatistics.

@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 (1)
oshi-common/src/test/java/oshi/util/ProcUtilsTest.java (1)

77-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Use fixture data at the parser boundary.

ProcUtil.parseStatistics(procFile.toString()) treats the value as a path and calls FileUtil.readFile, so this test depends on filesystem acquisition.

If no fixture-data overload exists, extract the parsing loop into a package-private method that accepts List<String>. Test that method with the trailing-whitespace line as an in-memory fixture.

As per coding guidelines: **/src/test/java/**/*.java requires tests to use parsing methods that accept fixture data such as List<String> or String, rather than requiring native calls or file/command acquisition. Based on learnings: the same repository rule applies to these parser tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/test/java/oshi/util/ProcUtilsTest.java` around lines 77 - 87,
Update testParseStatisticsWithTrailingWhitespace to exercise the parser with
in-memory fixture data instead of a temporary file and path-based
ProcUtil.parseStatistics. If no suitable overload exists, extract the parsing
loop into a package-private ProcUtil method accepting List<String>, then pass
the trailing-whitespace line directly to that method while preserving the
existing assertion.

Sources: Coding guidelines, Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@oshi-common/src/test/java/oshi/util/ProcUtilsTest.java`:
- Around line 77-87: Update testParseStatisticsWithTrailingWhitespace to
exercise the parser with in-memory fixture data instead of a temporary file and
path-based ProcUtil.parseStatistics. If no suitable overload exists, extract the
parsing loop into a package-private ProcUtil method accepting List<String>, then
pass the trailing-whitespace line directly to that method while preserving the
existing assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 55b3f428-ef03-4ca9-be84-7a11604b8f8b

📥 Commits

Reviewing files that changed from the base of the PR and between db7e2a6 and c3d9bf1.

📒 Files selected for processing (11)
  • oshi-common/src/main/java/oshi/hardware/common/AbstractGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdPowerSource.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
  • oshi-common/src/main/java/oshi/util/ProcUtil.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuStat.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
🚧 Files skipped from review as they are similar to previous changes (9)
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-common/src/main/java/oshi/util/ProcUtil.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdPowerSource.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGlobalMemory.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractGlobalMemory.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxFirmware.java
  • oshi-common/src/main/java/oshi/util/driver/linux/proc/CpuStat.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Error Prone
  • GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.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/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.java
🧠 Learnings (5)
📚 Learning: 2026-07-30T00:35:25.835Z
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:25.835Z
Learning: In OSHI, only classes annotated with `PublicAPI` are considered API-breaking when changed. Public classes without `PublicAPI`, including `oshi.hardware.common.platform.unix.BsdFirmware`, are internal implementation details. `BsdFirmware.parseDmesg(List<String>)` is intentionally package-private to support tests in its package.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.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/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.java
  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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 oshi-common/src/main/java/**/*.java : Before adding a parsing helper, check `oshi.util.ParseUtil`; put reusable number, size, frequency, hexadecimal, delimited-field, and date parsing there.

Applied to files:

  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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 **/src/test/java/**/*.java : Write tests against parsing methods that accept fixture data such as `List<String>` or `String`, rather than requiring native calls or file/command acquisition.

Applied to files:

  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.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 **/src/main/java/**/*.java : 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.

Applied to files:

  • oshi-common/src/test/java/oshi/util/ProcUtilsTest.java
🔇 Additional comments (2)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxFirmwareTest.java (1)

79-87: LGTM!

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

13-22: LGTM!

… file

Extract the parsing loop into a package-private overload taking
List<String> directly, matching the existing "extract parsing from
acquisition" pattern used elsewhere (e.g. CpuStat). The trailing-
whitespace regression test now exercises that overload with an
in-memory fixture instead of writing a real file and going through
the file-reading path, which was untested surface irrelevant to what
the test is actually checking.
@dbwiddis
dbwiddis merged commit 31efc66 into oshi:master Aug 12, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the triage-error-prone-warnings branch August 12, 2026 21:11
dbwiddis added a commit that referenced this pull request Aug 15, 2026
…e 2) (#3615)

* Mark oshi.util @NullMarked and normalize null handling (jSpecify Phase 2)

Phase 2 of #3593. oshi.util is now @NullMarked, so every type usage in a
signature there is non-null unless annotated @nullable.

Sixteen methods gained an honest @nullable parameter contract. Each already
handled null and was already exercised with null by a test; only the signature
was silent about it. GlobalConfig.get(String) is annotated @nullable rather
than made to return "", so an absent property stays distinguishable from one
set to an empty value, which the two-argument overload cannot express.

Adds ParseUtil.getStringValueOrEmpty beside the existing getStringValueOrUnknown
and removes Util.isBlankOrUnknown, which had no callers outside its own test.
The normalizers replace the spelled-out null check in queryMicroarchitecture
that existed only because NullAway cannot see through the Util.isBlank predicate.

Two latent bugs surfaced:

- ProcUtil.parseNestedStatistics threw ArrayIndexOutOfBoundsException on an
  empty line. A whitespace-only line splits to length 0 and is skipped, but ""
  splits to a single empty element, passes the length guard, and is left with
  nothing by the leading-whitespace shift. The length check now runs after the
  shift, and the netstat fixture gained an empty line to cover it. The bug is
  original to the method (058cb8c), not a regression from the #3597 -1 work,
  which never touched it: StringSplitter flags String.split only, so the
  Pattern.split surface was outside that sweep.
- GlobalConfigTest's asserter matched no branch when the expected default was
  null, so testGetString asserted nothing at all. It now exercises the
  single-argument get.

NullAway analyses test sources, which is what surfaced the parameter contracts
above. HandleTestAssertionLibraries is enabled so assertNotNull narrows a
nullable for the rest of a test method; Hamcrest's notNullValue() does not, so
the assertions preceding a dereference were converted. No suppressions added.

* Import DisplayInfo and DisplayInfoImpl in EdidUtil instead of naming them fully qualified

AGENTS.md forbids fully-qualified class names in code and in javadoc links.
The signature was the worst of these, since annotating the return type for
jSpecify had turned it into oshi.hardware.@nullable DisplayInfo.

oshi.util already imports from oshi.hardware in GlobalConfig and
SystemInfoHelper, and neither type collides with anything in scope.
dbwiddis added a commit that referenced this pull request Aug 15, 2026
Establishes the end state for #3593 across oshi-common, oshi-core and
oshi-core-ffm. NullAway runs at WARN until the backlog it reports is drained,
following the precedent set for the SLF4J check in #3597; it goes back to
ERROR once the count reaches zero.

Two mechanisms, aimed at what each can actually reach. A package annotation is
the only one every consumer sees: a JDK 8 user has no module system at all,
and a JDK 9+ user on the classpath does not resolve module annotations either.
So the packages a caller touches are annotated individually -- those holding
@publicapi types, and the whole oshi.util tree, which callers do sometimes
reach for. Everything below that line is per-OS implementation, abstract bases
and drivers, which the project already documents as not meant for outside use;
those are covered by @NullMarked on the module declaration, which exists to let
us check our own code and needs no per-package upkeep as packages are added.

The native mapping packages are opted out with @NullUnmarked. The struct and
library bindings under oshi.jna and oshi.ffm.platform describe someone else's
memory layout rather than our contracts, and are already exempt from the
javadoc rules for the same reason. Their utility packages, oshi.jna.util and
oshi.ffm.util, are not opted out.

oshi-common and oshi-core compile their sources at release 8, which predates
JPMS and therefore excludes module-info.java, leaving the module annotation
invisible to NullAway. Under -Perror-prone only, they now compile at release 9
with module-info.java included. The released jars are unchanged, still built at
release 8. oshi-core and oshi-core-ffm gain the jspecify dependency and a
requires static clause, since oshi-common declares it optional and it is
therefore not transitive.

-Xmaxerrs joins the -Xmaxwarns that #3597 set. NullAway reports at ERROR once
the backlog is drained, and javac caps errors at 100 by default just as
silently as warnings: a survey of oshi-common reported exactly 100 findings
until this was set, against a real 288.

Marking oshi.driver.common.windows.wmi showed WmiResult.getValue declaring a
non-null return that every caller in WmiUtil immediately null-checks, so a WMI
row without the property was already returning null through a signature that
promised otherwise. NetBsdCentralProcessor.parseCpTime likewise null-checks the
argument it declared non-null. Both are annotated now. Two tests asserted on a
map lookup without checking it was present, and one called main(null).
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