Skip to content

Add SystemInfoProvider SPI for automatic implementation selection - #3234

Merged
dbwiddis merged 3 commits into
masterfrom
feature/systeminfo-spi
May 8, 2026
Merged

dbwiddis merged 3 commits into
masterfrom
feature/systeminfo-spi

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 7, 2026 •

Copy link
Copy Markdown
Member

Resolves discussion #2993

Summary

Adds a SystemInfoProvider SPI (Service Provider Interface) and SystemInfoFactory in the oshi.spi package, enabling automatic selection of the best available OSHI implementation at runtime.

Users who have both oshi-core (JNA) and oshi-core-ffm (FFM) as dependencies can now use:

SystemInfoProvider si = SystemInfoFactory.create();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();

The factory uses java.util.ServiceLoader to discover providers, filters by isAvailable(), and selects the highest-priority one. The FFM provider (priority 20) is preferred over JNA (priority 10) when the platform is Windows, Linux, or macOS and the JDK is 25+. Priority 0 is reserved for a potential future no-native-access fallback.

Design

  • SystemInfoProvider — interface in oshi-common with getOperatingSystem(), getHardware(), getPriority(), isAvailable()
  • SystemInfoFactory — ServiceLoader-based factory in oshi-common
  • Both existing SystemInfo classes implement the interface (binary-compatible change)
  • JPMS provides/uses declarations + classpath META-INF/services for both module path and classpath usage

Backward compatibility

  • new oshi.SystemInfo() and new oshi.ffm.SystemInfo() continue to work unchanged
  • Adding an interface to an existing class is binary-compatible per SemVer (verified by japicmp)
  • Version bumped to 7.2.0 to reflect the new feature

Testing

  • SystemInfoFactoryTest verifies provider discovery, priority, availability, and that hardware/OS instances are returned

Summary by CodeRabbit

  • New Features

    • Added an SPI and factory that automatically selects the best available system-info provider at runtime.
  • Documentation

    • Updated usage examples to show automatic selection and reworded explicit selection; bumped SNAPSHOT versions to 7.2.0-SNAPSHOT.
  • Tests

    • Added tests for provider discovery, availability, priority, and returned system info.
  • Chores

    • Bumped parent/module versions and adjusted build/manifest settings.

@coderabbitai

coderabbitai Bot commented May 7, 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: cc6499b8-eca0-4a62-8e9b-d5ada21c8f04

📥 Commits

Reviewing files that changed from the base of the PR and between b0df109 and 1e01ec1.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • README.md
  • oshi-benchmark/pom.xml
  • oshi-common/pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core-ffm/pom.xml
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-demo/pom.xml
  • oshi-dist/pom.xml
  • oshi-metrics/pom.xml
  • pom.xml
  • src/site/markdown/index.md
✅ Files skipped from review due to trivial changes (11)
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core/pom.xml
  • oshi-dist/pom.xml
  • oshi-common/pom.xml
  • pom.xml
  • oshi-core-ffm/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-demo/pom.xml
  • README.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-benchmark/pom.xml
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-metrics/pom.xml
  • src/site/markdown/index.md
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🪛 markdownlint-cli2 (0.22.1)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (1)
CHANGELOG.md (1)

1-5: Changelog entry is clear and consistent with project conventions.

The 7.2.0 note accurately captures the SPI/factory addition and matches the established CHANGELOG structure.


📝 Walkthrough

Walkthrough

This PR adds a SystemInfoProvider SPI and SystemInfoFactory that uses ServiceLoader to pick the highest-priority available provider, updates JNA and FFM implementations to implement the SPI, registers providers via JPMS, adds tests, and bumps docs/POMs to 7.2.0-SNAPSHOT.

Changes

SystemInfoProvider SPI and Runtime Selection

