Skip to content

Replace two duplicated parse helpers with their ParseUtil equivalents - #3580

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-parse-helpers
Aug 4, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dedup-parse-helpers

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Two private helpers reimplemented logic that already existed elsewhere. Follow-up to #3579, continuing the sweep for private helpers that ParseUtil already covers.

LinuxVirtualMemory.parseMeminfo → ParseUtil.parseDecimalMemorySizeToBinary

parseMeminfo multiplied a /proc/meminfo value by 1024 when its unit column was "kB". LinuxGlobalMemory, parsing the same file, already used ParseUtil.parseDecimalMemorySizeToBinary for exactly this. The two siblings now agree.

The split limit had to change from unlimited to 2, matching LinuxGlobalMemory, so the value and unit reach parseDecimalMemorySizeToBinary as one string. I verified equivalence across the realistic inputs rather than by eye:

input old new
SwapTotal: 2000000 kB 2048000000 2048000000
SwapTotal: 2000000 (no unit) 2000000 2000000
SwapTotal:\t2000000\tkB (tabs) 2048000000 2048000000
SwapTotal: garbage kB 0 0
SwapTotal: (malformed, single field) skipped skipped
SwapTotal: 9007199254740992 kB (overflows long) same same
SwapTotal: 2000000 MB 2000000 2097152000000

The last row is the only divergence. The kernel never emits MB for these fields — they are always kB — and on that hypothetical input the new behavior is the more correct of the two.

convertBytesToInts → ParseUtil.parseIPv6BytesToIntArray

SessionWtsData and SessionWtsDataFFM each carried a byte-identical copy converting the WTS_CLIENT_ADDRESS Address member to the int[4] that ParseUtil.parseUtAddrV6toIP consumes — the JNA copy's javadoc already pointed at ParseUtil#parseUtAddrV6toIP as its only consumer, so that is where it now lives. Both twins share the conversion instead of maintaining separate copies.

One small hardening while hoisting: a length guard so a short array throws IllegalArgumentException with a clear message rather than IndexOutOfBoundsException from Arrays.copyOfRange, matching how the adjacent parseUtAddrV6toIP rejects a wrong-length input.

No user-visible behavior change, so no CHANGELOG entry.

Verification

Full gate green: clean spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check plus javadoc:javadoc, 0 tests failed across all modules. New testParseIPv6BytesToIntArray confirmed executing ([OK] in the console-launcher output, not just present in the source). Fork CI green on Windows — which covers the SessionWtsData paths I cannot exercise on macOS — and on Linux, which covers the /proc/meminfo change.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Linux virtual memory reporting by consistently interpreting memory values from system information.
    • Improved IPv6 client address handling for Windows session data, including padded address structures and zero addresses.
  • Tests
    • Added coverage for IPv6 byte-array conversion, valid boundary inputs, and invalid null or undersized inputs.

Two private helpers reimplemented logic that already existed elsewhere.

LinuxVirtualMemory.parseMeminfo multiplied a /proc/meminfo value by 1024
when its unit column was "kB". LinuxGlobalMemory, parsing the same file,
already used ParseUtil.parseDecimalMemorySizeToBinary for exactly this.
Split the line with a limit of 2 to keep the value and unit together, as
LinuxGlobalMemory does, and delegate. Verified equivalent across the
realistic inputs, including a missing unit, tabs, non-numeric values, a
malformed single-field line, and a value that overflows a long. The two
differ only on a hypothetical "MB" unit, which the kernel never emits for
these fields, and where the new behavior is the more correct of the two.

SessionWtsData and SessionWtsDataFFM each carried a byte-identical
convertBytesToInts converting the WTS_CLIENT_ADDRESS Address member to
the int[4] that ParseUtil.parseUtAddrV6toIP consumes. Hoist it to
ParseUtil.parseIPv6BytesToIntArray, next to its only consumer, and add a
length guard so a short array throws IllegalArgumentException rather than
IndexOutOfBoundsException from Arrays.copyOfRange. Both twins now share
the conversion instead of maintaining separate copies.

No user-visible behavior change, so no CHANGELOG entry.
@coderabbitai

coderabbitai Bot commented Aug 4, 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: 30d2dc55-a424-4174-97fa-1b896c1bcbab

📥 Commits

Reviewing files that changed from the base of the PR and between bf7f178 and 44970c3.

📒 Files selected for processing (5)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.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 corresponding tolerant ParseUtil methods.
Do not import org.slf4j.event.**; use oshi.util.LogLevel instead.

Files:

  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java
**/src/test/java/**/*Test.java

📄 CodeRabbit inference engine (AGENTS.md)

Write tests against parsing and transformation methods using fixture data; keep acquisition methods thin. Do not add Mockito, and use JUnit 5 with Hamcrest.

Files:

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

📄 CodeRabbit inference engine (AGENTS.md)

Test hardware-dependent behavior using invariants, plausible ranges, correct types, and ordering rather than fixed machine-specific values; treat zero and empty results as valid where applicable.

