Skip to content

Return 0 for unavailable CPU temperature everywhere, and make IPConnection.getState() non-null - #3781

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:align-sentinel-docs
Oct 9, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:align-sentinel-docs

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Part of the sentinel-convention sweep that follows #3767: getters whose documented or actual sentinel differed from the convention in the oshi.hardware / oshi.software.os package docs.

  • Sensors.getCpuTemperature() was documented as "0 or NaN". FreeBSD (JNA and FFM) returned NaN; every other platform returned 0. AbstractSensors, the only Sensors implementor, now maps NaN to 0 before memoizing, so the contract holds for every platform and backend. The Javadoc says 0 only, and the tests that tolerated NaN (SensorsTest and both macOS plausibility tests) no longer do.
  • IPConnection.getState() was @Nullable and documented as null for UDP or an unknown state. No implementation passes null (UDP gets TcpState.NONE, unrecognized states TcpState.UNKNOWN), so this is a documentation and annotation fix; the public constructor normalizes a null argument to UNKNOWN.

The only behavior change is FreeBSD's temperature sentinel; it has a CHANGELOG entry.

Testing: full gate on oshi-common, oshi-core and oshi-core-ffm with -Perror-prone, 0 failures, on macOS. New AbstractSensorsTest case covers the NaN mapping. The FreeBSD path itself is untested locally and reaches the getter only through that shared code.

Summary by CodeRabbit

  • Bug Fixes
    • CPU temperature now consistently returns 0 when unavailable, rather than NaN.
    • TCP connection states are no longer null: unknown states return UNKNOWN, while UDP connections return NONE.

…ction.getState() non-null

Sensors.getCpuTemperature() was documented as "0 or NaN" when unavailable.
Only FreeBSD (both backends) returned NaN; AbstractSensors now maps a NaN
reading to 0 before memoizing, so every implementation reports the single
sentinel the package documentation describes.

IPConnection.getState() was @nullable and documented to return null for UDP
or an unknown state, but no implementation ever passed null: UDP rows carry
TcpState.NONE and unrecognized states TcpState.UNKNOWN. The getter is now
non-null, and the public constructor normalizes a null argument to UNKNOWN.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f3376062-c7ba-47bf-abad-8248d038a736

📥 Commits

Reviewing files that changed from the base of the PR and between 02fe810 and 2401891.


📒 Files selected for processing (8)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/Sensors.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractSensors.java
  • oshi-common/src/main/java/oshi/software/os/InternetProtocolStats.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractSensorsTest.java
  • oshi-core-ffm/src/test/java/oshi/ffm/MacSensorsPlausibilityFFMTest.java
  • oshi-core/src/test/java/oshi/hardware/platform/shared/SensorsTest.java
  • oshi-core/src/test/java/oshi/util/platform/mac/MacSensorsPlausibilityTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📜 Recent review details
⏰ Context from checks skipped due to timeout. (14)
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Error Prone
  • GitHub Check: Analyze (java)

🧰 Additional context used
📚 Code guidelines (2)
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered

📓 Path-based instructions (3)
Source excerpt: `oshi-core-ffm` may not reference `com.sun.jna.**`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/test/java/oshi/ffm/MacSensorsPlausibilityFFMTest.java

Source excerpt: `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/oshi/hardware/Sensors.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractSensorsTest.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractSensors.java
  • oshi-common/src/main/java/oshi/software/os/InternetProtocolStats.java

Source excerpt: The Changelog lets users know what's changed.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md



🔇 Additional comments (1)
oshi-common/src/main/java/oshi/software/os/InternetProtocolStats.java (1)

485-485: LGTM!

Also applies to: 498-499, 511-511, 573-576





📝 Walkthrough

Walkthrough

The changes normalize unavailable CPU temperature results to zero and update related documentation and tests. They also make IPConnection.getState() return a non-null TcpState, using TcpState.UNKNOWN when the constructor receives null.

Changes

CPU temperature fallback

Layer / File(s) Summary
CPU temperature fallback and validation
oshi-common/src/main/java/oshi/hardware/common/AbstractSensors.java, oshi-common/src/main/java/oshi/hardware/Sensors.java, oshi-common/src/test/java/oshi/hardware/common/AbstractSensorsTest.java, oshi-core/src/test/java/oshi/hardware/platform/shared/SensorsTest.java, oshi-core-ffm/src/test/java/oshi/ffm/MacSensorsPlausibilityFFMTest.java, oshi-core/src/test/java/oshi/util/platform/mac/MacSensorsPlausibilityTest.java, CHANGELOG.md
AbstractSensors converts a NaN temperature result to 0d. API documentation, changelog text, and sensor tests reflect zero as the unavailable-temperature result. Sensor plausibility tests no longer accept NaN.

IP connection state

Layer / File(s) Summary
Normalize IP connection states
oshi-common/src/main/java/oshi/software/os/InternetProtocolStats.java
IPConnection converts a null state to TcpState.UNKNOWN. Its state field and getState() return type are non-null. The documentation identifies TcpState.NONE for UDP connections and TcpState.UNKNOWN for unknown states.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 24018

Unavailable CPU temperatures return zero through the public getter, and unknown IP connection states return UNKNOWN. The supplied evidence shows these changes align with their documented contracts, with no established merge risk.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 7 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies both primary changes: returning 0 for unavailable CPU temperature and making IPConnection.getState() non-null.
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.

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 7 files. (1 skipped: 1 unsupported.)



  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the sensors bright,
NaN becomes a zero right.
TCP states now have a name,
Unknown fills the null-shaped frame.
I hop through tests and changelog lines,
Then nibble clover in the pines.

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

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.30%. Comparing base (02fe810) to head (2401891).

Files with missing lines Patch % Lines
...n/java/oshi/software/os/InternetProtocolStats.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3781      +/-   ##
============================================
- Coverage     80.40%   80.30%   -0.11%     
- Complexity       83      370     +287     
============================================
  Files           722      722              
  Lines         25917    25920       +3     
  Branches       4376     4378       +2     
============================================
- Hits          20838    20814      -24     
- Misses         2850     2872      +22     
- Partials       2229     2234       +5     
Flag Coverage Δ
freebsd 36.42% <80.00%> (+0.01%) ⬆️
linux 40.20% <80.00%> (+0.01%) ⬆️
macos 41.03% <80.00%> (-0.05%) ⬇️
netbsd 35.11% <80.00%> (-0.03%) ⬇️
openbsd 35.66% <80.00%> (-0.02%) ⬇️
solaris 37.02% <80.00%> (-0.01%) ⬇️
windows 47.31% <80.00%> (-0.02%) ⬇️

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 9bc3b2c into oshi:master Oct 9, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the align-sentinel-docs branch October 9, 2026 22:34
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