Layer / File(s) Summary
SPI Contract & Module Exports
oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java, oshi-common/src/main/java/oshi/spi/package-info.java, oshi-common/src/main/java/module-info.java
New public interface SystemInfoProvider with methods getOperatingSystem(), getHardware(), getPriority(), isAvailable(); package Javadoc added; common module exports oshi.spi and declares uses for the SPI.
ServiceLoader Factory
oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
New SystemInfoFactory.create() discovers providers via ServiceLoader, filters by isAvailable(), selects the highest getPriority(), logs and skips failing providers, and throws IllegalStateException if none found.
JPMS Provider Registrations
oshi-core/src/main/java/module-info.java, oshi-core-ffm/src/main/java/module-info.java
Module descriptors add provides oshi.spi.SystemInfoProvider with oshi.SystemInfo and provides ... with oshi.ffm.SystemInfo registrations.
JNA Implementation
oshi-core/src/main/java/oshi/SystemInfo.java
oshi.SystemInfo now implements SystemInfoProvider, adds getPriority() returning 10 and isAvailable() returning true; existing memoized suppliers and behavior preserved.
FFM Implementation
oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
oshi.ffm.SystemInfo implements SystemInfoProvider, adds SUPPORTED_PLATFORMS, getPriority() returning 20, and isAvailable() checking supported platforms and JDK feature version >= 25; existing suppliers preserved.
Factory Tests
oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
JUnit 5 tests ensure SystemInfoFactory.create() returns an available provider with positive priority and non-null HAL/OS; assert default SystemInfo availability/priority.
Project Coordination & Documentation
pom.xml, oshi-*/pom.xml, CHANGELOG.md, README.md, src/site/markdown/index.md
Bump versions to 7.2.0-SNAPSHOT, add maven-jar plugin manifest overrides where present, update README/site examples to show automatic selection via SystemInfoFactory.create(), and add CHANGELOG entry documenting the new SPI and factory.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Factory as SystemInfoFactory
  participant SL as ServiceLoader
  participant Provider as SystemInfoProvider
  Client->>Factory: create()
  Factory->>SL: load(SystemInfoProvider)
  SL->>Provider: discover implementations
  Factory->>Provider: call isAvailable()
  Factory->>Provider: compare getPriority()
  Factory-->>Client: return selected provider
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • oshi/oshi#3183: Both PRs modify the same public entry-point types (oshi.SystemInfo and oshi.ffm.SystemInfo) and overlap with SPI-related updates.
  • oshi/oshi#3182: Also modifies oshi.SystemInfo; both PRs touch the SystemInfo entry point and related behaviors.

Poem

🐰 I nibble code by moonlit light,
I hop through services, sniff what's right.
JNA or FFM, I seek the best,
The factory picks, we run the test.
Hooray—runtime choice, snug in my chest.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.06% 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 PR title 'Add SystemInfoProvider SPI for automatic implementation selection' clearly and specifically describes the main feature being added: an SPI (Service Provider Interface) for automatic selection of OSHI implementations, which aligns perfectly with the changeset that introduces SystemInfoProvider, SystemInfoFactory, and the necessary infrastructure.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/systeminfo-spi

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dbwiddis
dbwiddis force-pushed the feature/systeminfo-spi branch from 1b17049 to eed5477 Compare May 7, 2026 23:16

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

🤖 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 `@CHANGELOG.md`:
- Line 3: The heading "##### New Features" in the changelog jumps down from the
H1 release title and triggers MD001; change the "##### New Features" line to a
higher-level heading (e.g., "## New Features" or "### New Features" to match
your chosen document structure) so heading levels increment properly and the
markdown linter no longer flags the "New Features" heading.

In `@oshi-common/src/main/java/oshi/hardware/common/NoOpGpuStats.java`:
- Line 27: The NoOpGpuStats constructor visibility was changed to protected
which breaks cross-package tests; restore the constructor in NoOpGpuStats to
public (i.e., change protected NoOpGpuStats() back to public NoOpGpuStats()) so
test classes in oshi-core (referenced by GpuStatsTest) can instantiate it, or
alternatively add a public factory method on a public class (e.g., a static
factory on NoOpGpuStats or on AbstractGraphicsCard) that returns a new
NoOpGpuStats instance and update tests to use that factory; prefer restoring the
public constructor for the simplest fix to restore existing test usage.

In `@oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java`:
- Around line 47-53: The ServiceLoader iteration in SystemInfoFactory that walks
ServiceLoader.load(SystemInfoProvider.class) should be hardened so a single
malformed provider doesn't abort selection: wrap the loop body (the call to
provider.isAvailable() and provider.getPriority()) in a try/catch that catches
ServiceConfigurationError (and optionally RuntimeException) and logs/debugs the
failing provider before continuing, skipping that entry and leaving the existing
best variable unchanged; ensure you still select the highest priority
SystemInfoProvider by comparing provider.getPriority() only when safe and
continue to the next provider on error.

