Repository navigation
Add SystemInfoProvider SPI for automatic implementation selection - #3234
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (20)
✅ Files skipped from review due to trivial changes (11)
🚧 Files skipped from review as they are similar to previous changes (8)
📜 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)
🧰 Additional context used🪛 markdownlint-cli2 (0.22.1)CHANGELOG.md[warning] 3-3: Heading levels should only increment by one level at a time (MD001, heading-increment) 🔇 Additional comments (1)
📝 WalkthroughWalkthroughThis 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. ChangesSystemInfoProvider SPI and Runtime Selection
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
1b17049 to
eed5477
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (21)
CHANGELOG.mdREADME.mdoshi-benchmark/pom.xmloshi-common/pom.xmloshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/hardware/common/NoOpGpuStats.javaoshi-common/src/main/java/oshi/spi/SystemInfoFactory.javaoshi-common/src/main/java/oshi/spi/SystemInfoProvider.javaoshi-common/src/main/java/oshi/spi/package-info.javaoshi-core-ffm/pom.xmloshi-core-ffm/src/main/java/module-info.javaoshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.javaoshi-core/pom.xmloshi-core/src/main/java/module-info.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-core/src/test/java/oshi/SystemInfoFactoryTest.javaoshi-demo/pom.xmloshi-dist/pom.xmloshi-metrics/pom.xmlpom.xmlsrc/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.javaoshi-common/src/main/java/oshi/hardware/common/NoOpGpuStats.javaoshi-common/src/main/java/oshi/spi/SystemInfoFactory.javaoshi-common/src/main/java/module-info.javaoshi-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-SNAPSHOTis consistent with the SPI rollout across modules.oshi-demo/pom.xml (1)
8-8: LGTM for demo module version sync.This keeps
oshi-demoaligned 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
SystemInfoFactorydiscovery 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/SystemInfoFactoryAPI.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
ServiceLoaderdiscovery 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
ServiceLoaderresolution.
There was a problem hiding this comment.
♻️ Duplicate comments (2)
CHANGELOG.md (1)
3-3:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winHeading level jump (H1 → H5) still violates MD001.
##### New Featuresat 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 returnstrue.This issue was flagged in a prior review and remains unresolved.
createOperatingSystem()andcreateHardware()both throwUnsupportedOperationExceptionon thedefaultbranch, so returningtrueon an unsupported platform allowsSystemInfoFactoryto 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
📒 Files selected for processing (20)
CHANGELOG.mdREADME.mdoshi-benchmark/pom.xmloshi-common/pom.xmloshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/spi/SystemInfoFactory.javaoshi-common/src/main/java/oshi/spi/SystemInfoProvider.javaoshi-common/src/main/java/oshi/spi/package-info.javaoshi-core-ffm/pom.xmloshi-core-ffm/src/main/java/module-info.javaoshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.javaoshi-core/pom.xmloshi-core/src/main/java/module-info.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-core/src/test/java/oshi/SystemInfoFactoryTest.javaoshi-demo/pom.xmloshi-dist/pom.xmloshi-metrics/pom.xmlpom.xmlsrc/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)
eed5477 to
921bd06
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
oshi-core/src/main/java/oshi/SystemInfo.java (1)
95-98:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
isAvailable()unconditionally returnstrue, violating the SPI availability contract on unsupported platforms.
createOperatingSystem()andcreateHardware()both throwUnsupportedOperationExceptionvia theirdefaultbranch. IfSystemInfoFactoryselects this provider (becauseisAvailable()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
📒 Files selected for processing (20)
CHANGELOG.mdREADME.mdoshi-benchmark/pom.xmloshi-common/pom.xmloshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/spi/SystemInfoFactory.javaoshi-common/src/main/java/oshi/spi/SystemInfoProvider.javaoshi-common/src/main/java/oshi/spi/package-info.javaoshi-core-ffm/pom.xmloshi-core-ffm/src/main/java/module-info.javaoshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.javaoshi-core/pom.xmloshi-core/src/main/java/module-info.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-core/src/test/java/oshi/SystemInfoFactoryTest.javaoshi-demo/pom.xmloshi-dist/pom.xmloshi-metrics/pom.xmlpom.xmlsrc/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-parentto7.2.0-SNAPSHOTis consistent with the PR’s cross-module version update and keeps${project.version}resolution coherent foroshi-core.
55-63: Explicit JAR manifest override is a good scoped change.This plugin block cleanly isolates
oshi-demofrom 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.
921bd06 to
bdcf759
Compare
There was a problem hiding this comment.
♻️ 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
trueunconditionally can letSystemInfoFactoryselect this provider on unsupported platforms, but latergetOperatingSystem()/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
📒 Files selected for processing (20)
CHANGELOG.mdREADME.mdoshi-benchmark/pom.xmloshi-common/pom.xmloshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/spi/SystemInfoFactory.javaoshi-common/src/main/java/oshi/spi/SystemInfoProvider.javaoshi-common/src/main/java/oshi/spi/package-info.javaoshi-core-ffm/pom.xmloshi-core-ffm/src/main/java/module-info.javaoshi-core-ffm/src/main/java/oshi/ffm/SystemInfo.javaoshi-core/pom.xmloshi-core/src/main/java/module-info.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-core/src/test/java/oshi/SystemInfoFactoryTest.javaoshi-demo/pom.xmloshi-dist/pom.xmloshi-metrics/pom.xmlpom.xmlsrc/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-SNAPSHOTis consistent with the SPI feature addition and module-wide version alignment.
bdcf759 to
b0df109
Compare
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.
b0df109 to
1e01ec1
Compare
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Resolves discussion #2993
Summary
Adds a
SystemInfoProviderSPI (Service Provider Interface) andSystemInfoFactoryin theoshi.spipackage, enabling automatic selection of the best available OSHI implementation at runtime.Users who have both
oshi-core(JNA) andoshi-core-ffm(FFM) as dependencies can now use:The factory uses
java.util.ServiceLoaderto discover providers, filters byisAvailable(), 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 inoshi-commonwithgetOperatingSystem(),getHardware(),getPriority(),isAvailable()SystemInfoFactory— ServiceLoader-based factory inoshi-commonSystemInfoclasses implement the interface (binary-compatible change)provides/usesdeclarations + classpathMETA-INF/servicesfor both module path and classpath usageBackward compatibility
new oshi.SystemInfo()andnew oshi.ffm.SystemInfo()continue to work unchangedTesting
SystemInfoFactoryTestverifies provider discovery, priority, availability, and that hardware/OS instances are returnedSummary by CodeRabbit
New Features
Documentation
Tests
Chores