Skip to content

Clear the Sonar findings from the 7.8.0 work - #3901

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:sonar-cleanup
Nov 14, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:sonar-cleanup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Release prep. No user-visible change, so no CHANGELOG entry.

SonarCloud had 81 open issues on master, all from this cycle's PRs. CodeQL code scanning has no open alerts; CodeQL Code Quality had two findings, below.

Fixed here (27):

  • S8786: super-linear regexes in PkgInfoInstalledApps, SolarisInstalledApps and NetBsdGraphicsCard, made possessive where that leaves the match unchanged. A unit-numbered device name becomes \\w++(?<=\\d) instead of the backtracking \\w+\\d+, and the OpenBSD name/version split is written without a lazy quantifier.
  • S135: the Solaris smbios and NetBSD dmesg loops are restructured as if/else chains.
  • Mechanical: S3252, S1192 ×2, S5411 ×2, S9435 ×2, S3358, S4276, S6213 ×2, S1128, S1075 ×2, S125 (one comment that read as code), and S116 for the tb_last fields of the AIX CPU POJOs (now tbLast; the JNA struct field keeps its C name).

Accepted in SonarCloud, with a reason comment on each (54):

  • S3776 (cognitive complexity) and S9398, per project policy.
  • Native binding names in IPHlpAPI, Kernel32FFM and IPHlpAPIFFM: S100, S101, S116, S117, S2160.
  • S107 where the parameters mirror the fields being filled.
  • The C-prototype comments in MacSystemFunctions.
  • Early exits in the Windows battery enumeration loops.
  • The lazy device-name split in FreeBsdSoundCard.

Sonar config now loaded: config/sonar-project.properties holds issue-ignore rules for the JNA naming conventions. properties-maven-plugin was only declared in pluginManagement and never bound, so the file was never read, which is why those findings were accepted one by one. The plugin is now bound in the root build, and the rules also cover S101, S116 and S117 under jna, and S100 under ffm/platform. Confirmed with ./mvnw initialize help:evaluate -Dexpression=sonar.issue.ignore.multicriteria in the root and a module.

CodeQL Code Quality findings (2):

  • AIX environment loop never updates addr: a false positive, but the code was misleading. addr is the env table's base, read once (pr_envp points to the pointer table, as pr_argv does), not an entry to re-read. Entries were read at offset, and the null entry ended the loop through break. Both AIX readers (JNA and FFM) now name it envTable, test it once and walk the entries by index. The cap is now exactly 500 entries; --limit stopped at 499.
  • useLegacySystemCounters() test intent not at class level: to be dismissed. The method javadoc already says it is overridable for tests, and both Windows twins say they are not final for that reason.

Verification: full gate with -Paggregate-coverage -Perror-prone and tests; existing fixture tests cover every changed regex and loop.

Summary by CodeRabbit

  • Bug Fixes

    • Improved graphics-card detection on NetBSD and package information parsing on Unix systems.
    • Improved Linux power-supply and sensor readings, including when Raspberry Pi firmware data is unavailable.
    • Improved temperature handling when CPU readings are missing and Solaris memory-device parsing.
    • Increased the number of process environment entries that can be captured on AIX.
  • Refactor

    • Updated hardware and software information handling across several platforms.

- S8786: possessive quantifiers in the BSD pkg_info, Solaris FMRI and NetBSD
  dmesg patterns; a device name that must end in a unit number is matched as
  \w++(?<=\d) rather than by backtracking \w+\d+. The OpenBSD
  name/version split follows packages-specs(7) without a lazy quantifier.
- S135: the Solaris smbios and NetBSD dmesg loops are if/else chains; the
  smbios key=value parsing moved into the record class.
- S3252: AF_* constants statically imported from JNA's IPHlpAPI.
- S1192: SUPER_IO and a DEVICE constant replace repeated literals.
- S5411, S9435, S3358, S4276, S6213, S1128, S1075, S125 (a comment that read
  as code), and S116 for the tb_last fields of the AIX CPU POJOs (tbLast).
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes update hardware queries and parsing across several operating systems, rename the AIX timebase field, refactor memory and installed-application parsing, and adjust FreeBSD and Windows API call sites.

Changes: Hardware queries and parsing

Layer / File(s) Summary
Linux sysfs paths and sensor checks
oshi-common/.../LinuxGraphicsCard.java, oshi-common/.../LinuxPowerSource.java, oshi-common/.../LinuxSensors.java
Linux graphics paths use a shared /device constant, power-supply paths use each listed file’s path, and Raspberry Pi firmware queries run only when availability is Boolean.TRUE.
Hardware status and data parsing
oshi-common/.../Envstat.java, oshi-common/.../MacNetworkIF.java, oshi-common/.../NetBsdGraphicsCard.java, oshi-common/.../SolarisCentralProcessor.java, oshi-common/.../WindowsSensors.java
Temperature selection uses explicit branches. macOS network-status conditions are inverted without changing outcomes. NetBSD attachment parsing and hardware-related references are updated. The Solaris cache comment is revised.