In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Around line 95-98: The isAvailable() implementation in SystemInfo incorrectly
always returns true; change it to perform the same platform detection used by
the provider's initialization (the code path that later throws on unsupported
platforms) and return false when the current platform is unsupported so the SPI
availability contract is honored—for example, have SystemInfo.isAvailable() call
the same platform-check helper used elsewhere (the initialization/constructor
path that throws) or a central platform-detection method and return that boolean
instead of true.

In `@oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java`:
- Around line 20-24: The test testFactoryFindsProvider() asserts a concrete
implementation (SystemInfo) which makes it brittle; update the assertion after
calling SystemInfoFactory.create() to verify only the interface-level contract
by removing the instanceOf(SystemInfo.class) check and instead assert the
returned object is non-null and an instance of SystemInfoProvider (or otherwise
exercise interface methods), referring to SystemInfoFactory.create() and the
SystemInfoProvider type to locate the code to change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b2a3bf41-f5c6-41ea-9eef-d0d81b8401a6

📥 Commits

Reviewing files that changed from the base of the PR and between 153df0a and 1b17049.

📒 Files selected for processing (21)
  • CHANGELOG.md
  • README.md
  • oshi-benchmark/pom.xml
  • oshi-common/pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/hardware/common/NoOpGpuStats.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core-ffm/pom.xml
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-demo/pom.xml
  • oshi-dist/pom.xml
  • oshi-metrics/pom.xml
  • pom.xml
  • src/site/markdown/index.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-03-29T20:01:01.877Z
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:01.877Z
Learning: In this repo’s `module-info.java` files, keep exports aligned with which platform implementations are actually supported by the current FFM (Foreign Function & Memory) backend. Do not export FreeBSD, OpenBSD, or Solaris packages (e.g., `oshi.util.platform.unix.freebsd|openbsd|solaris`) in modules where the FFM implementation only supports Windows/macOS/Linux; this asymmetry vs older Java targets (e.g., the java11 module-info that exports all Unix packages) is intentional and should not be flagged as an omission unless the underlying support changes.

Applied to files:

  • oshi-core-ffm/src/main/java/module-info.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/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/hardware/common/NoOpGpuStats.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/package-info.java
🪛 markdownlint-cli2 (0.22.1)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (16)
oshi-common/src/main/java/oshi/spi/package-info.java (1)

1-4: Looks good — clear SPI package documentation.

This package-level Javadoc is concise and aligned with the new provider/factory design.

oshi-common/pom.xml (1)

8-8: Version alignment is correct.

Parent version bump matches the PR’s release train update.

pom.xml (1)

7-7: LGTM — root version bump is consistent.

oshi-core/pom.xml (1)

8-8: Looks good — module version alignment is correct.

oshi-dist/pom.xml (1)

8-8: Version bump is consistent with the rest of the modules.

oshi-benchmark/pom.xml (1)

8-8: LGTM — benchmark module version alignment is correct.

oshi-metrics/pom.xml (1)

8-8: Looks good — metrics module is aligned to 7.2.0-SNAPSHOT.

oshi-core-ffm/pom.xml (1)

8-8: Version alignment looks correct.

Parent version bump to 7.2.0-SNAPSHOT is consistent with the SPI rollout across modules.

oshi-demo/pom.xml (1)

8-8: LGTM for demo module version sync.

This keeps oshi-demo aligned with the new snapshot line.

oshi-core-ffm/src/main/java/module-info.java (1)

28-28: JPMS provider wiring is correct.

provides oshi.spi.SystemInfoProvider with oshi.ffm.SystemInfo; is the right registration for ServiceLoader discovery.

oshi-core/src/main/java/module-info.java (1)

30-30: Service registration for JNA implementation looks good.

This enables SystemInfoFactory discovery on module path.

src/site/markdown/index.md (1)

54-55: Docs update is consistent with the new SPI flow.

The snapshot version bump and runtime-selection example now match the introduced SystemInfoProvider/SystemInfoFactory API.

Also applies to: 80-87, 89-89

README.md (1)

54-55: README changes are aligned with the new factory-based selection.

Good update to keep user-facing examples in sync with the SPI introduction.

Also applies to: 80-87, 89-89

oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java (1)

63-87: SPI implementation and availability gating look correct.

Line 63 and Lines 77-87 are consistent with the intended selection model: FFM is preferred via higher priority and only participates when runtime/platform requirements are actually met.

oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java (1)

11-57: Clean SPI contract for runtime provider selection.

The interface methods and docs are scoped well for ServiceLoader discovery and deterministic provider choice.

oshi-common/src/main/java/module-info.java (1)

39-47: JPMS SPI wiring looks correct.

Line 39 and Line 47 properly expose and consume the provider contract for module-path ServiceLoader resolution.

Comment thread CHANGELOG.md Resolved

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

♻️ Duplicate comments (2)
CHANGELOG.md (1)

3-3: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Heading level jump (H1 → H5) still violates MD001.

##### New Features at line 3 skips three heading levels immediately after the H1 release title. This was flagged in a prior review and remains unfixed.

🤖 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 `@CHANGELOG.md` at line 3, The heading "##### New Features" causes an MD001
level jump after the H1 release title; replace or adjust it so headings progress
without skipping levels (for example change "##### New Features" to "## New
Features" immediately after the H1 release title, or otherwise ensure
intermediate H2/H3 are present), and re-run the markdown linter to confirm the
MD001 violation is resolved.
oshi-core/src/main/java/oshi/SystemInfo.java (1)

95-98: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

isAvailable() still unconditionally returns true.

This issue was flagged in a prior review and remains unresolved. createOperatingSystem() and createHardware() both throw UnsupportedOperationException on the default branch, so returning true on an unsupported platform allows SystemInfoFactory to select this provider only for it to blow up on the first real call.

🤖 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-core/src/main/java/oshi/SystemInfo.java` around lines 95 - 98,
isAvailable() currently always returns true which lets SystemInfoFactory pick
this provider even though createOperatingSystem() and createHardware() throw
UnsupportedOperationException for the default/unsupported branch; change
isAvailable() to perform the same platform-check logic used by
createOperatingSystem()/createHardware() and return false for the
default/unsupported case (or otherwise detect unsupported platforms) so
SystemInfoFactory will skip this provider on unsupported systems; reference the
isAvailable(), createOperatingSystem(), createHardware(), and the default
UnsupportedOperationException branch to align the availability check with the
actual implementation.
🤖 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.

Duplicate comments:
In `@CHANGELOG.md`:
- Line 3: The heading "##### New Features" causes an MD001 level jump after the
H1 release title; replace or adjust it so headings progress without skipping
levels (for example change "##### New Features" to "## New Features" immediately
after the H1 release title, or otherwise ensure intermediate H2/H3 are present),
and re-run the markdown linter to confirm the MD001 violation is resolved.

In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Around line 95-98: isAvailable() currently always returns true which lets
SystemInfoFactory pick this provider even though createOperatingSystem() and
createHardware() throw UnsupportedOperationException for the default/unsupported
branch; change isAvailable() to perform the same platform-check logic used by
createOperatingSystem()/createHardware() and return false for the
default/unsupported case (or otherwise detect unsupported platforms) so
SystemInfoFactory will skip this provider on unsupported systems; reference the
isAvailable(), createOperatingSystem(), createHardware(), and the default
UnsupportedOperationException branch to align the availability check with the
actual implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 10fcb155-e1f4-4b10-be5d-6d92a7f9b0d1

📥 Commits

Reviewing files that changed from the base of the PR and between 1b17049 and eed5477.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • README.md
  • oshi-benchmark/pom.xml
  • oshi-common/pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core-ffm/pom.xml
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-demo/pom.xml
  • oshi-dist/pom.xml
  • oshi-metrics/pom.xml
  • pom.xml
  • src/site/markdown/index.md
✅ Files skipped from review due to trivial changes (13)
  • oshi-common/pom.xml
  • oshi-metrics/pom.xml
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/pom.xml
  • oshi-core/pom.xml
  • pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-benchmark/pom.xml
  • oshi-demo/pom.xml
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-dist/pom.xml
🚧 Files skipped from review as they are similar to previous changes (5)
  • README.md
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • src/site/markdown/index.md
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🪛 markdownlint-cli2 (0.22.1)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

@dbwiddis
dbwiddis force-pushed the feature/systeminfo-spi branch from eed5477 to 921bd06 Compare May 7, 2026 23:23

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

♻️ Duplicate comments (1)
oshi-core/src/main/java/oshi/SystemInfo.java (1)

95-98: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

isAvailable() unconditionally returns true, violating the SPI availability contract on unsupported platforms.

createOperatingSystem() and createHardware() both throw UnsupportedOperationException via their default branch. If SystemInfoFactory selects this provider (because isAvailable() says it's ready), callers will get a runtime exception instead of a clean fallback to another provider or a meaningful "no provider found" error.

🛡️ Proposed fix
 `@Override`
 public boolean isAvailable() {
-    return true;
+    switch (PlatformEnum.getCurrentPlatform()) {
+        case LINUX:
+        case ANDROID:
+        case MACOS:
+        case WINDOWS:
+        case SOLARIS:
+        case FREEBSD:
+        case AIX:
+        case OPENBSD:
+            return true;
+        default:
+            return false;
+    }
 }
🤖 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-core/src/main/java/oshi/SystemInfo.java` around lines 95 - 98, The
isAvailable() method in SystemInfo currently returns true unconditionally, which
can cause SystemInfoFactory to select this provider even though
createOperatingSystem() and createHardware() default to throwing
UnsupportedOperationException; change isAvailable() to perform real
platform-support checks (or delegate to the same detection logic used by
createOperatingSystem()/createHardware()) so it returns false on unsupported
platforms, ensuring SystemInfoFactory won't pick this provider and callers won't
receive unexpected runtime exceptions from createOperatingSystem() or
createHardware().
🤖 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.