Files:

  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
**/*.{java,xml,properties,md}

📄 CodeRabbit inference engine (AGENTS.md)

Do not commit generated output, target/, or IDE files.

Files:

  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java
oshi-core-ffm/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-core-ffm/src/main/java/**/*.java: For changes to an oshi-core-ffm implementation, apply the equivalent behavior change to its corresponding oshi-core twin, or explain why the implementations intentionally differ.
Do not reference com.sun.jna from FFM implementation sources.

Files:

  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
**/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/main/java/**/*.java: Keep external imports synchronized with config/import-control.xml, the module's module-info.java, and, when necessary, its Maven configuration.
Provide Javadoc for every public and protected type and method; use imported simple class names rather than fully qualified names in code and Javadoc links.
Use the repository's concurrency annotation (@ThreadSafe, @Immutable, @NotThreadSafe, or @GuardedBy) on new classes, matching the modeled class where appropriate.
Memoize constant or expensive, slowly changing system values with oshi.util.Memoizer.memoize, generally using a Supplier<T> and defaultExpiration() when refresh is required.
Do not duplicate non-native logic between platform implementations; hoist parsing, conversion, filtering, caching, validation, and sentinel handling into oshi-common where possible.

Files:

  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java
oshi-common/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-common/src/main/java/**/*.java: Keep oshi-common pure Java: do not reference JNA, FFM (java.lang.foreign), or System.load/loadLibrary; place parsing, conversion, validation, caching, and shared implementation logic here when it is not native-API-specific.
Before adding a general parsing helper, check oshi.util.ParseUtil; use its existing parsing methods or add shared primitives there rather than duplicating parsers in platform drivers.
Read runtime configuration from oshi-common/src/main/resources/oshi.properties through GlobalConfig or Java system properties; do not introduce a separate configuration mechanism.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
{oshi-common,oshi-core}/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

Use Java 8 language and API compatibility: do not use var, records, switch expressions, text blocks, List.of, Stream.toList(), or other post-Java-8 features.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java
oshi-core/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

For changes to an oshi-core implementation, apply the equivalent behavior change to its corresponding oshi-core-ffm twin, or explain why the implementations intentionally differ.

Files:

  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java
🧠 Learnings (5)
📚 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/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.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-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.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-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.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/driver/windows/registry/SessionWtsDataFFM.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/platform/linux/LinuxVirtualMemory.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java (1)

90-100: LGTM!

Also applies to: 142-142

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

12-12: LGTM!

Also applies to: 1228-1249

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

770-789: LGTM!

oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java (1)

167-167: LGTM!

oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java (1)

138-138: LGTM!


📝 Walkthrough

Walkthrough

The change adds shared IPv6 byte conversion, updates Windows session parsers to use it, and simplifies Linux /proc/meminfo parsing with binary memory-size conversion.

Changes

IPv6 parsing centralization

Layer / File(s) Summary
Add shared IPv6 conversion
oshi-common/src/main/java/oshi/util/ParseUtil.java, oshi-common/src/test/java/oshi/util/ParseUtilTest.java
parseIPv6BytesToIntArray validates input and converts padded IPv6 bytes into four big-endian integers. Tests cover valid and invalid inputs.
Use shared IPv6 conversion
oshi-core/src/main/java/oshi/driver/windows/registry/SessionWtsData.java, oshi-core-ffm/src/main/java/oshi/driver/windows/registry/SessionWtsDataFFM.java
Both Windows session parsers use the shared method and remove duplicate conversion helpers.

Linux memory parsing

Layer / File(s) Summary
Simplify meminfo parsing
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxVirtualMemory.java
parseMemInfo directly parses swap and commit-limit values with binary memory-size conversion and removes the private helper.

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

Possibly related PRs

  • oshi/oshi#3579: Both changes centralize byte-array parsing in ParseUtil.

Poem

A rabbit hops through bytes so bright,
Four IPv6 ints align just right.
Meminfo values now parse with care,
Shared helpers bloom everywhere.
Hop, hop, clean code in sight!

🚥 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 main change: replacing duplicated parsing helpers with shared ParseUtil methods.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.98%. Comparing base (bf7f178) to head (44970c3).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3580      +/-   ##
============================================
- Coverage     80.03%   79.98%   -0.06%     
+ Complexity     3868     3867       -1     
============================================
  Files           709      709              
  Lines         24205    24206       +1     
  Branches       4048     4047       -1     
============================================
- Hits          19373    19360      -13     
- Misses         2689     2694       +5     
- Partials       2143     2152       +9     
Flag Coverage Δ
linux 37.66% <100.00%> (+0.04%) ⬆️
macos 38.43% <100.00%> (-0.04%) ⬇️
windows 45.38% <100.00%> (-0.04%) ⬇️

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 743b2bf into oshi:master Aug 4, 2026
17 checks passed
@dbwiddis
dbwiddis deleted the dedup-parse-helpers branch August 4, 2026 21:41
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