Skip to content

Hoist common OSThread fields and getters into AbstractOSThread - #3446

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:dedup-osthread-psinfo
Jul 10, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:dedup-osthread-psinfo

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Second subsystem in the cross-OS consistency/dedup audit. Pure structural consolidation — no observable change for valid threads.

What

Every OSThread implementation declared the same 12 thread-attribute fields (threadId, name, state, kernel/user/start/up time, priority, minor/major faults, context switches, start address) with identical return this.field getters. This hoists them into AbstractOSThread as protected fields + field-backed getters — the same field-hoist model AbstractOSProcess already uses — so each platform keeps only its own parsing in updateAttributes().

File Change
AbstractOSThread gains the 12 protected fields + the getters
Linux/AIX/Solaris/BSD/Windows/Mac OSThread drop the fields + getters; keep constructors + parsing

Platform-specific bits stay put: Linux's os field, Solaris's memoized psinfo/prusage suppliers, Windows's getProcName() + perf-counter updateAttributes(procName, pcb), BSD's ps-row parsing. BsdOSThread's protected fields (already the full superset) simply moved up a level, and its checkstyle VisibilityModifier suppression migrated to AbstractOSThread.

Net −279 lines (8 files, +93/−372).

Note

getName() is now uniformly null-safe in the base (name != null ? name : ""), matching the interface's documented default of "" and what Solaris already did. Previously Windows/Linux could return null for an invalid/unset thread; they now return "". Not a change for any valid thread, and it aligns to the contract — flagging it for transparency, not treating it as user-facing.

Deferred (from the map)

  • PsInfo Solaris↔AIX: the lwpsinfo structs genuinely differ (field count/order/types), so the flagged "twin" can't merge its parser — only a ~30-line JNA buffer-read helper is shareable, and it's really OSProcess plumbing. Folding that into the OSProcess PR (OSX: Yosemite: hw.availcpu is not defined #8) instead.

Part of the subsystem-by-subsystem audit; follows #3445 (FileSystem).

Summary by CodeRabbit

  • Refactor

    • Standardized thread information handling across supported operating systems.
    • Thread identifiers, names, states, timing, memory, fault, context-switch, and priority metrics now use consistent shared access behavior.
    • Improved default handling for unavailable thread names and invalid/unknown states, while platform updates continue refreshing metrics as before.
  • Tests

    • Updated thread test helpers to align with the new shared attribute storage.
  • Chores

    • Refreshed code-quality suppression rules related to visibility warnings.

Second subsystem in the cross-OS consistency audit. Every OSThread
implementation declared the same thread-attribute fields (threadId, name,
state, kernel/user/start/up time, priority, faults, context switches, start
address) with identical return-the-field getters. Hoist them into
AbstractOSThread as protected fields + getters (the AbstractOSProcess
field-hoist model), so each platform keeps only its own parsing:

- AbstractOSThread: gains the 12 protected fields + field-backed getters.
- Linux/AIX/Solaris/BSD/Windows/Mac OSThread: drop the fields + getters, keep
  their parsing/constructors (Linux keeps its os field, Solaris its memoized
  psinfo suppliers, Windows its getProcName + perf-counter updateAttributes,
  BSD its ps-row parsing).
- BsdOSThread's protected fields (already the full superset) moved up; its
  checkstyle VisibilityModifier suppression migrated to AbstractOSThread.

Net -279 lines. getName() is now uniformly null-safe (returns empty per the
interface contract) instead of each platform differing; no observable change
for valid threads.
@coderabbitai

coderabbitai Bot commented Jul 10, 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

Run ID: 6862cfec-074b-4dfa-824b-9db2a94825cb

📥 Commits

Reviewing files that changed from the base of the PR and between 3fb592a and 59b1942.

📒 Files selected for processing (1)
  • oshi-common/src/test/java/oshi/software/common/AbstractOSThreadTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (16)
  • GitHub Check: CodeRabbit
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
oshi-common/src/test/java/oshi/software/common/AbstractOSThreadTest.java (1)

20-29: LGTM!


📝 Walkthrough

Walkthrough

AbstractOSThread now owns shared thread attributes and getters. Platform-specific thread classes remove duplicate storage and accessor overrides while retaining update logic. Checkstyle suppression patterns are updated for the new protected fields.

Changes

Thread attribute centralization

Layer / File(s) Summary
Shared thread state contract
oshi-common/src/main/java/oshi/software/common/AbstractOSThread.java, oshi-common/src/test/java/oshi/software/common/AbstractOSThreadTest.java
Adds protected thread attributes, default values, concrete getters, and field-based test setup.
Platform thread migration
oshi-common/src/main/java/oshi/software/common/os/{linux,mac,unix/**,windows}/*OSThread.java, config/checkstyle-suppressions.xml
Removes duplicate platform fields and getter overrides, retains attribute-update logic, and adjusts visibility suppressions.

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

Possibly related PRs

  • oshi/oshi#3374: Refactors related BSD thread attribute storage and accessors.

Poem

A rabbit hops through fields once spread wide,
Now AbstractOSThread keeps them inside.
Platform getters fade from view,
Updates still do what they do.
Checkstyle nods: “A tidy stride!”

🚥 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 summarizes the structural consolidation of common OSThread fields and getters into AbstractOSThread.
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.

The test's anonymous AbstractOSThread overrode getters returning captured
parameters named threadId/kernelTime/etc. Now that AbstractOSThread declares
inherited protected fields of the same names, those unqualified references
resolved to the (zero) fields instead of the captured params, so every getter
returned 0. Set the protected fields directly instead (the test is in the same
package), which also exercises the real field-backed getters.
@codecov

codecov Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (b061c05) to head (59b1942).

Files with missing lines Patch % Lines
...in/java/oshi/software/common/AbstractOSThread.java 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3446      +/-   ##
============================================
- Coverage     74.54%   74.44%   -0.11%     
  Complexity       76       76              
============================================
  Files           581      581              
  Lines         21944    21903      -41     
  Branches       3669     3669              
============================================
- Hits          16358    16305      -53     
- Misses         3549     3556       +7     
- Partials       2037     2042       +5     
Flag Coverage Δ
freebsd 26.89% <85.71%> (+0.03%) ⬆️
linux 31.44% <85.71%> (+0.05%) ⬆️
macos 31.84% <85.71%> (+0.02%) ⬆️
openbsd 26.39% <85.71%> (+0.04%) ⬆️
solaris 28.43% <85.71%> (+0.07%) ⬆️
windows 39.81% <85.71%> (+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 131f2cd into oshi:master Jul 10, 2026
32 of 34 checks passed
@dbwiddis
dbwiddis deleted the dedup-osthread-psinfo branch July 11, 2026 00:00
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