Duplicate comments:
In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Around line 95-98: The isAvailable() method in SystemInfo currently returns
true unconditionally, which can cause SystemInfoFactory to select this provider
even though createOperatingSystem() and createHardware() default to throwing
UnsupportedOperationException; change isAvailable() to perform real
platform-support checks (or delegate to the same detection logic used by
createOperatingSystem()/createHardware()) so it returns false on unsupported
platforms, ensuring SystemInfoFactory won't pick this provider and callers won't
receive unexpected runtime exceptions from createOperatingSystem() or
createHardware().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 168c1407-a177-45f0-8810-bf4b65c64bee

📥 Commits

Reviewing files that changed from the base of the PR and between eed5477 and 921bd06.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • README.md
  • oshi-benchmark/pom.xml
  • oshi-common/pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core-ffm/pom.xml
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-demo/pom.xml
  • oshi-dist/pom.xml
  • oshi-metrics/pom.xml
  • pom.xml
  • src/site/markdown/index.md
✅ Files skipped from review due to trivial changes (11)
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core/src/main/java/module-info.java
  • oshi-core/pom.xml
  • oshi-core-ffm/pom.xml
  • oshi-benchmark/pom.xml
  • oshi-metrics/pom.xml
  • src/site/markdown/index.md
  • README.md
  • oshi-dist/pom.xml
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/pom.xml
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-core-ffm/src/main/java/module-info.java
  • pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🪛 markdownlint-cli2 (0.22.1)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (3)
oshi-demo/pom.xml (2)

8-8: Version alignment looks correct.

Bumping oshi-parent to 7.2.0-SNAPSHOT is consistent with the PR’s cross-module version update and keeps ${project.version} resolution coherent for oshi-core.


55-63: Explicit JAR manifest override is a good scoped change.

This plugin block cleanly isolates oshi-demo from inherited manifest behavior, which helps avoid unintended packaging metadata bleed-through.

CHANGELOG.md (1)

1-5: Changelog entry looks accurate and consistent with the PR scope.

The new 7.2.0 feature note clearly captures the SPI/factory addition and links the corresponding PR correctly.

@dbwiddis
dbwiddis force-pushed the feature/systeminfo-spi branch from 921bd06 to bdcf759 Compare May 7, 2026 23:45

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

♻️ Duplicate comments (1)
oshi-core/src/main/java/oshi/SystemInfo.java (1)

95-98: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

isAvailable() currently violates the SPI availability contract.

At Line 97, returning true unconditionally can let SystemInfoFactory select this provider on unsupported platforms, but later getOperatingSystem()/getHardware() can throw. Please align availability with the same platform support matrix used by the creation logic.

Suggested minimal fix
 `@Override`
 public boolean isAvailable() {
-    return true;
+    switch (PlatformEnum.getCurrentPlatform()) {
+        case LINUX:
+        case ANDROID:
+        case MACOS:
+        case WINDOWS:
+        case SOLARIS:
+        case FREEBSD:
+        case AIX:
+        case OPENBSD:
+            return true;
+        default:
+            return false;
+    }
 }
