Repository navigation
Solaris: extract testable parse methods from command readers - #3497
Conversation
Extract inline command-output parsing into package-private static methods that accept List<String> (or String), mirroring the pattern from #3494 (Linux), #3495 (FreeBSD), and #3496 (NetBSD/OpenBSD). This allows fixture-based tests to exercise the parse logic on every CI platform without requiring Solaris/OpenIndiana. Extractions: - SolarisCentralProcessor: parseDmesgCpuInfo (dmesg), parseNumaNodes (lgrpinfo -c leaves), parseIsainfoFlags (isainfo -v), sumKstatLong (kstat -p cpu_stat) - SolarisComputerSystem: parseSmbios (smbios), parseSerialFromPrtconf (prtconf -pv chassis-sn) - SolarisGraphicsCard: parsePrtconf (prtconf -pv display class) - SolarisSoundCard: parseLshal (lshal audio810 driver) - SolarisVirtualMemory: parseSwapInfo (swap -lk), sumKstatLong (kstat -p cpu_stat:::pgswapin/pgswapout) - SolarisInternetProtocolStats: parseTcpStats and parseUdpStats (netstat -s -P tcp/udp/ip), splitOnPrefix made package-private
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (14)
📝 WalkthroughWalkthroughSolaris hardware, virtual-memory, and network collectors now separate native command execution from output parsing through reusable helpers. New Solaris-focused tests cover processor, SMBIOS, device, memory, and protocol parsing, including empty and boundary inputs. ChangesSolaris parser refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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
Additional details and impacted files@@ Coverage Diff @@
## master #3497 +/- ##
============================================
+ Coverage 75.92% 75.95% +0.02%
Complexity 76 76
============================================
Files 591 591
Lines 21675 21676 +1
Branches 3614 3612 -2
============================================
+ Hits 16456 16463 +7
- Misses 3260 3262 +2
+ Partials 1959 1951 -8
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:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java (1)
68-69: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winFix multi-stat parsing when the second stat lacks the prefix.
stat.split("=")splits the line into as many parts as there are=signs. If a line contains two stats with different prefixes (e.g.,"tcpInErrs = 3 udpNoPorts = 0"),splitOnPrefixcorrectly leaves the string intact because it doesn't find a second matching prefix. However, splitting this combined string by=produces an array of length 3. Theif (split.length == 2)condition will then evaluate to false, causing the entire line to be skipped. As noted by the inline comment, this scenario is expected, but the strict length check preventsParseUtil.getFirstIntValuefrom ever being reached.
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java#L68-L69: InparseTcpStats, usestat.split("=", 2)to split only on the first=sign, guaranteeing a length of 2 and allowing the value to be parsed correctly.oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java#L130-L131: Apply the samestat.split("=", 2)fix inparseUdpStatsto protect against trailing non-UDP stats.🐛 Proposed fix
For TCP stats (
parseTcpStats):- String[] split = stat.split("="); - if (split.length == 2) { + String[] split = stat.split("=", 2); + if (split.length == 2) {For UDP stats (
parseUdpStats):- String[] split = stat.split("="); - if (split.length == 2) { + String[] split = stat.split("=", 2); + if (split.length == 2) {🤖 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/software/common/os/unix/solaris/SolarisInternetProtocolStats.java` around lines 68 - 69, Update stat splitting in both parseTcpStats (SolarisInternetProtocolStats.java lines 68-69) and parseUdpStats (SolarisInternetProtocolStats.java lines 130-131) to split on only the first equals sign, preserving the existing length check and allowing values to be parsed when trailing stats use different prefixes.
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java (1)
24-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse realistic test data to cover mixed-prefix edge cases.
The test currently bypasses a real-world parsing bug because
tcpInErrshares a line withtcpOutRsts, allowingsplitOnPrefixto separate them cleanly. In real Solarisnetstat -s -P ipoutput,tcpInErrstypically shares a line withudpNoPorts(which doesn't start withtcp).Once you apply the
stat.split("=", 2)fix to the parser, I recommend updating this mock data to properly test the parser's resilience against lines containing mixed prefixes.💡 Proposed refactor
List<String> netstat = Arrays.asList(// "tcpCurrEstab = 42 tcpActiveOpens = 1000", // "tcpPassiveOpens = 500 tcpAttemptFails = 10", // "tcpEstabResets = 5 tcpOutSegs = 50000", // "tcpInSegs = 60000 tcpRetransSegs = 200", // - "tcpInErr = 3 tcpOutRsts = 15"); + "tcpInErr = 3 udpNoPorts = 15", // + "tcpOutRsts = 15");🤖 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/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java` around lines 24 - 30, Update the mock netstat data in SolarisInternetProtocolStatsTest to reflect realistic mixed-prefix output: use the correctly named tcpInErrs statistic on a line with udpNoPorts rather than pairing tcpInErr with tcpOutRsts, while preserving coverage of the stat.split("=", 2) parsing behavior.
🤖 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.
Outside diff comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java`:
- Around line 68-69: Update stat splitting in both parseTcpStats
(SolarisInternetProtocolStats.java lines 68-69) and parseUdpStats
(SolarisInternetProtocolStats.java lines 130-131) to split on only the first
equals sign, preserving the existing length check and allowing values to be
parsed when trailing stats use different prefixes.
---
Nitpick comments:
In
`@oshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java`:
- Around line 24-30: Update the mock netstat data in
SolarisInternetProtocolStatsTest to reflect realistic mixed-prefix output: use
the correctly named tcpInErrs statistic on a line with udpNoPorts rather than
pairing tcpInErr with tcpOutRsts, while preserving coverage of the
stat.split("=", 2) parsing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 070d1b81-6702-4f39-b986-0d99a83e8c24
📒 Files selected for processing (13)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.javaoshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystemTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCardTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemoryTest.javaoshi-common/src/test/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStatsTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (13)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 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/unix/solaris/SolarisVirtualMemory.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.javaoshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.javaoshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisInternetProtocolStats.java
📚 Learning: 2026-04-12T19:34:56.879Z
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:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java
🔇 Additional comments (11)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemory.java (1)
10-10: LGTM!Also applies to: 79-85, 86-113
oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisVirtualMemoryTest.java (1)
1-51: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessor.java (1)
37-37: LGTM!Also applies to: 61-68, 83-97, 105-132, 152-181
oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisCentralProcessorTest.java (1)
1-100: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystem.java (1)
15-15: LGTM!Also applies to: 83-115, 152-201
oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisComputerSystemTest.java (1)
1-100: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCard.java (1)
44-53: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisGraphicsCardTest.java (1)
1-79: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCard.java (1)
46-60: LGTM!oshi-common/src/test/java/module-info.test (1)
89-92: LGTM!oshi-common/src/test/java/oshi/hardware/common/platform/unix/solaris/SolarisSoundCardTest.java (1)
1-78: LGTM!
When tcpInErr is paired with a non-tcp stat on the same line (e.g. udpNoPorts), splitOnPrefix finds only one "tcp" occurrence, leaving the full remainder including a second "=" sign. Limiting split to 2 parts ensures the length check passes and getFirstIntValue extracts the correct value from the leading portion.
…#3498) * Solaris: extract prtpicl, prtconf USB, svcs, and plimit/pbind parsers Extract remaining Solaris-specific command parsers into testable static methods, continuing the coverage work from #3497. Extractions: - SolarisSensors: parseCpuTemperature, parseFanSpeeds, parseVoltage (prtpicl -v -c temperature-sensor/fan/voltage-sensor) - SolarisUsbDevice: parsePrtconf (prtconf -pv USB device tree) - SolarisOperatingSystem: parseSvcs (svcs -p service enumeration) - SolarisOSProcess: parseOpenFileLimit (plimit), parsePbindOutput (pbind -q), parsePsrinfo (psrinfo processor enumeration) * Remove stale comment and use stream conversion in parseFanSpeeds
Summary
List<String>(orString), mirroring the pattern from Extract testable parse methods from Linux /proc and command readers #3494 (Linux), FreeBSD: quiet dmesg.boot read and extract testable command parsers #3495 (FreeBSD), and NetBSD/OpenBSD: extract testable parse methods from command readers #3496 (NetBSD/OpenBSD)Test plan
./mvnw clean install— 1170 tests, 0 failures)@EnabledOnOsgating on parse tests — they run on every platformSummary by CodeRabbit