Skip to content

Sonar java8-era modernization sweep (S1602, S1611, S1612, S8694) - #3394

Merged
dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:sonar-java8-modernization
Jun 13, 2026
Merged

dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:sonar-java8-modernization

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #3393, covering the mechanical java8-tagged SonarCloud findings. One commit per rule. No behavior change; verified locally with a clean install -P aggregate-coverage,native-comparison (full unit suite + NativeComparisonTest green) plus checkstyle/forbiddenapis/javadoc on the touched modules.

Applied

  • S1602 — three FFM cleanup/downcall lambdas with a redundant { ... } (one also a redundant return) collapsed to expression form.
  • S1611 — four LinuxSensors single-parameter lambdas had parenthesized params; parentheses removed.
  • S1612 — two lambdas that just forward their argument replaced with method references (Ole32FFM::CoUninitialize via runOrLog, and AuxvTest's NativeLongReader).
  • S8694 — numeric month arguments in LocalDate.of / LocalDateTime.of test literals replaced with java.time.Month constants.

Intentionally left (false positives in context)

  • S1612 × 5 (the assertDoesNotThrow(...) call sites in DmidecodeTest, LshalTest, CpuInfoTest) — a method reference there is ambiguous between the Executable and ThrowingSupplier<T> overloads of assertDoesNotThrow; the lambda is required to compile.
  • S2093 × 5 (WindowsInternetProtocolStatsJNA × 4, MacHWDiskStoreFFM × 1) — the JNA sites reassign buf inside the buffer-grow loop (not effectively final), and the Mac site's outer try wraps a borrowed-singleton CFAllocatorRef (@SuppressWarnings("resource")) that must not be closed. Neither converts to try-with-resources without changing behavior.
  • S3824 × 1 (SolarisComputerSystem) — the guard is !containsKey(k) || isBlank(get(k)), i.e. it also replaces blank values; computeIfAbsent only fires when the key is absent, so the suggestion would change behavior.
  • S2143 × 1 (ProcessorPanel demo) — the java.util.Date is required by JFreeChart's new Second(Date) constructor.

I'll mark the false-positive findings as won't-fix in SonarCloud separately.

Summary by CodeRabbit

  • Refactor

    • Improved lambda expressions and method references across sensor and Windows FFM platform code.
    • Transitioned from numeric month literals to Month enum constants in date handling.
  • Tests

    • Enhanced test code readability by updating date specifications to use Month enum constants.

dbwiddis added 4 commits June 13, 2026 12:21
Three FFM cleanup/downcall lambdas had a redundant '{ ... }' (and one a
redundant 'return'); convert them to expression lambdas. No behavior change.
Four single-parameter lambdas in LinuxSensors used parenthesized parameters
((s), (index), (files)); remove the parentheses. No behavior change.
Replace two lambdas that simply forward their argument with method references:
Ole32FFM.CoUninitialize (runOrLog) and AuxvTest's NativeLongReader.

The remaining S1612 findings (the assertDoesNotThrow call sites) are left as
lambdas on purpose: a method reference there is ambiguous between the
Executable and ThrowingSupplier overloads of assertDoesNotThrow, so the lambda
is required to compile.
Replace numeric month arguments in LocalDate.of/LocalDateTime.of test literals
with the corresponding java.time.Month constants for readability. No behavior
change.
@coderabbitai

coderabbitai Bot commented Jun 13, 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: afad2113-3458-4ff1-8d91-788bc241ab41

📥 Commits

Reviewing files that changed from the base of the PR and between a2a14c6 and ecf1e49.

📒 Files selected for processing (8)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractPowerSourceTest.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/NtDllFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/com/BStrFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/com/Ole32FFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
📜 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 21, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 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/hardware/common/platform/linux/LinuxSensors.java
🔇 Additional comments (8)
oshi-common/src/test/java/oshi/hardware/common/AbstractPowerSourceTest.java (1)

12-12: LGTM!

Also applies to: 24-25, 62-62

oshi-common/src/test/java/oshi/util/ParseUtilTest.java (1)

27-27: LGTM!

Also applies to: 971-984

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java (1)

50-50: LGTM!

Also applies to: 53-53, 167-167, 178-178

oshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java (1)

25-26: Verify method reference type compatibility with functional interface.

The method reference FileUtil::readIntFromBuffer returns int, but Auxv.NativeLongReader.read(ByteBuffer) expects a long return type. While the PR summary claims local verification with a passing test suite, this type mismatch requires confirmation.

To verify the type compatibility, please confirm:

  1. Whether int-to-long widening is implicitly applied at assignment
  2. Whether FileUtil::readIntFromBuffer is actually being called (32-bit platform scenario)
  3. Whether the compiled classes show any type-casting bytecode

Alternatively, confirm that the local test environment and this codebase version align, and that AuxvTest::testQueryAuxv() passes on a 32-bit platform.

oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/NtDllFFM.java (1)

126-129: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/com/BStrFFM.java (1)

72-72: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/com/Ole32FFM.java (1)

98-98: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java (1)

135-138: LGTM!


📝 Walkthrough

Walkthrough

This PR refactors code style across multiple modules by simplifying lambda expressions and modernizing date construction in tests. Changes include removing redundant lambda parameter parentheses, converting lambdas to method references, and replacing numeric month literals with Month enum constants. No functional behavior is altered.

Changes

Code Style Modernization

Layer / File(s) Summary
Lambda Expression Simplification
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxSensors.java, oshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/NtDllFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/com/BStrFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/com/Ole32FFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
Lambda parameters are simplified by removing redundant parentheses around single parameters in stream pipelines and method arguments. Block lambdas are converted to single-expression forms and method references where applicable, affecting priority list filtering, FFM COM calls, and system function invocations.
Month Enum Constant Migration
oshi-common/src/test/java/oshi/hardware/common/AbstractPowerSourceTest.java, oshi-common/src/test/java/oshi/util/ParseUtilTest.java
Test date assertions are updated to use Month enum constants (JANUARY, JUNE, SEPTEMBER) instead of numeric month literals in LocalDate and LocalDateTime construction, with Month import additions for both test files.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • oshi/oshi#3263: Refactors the same AuxvTest.READER logic by switching to a direct method reference.
  • oshi/oshi#3157: Also modifies MacCentralProcessorFFM.queryProcessorCpuLoadTicks() with changes to CPU tick offset operands.
  • oshi/oshi#3287: Refactors the same queryProcessorCpuLoadTicks() method with arena/failure handling via callInArenaOrDefault.

Poem

🐰 Lambdas lean and Month enums shine,
Parentheses trimmed, one line at a time,
Code reads cleaner, logic holds true,
Style modernized through and through! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% 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 title accurately describes the main change: applying SonarCloud modernization suggestions for Java 8-era patterns across multiple files.
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 unit tests (beta)
  • Create PR with unit tests

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

❤️ Share

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

@codecov

codecov Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.02%. Comparing base (a2a14c6) to head (ecf1e49).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...i/hardware/common/platform/linux/LinuxSensors.java 25.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3394      +/-   ##
============================================
+ Coverage     68.65%   75.02%   +6.37%     
  Complexity       76       76              
============================================
  Files           579      579              
  Lines         21363    21363              
  Branches       3560     3560              
============================================
+ Hits          14666    16027    +1361     
+ Misses         4868     3308    -1560     
- Partials       1829     2028     +199     
Flag Coverage Δ
freebsd 26.31% <14.28%> (ø)
linux 30.91% <14.28%> (+<0.01%) ⬆️
macos 31.22% <57.14%> (ø)
openbsd 25.78% <14.28%> (-0.01%) ⬇️
solaris 27.87% <14.28%> (?)
windows 39.53% <14.28%> (+<0.01%) ⬆️

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 89090ff into oshi:master Jun 13, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the sonar-java8-modernization branch June 13, 2026 19: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