🤖 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-core/src/main/java/oshi/SystemInfo.java` around lines 95 - 98, The
isAvailable() method currently returns true unconditionally causing the provider
to be chosen on unsupported platforms; change isAvailable() to perform the same
platform/support check used when creating the provider (i.e., reuse the same
support matrix or helper used by SystemInfoFactory creation logic) so it only
returns true when the OS/hardware implementation is actually supported and will
not cause getOperatingSystem() or getHardware() to throw; reference
isAvailable(), SystemInfoFactory, getOperatingSystem(), and getHardware() and
call into or replicate the factory's platform-support check so the availability
result matches the creation logic.
🤖 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.

Duplicate comments:
In `@oshi-core/src/main/java/oshi/SystemInfo.java`:
- Around line 95-98: The isAvailable() method currently returns true
unconditionally causing the provider to be chosen on unsupported platforms;
change isAvailable() to perform the same platform/support check used when
creating the provider (i.e., reuse the same support matrix or helper used by
SystemInfoFactory creation logic) so it only returns true when the OS/hardware
implementation is actually supported and will not cause getOperatingSystem() or
getHardware() to throw; reference isAvailable(), SystemInfoFactory,
getOperatingSystem(), and getHardware() and call into or replicate the factory's
platform-support check so the availability result matches the creation logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: efbad1a1-422a-491e-bc75-5d4090a89870

📥 Commits

Reviewing files that changed from the base of the PR and between 921bd06 and bdcf759.

📒 Files selected for processing (20)
  • CHANGELOG.md
  • README.md
  • oshi-benchmark/pom.xml
  • oshi-common/pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-core-ffm/pom.xml
  • oshi-core-ffm/src/main/java/module-info.java
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-demo/pom.xml
  • oshi-dist/pom.xml
  • oshi-metrics/pom.xml
  • pom.xml
  • src/site/markdown/index.md
✅ Files skipped from review due to trivial changes (9)
  • oshi-common/src/main/java/oshi/spi/package-info.java
  • oshi-common/pom.xml
  • oshi-core/pom.xml
  • oshi-core/src/main/java/module-info.java
  • oshi-dist/pom.xml
  • oshi-benchmark/pom.xml
  • oshi-common/src/main/java/oshi/spi/SystemInfoProvider.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core-ffm/pom.xml
  • oshi-core-ffm/src/main/java/module-info.java
  • README.md
  • oshi-core/src/test/java/oshi/SystemInfoFactoryTest.java
  • oshi-demo/pom.xml
  • src/site/markdown/index.md
  • oshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-metrics/pom.xml
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🪛 markdownlint-cli2 (0.22.1)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (2)
CHANGELOG.md (1)

1-5: Changelog entry is clear and consistent with project conventions.

The new 7.2.0 feature bullet accurately describes the SPI/factory addition and matches the established CHANGELOG structure.

pom.xml (1)

7-7: Version bump looks correct for this release cycle.

Updating the parent POM to 7.2.0-SNAPSHOT is consistent with the SPI feature addition and module-wide version alignment.

@dbwiddis
dbwiddis force-pushed the feature/systeminfo-spi branch from bdcf759 to b0df109 Compare May 7, 2026 23:50
Add a SystemInfoProvider SPI and SystemInfoFactory in the oshi.spi
package, enabling automatic selection of the best available OSHI
implementation at runtime via ServiceLoader.

Bump version to 7.2.0-SNAPSHOT.
@dbwiddis
dbwiddis force-pushed the feature/systeminfo-spi branch from b0df109 to 1e01ec1 Compare May 8, 2026 00:02
@codecov

codecov Bot commented May 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.83%. Comparing base (153df0a) to head (1e01ec1).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...mmon/src/main/java/oshi/spi/SystemInfoFactory.java 57.14% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3234      +/-   ##
============================================
+ Coverage     63.78%   63.83%   +0.04%     
  Complexity       73       73              
============================================
  Files           421      422       +1     
  Lines         19725    19741      +16     
  Branches       3407     3411       +4     
============================================
+ Hits          12582    12601      +19     
+ Misses         5397     5387      -10     
- Partials       1746     1753       +7     
Flag Coverage Δ
linux 30.02% <62.50%> (+0.01%) ⬆️
macos 33.10% <62.50%> (+0.01%) ⬆️
windows 40.85% <62.50%> (+0.08%) ⬆️

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

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

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

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