AIX timebase field

Layer / File(s) Summary
Rename and propagate the timebase field
oshi-common/.../AixCentralProcessor.java, oshi-common/.../AixCentralProcessorTest.java, oshi-core-ffm/.../PerfstatCpuFFM.java, oshi-core-ffm/.../AixCentralProcessorFFM.java, oshi-core/.../AixCentralProcessorJNA.java
The AIX timebase field changes from tb_last to tbLast. FFM and JNA query paths, frequency calculation, and the test use the renamed field.

OS inventory parsing

Layer / File(s) Summary
Solaris SMBIOS record parsing
oshi-common/.../SolarisGlobalMemory.java
SmbiosMemoryDevice now parses key/value lines. Record finalization and filtering to devices with positive capacity remain in place.
Installed-application record parsing
oshi-common/.../LinuxInstalledApps.java, oshi-common/.../PkgInfoInstalledApps.java, oshi-common/.../SolarisInstalledApps.java
APK record conversion is extracted into a helper. BSD and Solaris package-name patterns use updated quantifiers and matching rules.

FreeBSD sound-card callback type

Layer / File(s) Summary
Update the sound-card callback type
oshi-common/.../FreeBsdSoundCard.java, oshi-common/.../FreeBsdSoundCardTest.java
The parser parameter and test helper return type change from Function<List<String>, List<String>> to UnaryOperator<List<String>>.

Windows DNS address-family constants

Layer / File(s) Summary
Use imported address-family constants
oshi-core/.../WindowsNetworkParamsJNA.java
DNS queries and address-family comparisons use statically imported constants instead of qualified IPHlpAPI constants.

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

Change: Refactor

Merge Risk: Minimal · up to 03fd7

This is release-preparation cleanup with no intended user-visible change. No concrete merge-blocking risk was identified in the supplied change summaries.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Clear the Sonar findings from the 7.8.0 work" matches the main purpose of the PR. The PR fixes 27 Sonar findings with regex, loop, and mechanical updates, and it accepts 54 other findings w…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "Clear the Sonar findings from the 7.8.0 work" matches the main purpose of the PR. The PR fixes 27 Sonar findings with regex, loop, and mechanical updates, and it accepts 54 other findings with reason comments. It also corrects the sonar-project.properties loading by binding properties-maven-plugin in the root build. The title does not name the specific changes, but it describes the primary intent and it is not vague.

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 sensor glow,
Then follows paths where data flow.
A field gets named with care,
While parsers sort the records there.
I thump for tidy code below.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: db3257c7-c704-48e6-bb0b-972af19116f7
Commits

Reviewing files that changed from the base of the PR and between 88e43d0 and 03fd7f3.

Files selected for processing: 2

  • oshi-core-ffm/src/main/java/oshi/driver/unix/aix/PsInfoFFM.java
  • oshi-core/src/main/java/oshi/driver/unix/aix/PsInfoJNA.java

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

Recent review details

Context from checks skipped due to timeout: 7

  • GitHub Check: CodeRabbit
  • GitHub Check: Test JDK 25, DragonFly BSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Analyze (java)
Additional context used

Code guidelines: 2

FAQ.md — auto-discovered
AGENTS.md — auto-discovered
Path-based instructions: 3

Applicability reference: AGENTS.md: # AGENTS.md **API compatibility.**

CodeRabbit inference engine (FAQ.md)

