Repository navigation
Sonar Category C cleanup: dead code + redundant casts (S1905, S1068, S1144, S1130) - #3395
Conversation
Drop 18 redundant casts. Each was verified safe: every '(long) i * X' multiplication has a long right operand (X is increment, PTR_SIZE, ENUM_SERVICE_STATUS_PROCESS_SIZE, ADDRESS.byteSize(), etc.), so the product was already computed in long and no narrowing/overflow was being prevented. The two '(int)' casts on short/byte values are redundant because the '&' operator already promotes to int, and getPartitions() is already declared List<HWPartition>. No behavior change.
Delete eight genuinely dead private fields: unused loggers (MacGpuStatsFFM, WindowsFileSystemFFM, DragonFlyBsdOSProcessJNA), write-only fields whose derived state is what's actually used (MacGpuStatsFFM.cardName, CupsFunctions.CUPS_LIBRARY - the bound method handles use the local lookup), and leftover constants (AdlUtilFFM.PERF_GPU_ACTIVITY_OFFSET, WindowsGraphicsCardJNA.MB_TO_BYTES from a removed LHM code path, OshiMetricsTest.hal). NOT deleted: DiskMetrics.diskStores. It looks unused but is a deliberate strong reference (GC root) that keeps the disk objects alive, because Micrometer's FunctionCounter only holds WeakReferences to them; deleting it would silently break the disk metrics after a GC. Documented and marked @SuppressWarnings("java:S1068").
Delete four dead overloads (not prevent-instantiation idioms - each class is instantiated via its other constructor): the pre-diskType constructors of MacHWDiskStoreFFM / WindowsHWDiskStoreFFM / WindowsHWDiskStoreJNA (the diskType variants are the ones getDisks() uses), and LinuxGraphicsCard's queryLspciMemorySize(String) overload, which nothing calls - the caller already runs lspci and invokes the List<String> overload directly. No behavior change.
MacInstalledApps.readStringValue declared 'throws Exception' but does only string parsing and cannot throw it. Removing the clause is safe: the sole caller wraps it in a catch(Exception) that remains valid (it still catches RuntimeException and other calls in the same try). No behavior change. The six JMXOshiAgentServer S1130 findings are intentionally left: they are @OverRide stubs whose throws clauses mirror the JMX MBeanServer interface contract (Java forbids an override from adding new checked exceptions), so removing Sonar's flagged subset would make them inconsistent with their siblings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (24)
💤 Files with no reviewable changes (10)
📜 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). (11)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (14)
📝 WalkthroughWalkthroughAcross 23 files in oshi-common, oshi-core, oshi-core-ffm, and oshi-metrics, this PR removes unused SLF4J logger fields, dead private constants and methods, redundant private constructor overloads (consolidating to ChangesCode Cleanup: Dead Code, Cast, and Logger Removal
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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 unit tests (beta)
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 |
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #3395 +/- ##
============================================
+ Coverage 75.02% 75.08% +0.05%
Complexity 76 76
============================================
Files 579 579
Lines 21364 21355 -9
Branches 3556 3556
============================================
+ Hits 16029 16035 +6
+ Misses 3311 3300 -11
+ Partials 2024 2020 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Mechanical dead-code / redundancy cleanup from the Sonar triage backlog, 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.Fixed
(long) i * Xhad alongright operand (so the product was already computed inlong— no overflow was being prevented), the(int)casts onshort/byteare redundant under&promotion, andgetPartitions()is alreadyList<HWPartition>.diskTypeconstructors; an inlinedqueryLspciMemorySize(String)). These are not prevent-instantiation idioms.throws ExceptiononMacInstalledApps.readStringValue.Notable: a bug not introduced
DiskMetrics.diskStoreslooks like an unused field (S1068) but is a deliberate GC root — Micrometer'sFunctionCounteronly holds aWeakReferenceto each disk object, so this strong reference keeps them alive. Deleting it would silently break the disk metrics after a GC. Kept it, documented, and marked@SuppressWarnings("java:S1068").Intentionally deferred
JMXOshiAgentServer) —@Overridestubs whosethrowsmirror the JMXMBeanServerinterface contract; removing Sonar's flagged subset would make them inconsistent with their siblings. Better suppressed-as-conformance or left.Remaining Category C (
S1168null→empty,S4144identical bodies) involves caller-by-caller analysis and is a deliberate follow-up.Summary by CodeRabbit
Refactor
Chores
Tests