Repository navigation
Reduce Auxv duplication with functional interface - #3263
Conversation
|
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 (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 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). (12)
📝 WalkthroughWalkthroughConsolidates duplicate /proc/self/auxv parsing into a shared ChangesAuxiliary Vector Parsing Consolidation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3263 +/- ##
============================================
- Coverage 74.26% 74.15% -0.11%
Complexity 73 73
============================================
Files 396 397 +1
Lines 16096 16091 -5
Branches 2589 2587 -2
============================================
- Hits 11954 11933 -21
- Misses 2631 2639 +8
- Partials 1511 1519 +8
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:
|
7fa3276 to
426c370
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java (1)
19-27: ⚡ Quick winGate or adapt this test for native-long width.
Line 24 hardcodes an 8-byte reader, but the class is only Linux-gated. On 32-bit Linux, auxv entries are native-long width and this test can misparse data. Please gate to 64-bit or switch to a width-aware test reader.
Example gating approach
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.junit.jupiter.api.condition.OS; @@ `@EnabledOnOs`(OS.LINUX) +@EnabledIfSystemProperty(named = "sun.arch.data.model", matches = "64") class AuxvTest {🤖 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-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java` around lines 19 - 27, The test AuxvTest currently calls Auxv.queryAuxv(FileUtil::readLongFromBuffer) which assumes native longs are 8 bytes; on 32-bit Linux this will misparse auxv. Update the test to either gate it to 64-bit JVMs (e.g. only run when Native long size == 8) or pass a width-aware reader to Auxv.queryAuxv that reads native-long-sized values based on Platform.nativePointerSize (or equivalent); adjust assertions using Auxv.AT_CLKTCK to use the parsed map from the corrected reader and ensure the test only asserts greaterThan(0L) when running with a 64-bit native-long reader.oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java (1)
60-65: ⚡ Quick winAdd a defensive guard for truncated auxv buffers.
queryAuxvassumesAT_NULLis always reachable. If the buffer is truncated/corrupt, Line 61 or Line 63 can throw during read and fail the call. Consider handling underflow and returning parsed entries safely.Proposed patch
+import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; @@ - int key; - do { - key = (int) reader.read(buff); - if (key != AT_NULL) { - auxvMap.put(key, reader.read(buff)); - } - } while (key != AT_NULL); + try { + int key; + do { + key = (int) reader.read(buff); + if (key != AT_NULL) { + auxvMap.put(key, reader.read(buff)); + } + } while (key != AT_NULL); + } catch (BufferUnderflowException e) { + // Return entries parsed so far if auxv is truncated/malformed. + } return auxvMap;🤖 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-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java` around lines 60 - 65, The loop in Auxv.queryAuxv assumes AT_NULL will be read and performs two unguarded reads (for key and value) which can throw or underflow on truncated/corrupt buffers; modify the do/while to check that the reader has enough remaining bytes before each reader.read(buff) (or verify reader.read returns the expected number of bytes) and break out gracefully if there isn’t enough data, ensuring auxvMap is returned with the entries parsed so far; update the block around the key read and the subsequent value read (the variables key and the auxvMap.put(...) call) to perform these bounds/return-value checks and avoid throwing on truncated buffers.
🤖 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.
Nitpick comments:
In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java`:
- Around line 60-65: The loop in Auxv.queryAuxv assumes AT_NULL will be read and
performs two unguarded reads (for key and value) which can throw or underflow on
truncated/corrupt buffers; modify the do/while to check that the reader has
enough remaining bytes before each reader.read(buff) (or verify reader.read
returns the expected number of bytes) and break out gracefully if there isn’t
enough data, ensuring auxvMap is returned with the entries parsed so far; update
the block around the key read and the subsequent value read (the variables key
and the auxvMap.put(...) call) to perform these bounds/return-value checks and
avoid throwing on truncated buffers.
In `@oshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.java`:
- Around line 19-27: The test AuxvTest currently calls
Auxv.queryAuxv(FileUtil::readLongFromBuffer) which assumes native longs are 8
bytes; on 32-bit Linux this will misparse auxv. Update the test to either gate
it to 64-bit JVMs (e.g. only run when Native long size == 8) or pass a
width-aware reader to Auxv.queryAuxv that reads native-long-sized values based
on Platform.nativePointerSize (or equivalent); adjust assertions using
Auxv.AT_CLKTCK to use the parsed map from the corrected reader and ensure the
test only asserts greaterThan(0L) when running with a 64-bit native-long reader.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 690ba4a7-cb1e-471a-8085-452adfc95236
📒 Files selected for processing (4)
oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.javaoshi-common/src/test/java/oshi/util/driver/linux/proc/AuxvTest.javaoshi-core-ffm/src/main/java/oshi/driver/linux/proc/AuxvFFM.javaoshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.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). (4)
- GitHub Check: Analyze (java)
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
🧰 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/util/driver/linux/proc/Auxv.java
🔇 Additional comments (3)
oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java (1)
16-47: LGTM!oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java (1)
29-29: LGTM!oshi-core-ffm/src/main/java/oshi/driver/linux/proc/AuxvFFM.java (1)
29-29: LGTM!
Move the auxv buffer-reading logic into a shared queryAuxv(NativeLongReader) method in oshi-common. AuxvJNA and AuxvFFM now delegate to it, each supplying their platform-specific native-long reader as a lambda/method reference.
426c370 to
ed500a6
Compare
Closes #3262
Introduces a
NativeLongReaderfunctional interface in the commonAuxvclass and moves the buffer-reading loop intoAuxv.queryAuxv(NativeLongReader). The JNA and FFM subclasses now each supply their reader as a one-liner delegation.Changes:
Auxv.java(oshi-common): AddedNativeLongReaderinterface andqueryAuxv()methodAuxvJNA.java: Reduced to single delegation callAuxvFFM.java: Reduced to single delegation callAuxvTest.javain oshi-common testing the shared implementationSummary by CodeRabbit
New Features
Refactor
Tests