Files:

  • oshi-core-ffm/src/main/java/oshi/driver/unix/aix/PsInfoFFM.java
  • oshi-core/src/main/java/oshi/driver/unix/aix/PsInfoJNA.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-core-ffm` may not reference `com.sun.jna.**`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/main/java/oshi/driver/unix/aix/PsInfoFFM.java
Source excerpt: **Language level.**

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/main/java/oshi/driver/unix/aix/PsInfoJNA.java

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.57895% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.57%. Comparing base (444b65f) to head (03fd7f3).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../src/main/java/oshi/driver/unix/aix/PsInfoFFM.java 0.00% 5 Missing ⚠️
.../src/main/java/oshi/driver/unix/aix/PsInfoJNA.java 0.00% 3 Missing ⚠️
.../common/platform/unix/aix/AixCentralProcessor.java 50.00% 0 Missing and 1 partial ⚠️
...mon/platform/unix/solaris/SolarisGlobalMemory.java 96.66% 0 Missing and 1 partial ⚠️
.../oshi/driver/unix/aix/perfstat/PerfstatCpuFFM.java 0.00% 1 Missing ⚠️
...ware/platform/unix/aix/AixCentralProcessorFFM.java 0.00% 1 Missing ⚠️
...ware/platform/unix/aix/AixCentralProcessorJNA.java 0.00% 1 Missing ⚠️
...i/software/os/windows/WindowsNetworkParamsJNA.java 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3901      +/-   ##
============================================
- Coverage     81.64%   81.57%   -0.07%     
- Complexity     1288     1314      +26     
============================================
  Files           735      735              
  Lines         27695    27695              
  Branches       4798     4799       +1     
============================================
- Hits          22611    22593      -18     
- Misses         2780     2804      +24     
+ Partials       2304     2298       -6     
Flag Coverage Δ
dragonflybsd 39.11% <67.10%> (+0.03%) ⬆️
freebsd 39.64% <67.10%> (+0.01%) ⬆️
linux 43.78% <77.63%> (+0.02%) ⬆️
macos 44.53% <67.10%> (+<0.01%) ⬆️
netbsd 38.96% <68.42%> (+0.01%) ⬆️
openbsd 39.44% <67.10%> (+0.01%) ⬆️
solaris 40.75% <67.10%> (+0.01%) ⬆️
windows 50.52% <68.42%> (-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.

config/sonar-project.properties was read by properties-maven-plugin, but the
plugin was only declared in pluginManagement and never bound, so none of its
ignore rules reached the analysis and the JNA naming findings were accepted
by hand. Bind it, and cover the remaining binding conventions: S101, S116 and
S117 under jna, and S100 under ffm/platform.
CodeQL flagged the env loop because its condition tested addr, which never
changed. addr is the table's base, read once (pr_envp points to the pointer
table, as pr_argv does), not an entry to re-read: entries were read at
offset, and the null entry ended the loop through break. Name it envTable,
test it once, and walk its entries by index, in both the JNA and FFM readers.
The cap is 500 entries, where --limit stopped at 499.
@dbwiddis
dbwiddis merged commit 35eb5df into oshi:master Nov 14, 2026
21 checks passed
@dbwiddis
dbwiddis deleted the sonar-cleanup branch November 14, 2026 23:04
dbwiddis added a commit that referenced this pull request Nov 15, 2026
#3902)

* Annotate IOKitProvider registry getters @nullable

The RegistryEntry getters document returning null when a property or name is
absent, and the JNA and FFM entries delegate to IOKit calls that do, but none
carried @nullable, so NullAway could not check their callers. Every existing
caller already handles null; the build is unchanged.

* Report ARM64 Windows processor stepping and ID from MIDR_EL1

On ARM64 the registry Identifier reads "ARMv8 (64-bit) Family 8 Model D49
Revision 0": no Stepping, so stepping was empty, and Win32_Processor's
ProcessorId is all zeros (GitHub windows-11-arm runner, Azure Cobalt 100).
Each processor's registry key carries MIDR_EL1 as CP 4000 (0x410fd490 there).
Stepping is now Linux's r<variant>p<revision> from it, and the processor ID
the MIDR in hex followed by eight zeros, as Linux reports on ARM. Both twins
read the QWORD; the choice lives in WindowsCentralProcessor.

* Use the SUPER_IO constant for the LHM voltage sensors

The last Sonar S1192 finding on master, next to the fan read fixed in #3901.

* Stop recommending the jLibreHardwareMonitor dependency

Its static PowerShell session is never closed and holds two non-daemon
threads, so a JVM with the jar on the class path does not exit after main
returns. It bundles LibreHardwareMonitorLib 0.9.4, whose WinRing0 driver
Microsoft Defender flags as a hacking tool. It also returns nothing on some
hosts (#3707). The maintainer has not answered any report (filed as
pandalxb/jLibreHardwareMonitor#2), so the README, the FAQ and the Sensors
javadoc now point to the LibreHardwareMonitor application instead. The FAQ
lists the problems and says support may be removed in a future release.
OSHI still reads the jar when it is present.

The Sensors interface javadoc also listed the sources in the wrong order.
Fixed that here.

Also adds the CHANGELOG entry for the ARM64 Windows stepping change.

* State which LibreHardwareMonitor versions publish to WMI

LibreHardwareMonitor 0.9.5 removed its WMI provider (upstream aaf65f5,
"no longer working with .NET 10"), and later releases do not restore it.
OSHI's ROOT\LibreHardwareMonitor queries therefore find nothing with a
current release. The README, FAQ, CHANGELOG and Sensors javadoc now say
that only OpenHardwareMonitor and LibreHardwareMonitor 0.9.4 and earlier
publish to WMI, and that both load the WinRing0 driver Defender flags.
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