Repository navigation
Fix the Linux soft open-file limit when the hard limit is unlimited - #3564
Conversation
Extracting a test seam for getProcessOpenFileLimit turned up a bug and a
duplicate, so all three land together.
LinuxOSProcess guarded the parse with a check on the whole row:
if (line.contains("unlimited")) {
return -1;
}
which discards both fields whenever either one is unlimited. A root
process after `ulimit -Hn unlimited` has a row reading
Max open files 1024 unlimited files
and getSoftOpenFileLimit() returned -1 for it rather than 1024. The
guard is also unnecessary for the case it was presumably written for: an
all-unlimited row contributes no digits, so the split is ["", ""] and
both indices already fall through to -1. Removing it fixes the mixed row
and changes nothing else.
BsdOSProcess had the same parse without that guard, so it was already
correct. The two copies are now one: ProcLimits in oshi.util.driver.unix,
alongside the other cross-UNIX command drivers, since /proc/<pid>/limits
has the same format on Linux and on the BSDs with a mounted procfs.
Neither caller's signature or visibility changed; both delegate.
The parse is split from the file read, so ProcLimitsTest can drive it
from fixture rows on any OS. Restoring the old guard fails
testHardUnlimitedKeepsSoftLimit, so it is a real regression test rather
than a restatement.
LinuxOSProcess's javadoc claimed soft=0, hard=1. Every caller passes 1
and 2, and splitting a real row on \D+ yields ["", soft, hard, ""], so
1 and 2 are right; BsdOSProcess already documented it correctly.
Also drops two vestigial NOSONAR comments on the Addrinfo
try-with-resources in MacNetworkParamsJNA and FreeBsdNetworkParamsJNA.
Commit 40e5ee0 shows they were attached to the pre-try-with-resources
form, so the suppression was for a resource leak that wrapping the
statement had already fixed; they have suppressed nothing since.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus 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. (11)
📝 WalkthroughWalkthroughThe change centralizes Linux and BSD open-file-limit parsing in ChangesOpen-file limit handling
Network resource declaration cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant OSProcess
participant ProcLimits
participant Procfs
OSProcess->>ProcLimits: queryOpenFileLimit(processId, index)
ProcLimits->>Procfs: read /proc/<pid>/limits
Procfs-->>ProcLimits: limit lines
ProcLimits-->>OSProcess: numeric limit or -1
Possibly related PRs
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 ❌ Your patch check has failed because the patch coverage (56.25%) 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 #3564 +/- ##
============================================
+ Coverage 79.36% 79.37% +0.01%
- Complexity 4038 4160 +122
============================================
Files 706 707 +1
Lines 24293 24280 -13
Branches 4065 4061 -4
============================================
- Hits 19279 19272 -7
+ Misses 2820 2811 -9
- Partials 2194 2197 +3
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.
Actionable comments posted: 1
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/linux/LinuxOSProcess.java (1)
484-492: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winCorrect the Javadoc index values.
The callers pass
1for the soft limit and2for the hard limit. Changesoft=0, hard=1tosoft=1, hard=2.Based on the PR objective, this Javadoc must describe the current shared parser contract.
🤖 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/linux/LinuxOSProcess.java` around lines 484 - 492, Update the Javadoc for LinuxOSProcess.getProcessOpenFileLimit to document the shared parser contract accurately: state that index 1 is the soft limit and index 2 is the hard limit, leaving the method implementation unchanged.
🤖 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.
Inline comments:
In `@oshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.java`:
- Around line 62-65: Update the index validation in the relevant ProcLimits
parsing helper to return -1 when index is less than 1, before accessing
split[index]. Preserve the existing out-of-range handling and add a fixture
assertion covering a negative index.
---
Outside diff comments:
In `@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.java`:
- Around line 484-492: Update the Javadoc for
LinuxOSProcess.getProcessOpenFileLimit to document the shared parser contract
accurately: state that index 1 is the soft limit and index 2 is the hard limit,
leaving the method implementation unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0b82e475-63b8-4195-ba5a-f413882a666d
📒 Files selected for processing (7)
CHANGELOG.mdoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.javaoshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.javaoshi-common/src/test/java/oshi/util/driver/unix/ProcLimitsTest.javaoshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout. (11)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, ubuntu-latest
🧰 Additional context used
📓 Path-based instructions (5)
oshi-common/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-common/src/main/java/**/*.java: Keeposhi-commonpure Java 8 with no JNA, FFM, or native library loading references; shared parsing, conversion, filtering, caching, and validation logic belongs here rather than duplicated in implementation modules.
Useoshi.util.ParseUtilmethods instead of banned numeric parsing APIs such asInteger.parseInt,Long.parseLong,Double.parseDouble, andInteger.decode.
Files:
oshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*.java: Do not useorg.slf4j.event.**; useoshi.util.LogLevelinstead.
Add the imports needed by code, and let Spotless own formatting and import ordering.
Verify native struct offsets, field widths, andsysctl/ioctlconstants against the target operating system's real headers rather than inferring them from another OS.
Files:
oshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.javaoshi-common/src/test/java/oshi/util/driver/unix/ProcLimitsTest.javaoshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
**/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/main/java/**/*.java: Every public member must have Javadoc, and code and Javadoc—including{@link...}—must use imported simple class names rather than fully qualified names.
New classes should declare an appropriate concurrency annotation fromoshi.annotation.concurrent, matching the modeled class when applicable.
Memoize constant or expensive, slowly changing system-call results withoshi.util.Memoizer, following surrounding patterns and usingdefaultExpiration()when values must refresh.
Place reusable per-OS acquisition and parsing helpers inoshi/driver/<os>/; keep parsing logic out of HAL classes where practical.
Prefer native calls for system information; on Linux preferFileUtilfor/procand/sys, while on other platformsExecutingCommandis acceptable when native APIs do not expose the information.
Do not commit generated output,target/, or IDE files.
Files:
oshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.javaoshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
**/src/test/java/**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
**/src/test/java/**/*Test.java: Use JUnit 5 and Hamcrest; do not add Mockito. Extract parsing into methods accepting fixture data such asList<String>orString, and test those methods separately from acquisition.
Assert hardware-independent invariants such as non-null values, types, ordering, and plausible ranges rather than specific hardware values; allow zero and empty results.
Avoid timing-sensitive assertions comparing live readings, including CPU frequency, tick counters, and uptime.
Do not assume platform-specific hardware exists; tests must tolerate absent batteries, sensors, GPUs, sound cards, and processors.
Files:
oshi-common/src/test/java/oshi/util/driver/unix/ProcLimitsTest.java
oshi-core/src/main/java/**/*.java
📄 CodeRabbit inference engine (AGENTS.md)
oshi-core/src/main/java/**/*.java:oshi-coremust compile with Java 8; do not use modern features such asvar, records, switch expressions, text blocks,List.of, orStream.toList().
Behavior changes in JNA implementation classes should also be applied equivalently to their corresponding FFM twins, unless the difference is intentionally specific to JNA or FFM.
Files:
oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.java
🧠 Learnings (4)
📚 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/unix/ProcLimits.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.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/util/driver/unix/ProcLimits.javaoshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.
Applied to files:
oshi-common/src/main/java/oshi/util/driver/unix/ProcLimits.javaoshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.java
🔇 Additional comments (4)
oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java (1)
56-56: LGTM!oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsJNA.java (1)
46-46: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java (1)
23-23: LGTM!Also applies to: 339-339
CHANGELOG.md (1)
5-5: LGTM!
CodeRabbit review. All three findings verified and valid. parseOpenFileLimit guarded only the upper bound, so a negative index passed split.length <= index and then indexed the array out of bounds. That was unreachable while the method was protected and both call sites passed 1 or 2, but it is public API on a utility class now, so the guard belongs here rather than in the callers. Element 0 is the empty string left of the "Max open files" label, so 1 is the lowest usable index. testIndexBelowTheFirstField covers index 0 and -1; removing the guard fails it with ArrayIndexOutOfBoundsException, so it is a real check. LinuxOSProcess.getProcessOpenFileLimit still carried the wrong javadoc, soft=0 and hard=1, that this branch corrected on the shared parser. Both now say 1 for soft and 2 for hard. The CHANGELOG entry moves to the end of the list so the entries stay in PR order.
Extracting a test seam for
getProcessOpenFileLimitturned up a bug and a duplicate, so the fix, the dedup and the tests land together.The bug
LinuxOSProcessguarded the parse with a check on the whole row:That discards both fields whenever either is unlimited. A root process after
ulimit -Hn unlimitedhas:and
getSoftOpenFileLimit()returned -1 rather than 1024./proc/<pid>/limitsrow1024 40961024 unlimitedunlimited unlimitedThe guard is also unnecessary for the case it was presumably written for: an all-unlimited row contributes no digits, so
split("\\D+")gives["", ""]and both indices already fall through to -1. Removing it fixes the middle row and changes nothing else.The duplicate
BsdOSProcesshad the same parse without that guard, so it was already correct. The two copies are now one —ProcLimitsinoshi.util.driver.unix, alongside the other cross-UNIX command drivers, since/proc/<pid>/limitshas the same format on Linux and on the BSDs with a mounted procfs. Neither caller changed signature or visibility; both delegate.The seam
The parse is split from the file read, so
ProcLimitsTestdrives it from fixture rows on any OS — no Linux needed. Verified non-vacuous: restoring the old guard failstestHardUnlimitedKeepsSoftLimit, so it is a real regression test rather than a restatement of current behaviour.Incidental
LinuxOSProcessjavadoc claimedsoft=0, hard=1. Every caller passes 1 and 2, and splitting a real row yields["", soft, hard, ""], so 1 and 2 are right —BsdOSProcessalready documented it correctly.Two vestigial
NOSONARcomments removed from theAddrinfotry-with-resources inMacNetworkParamsJNAandFreeBsdNetworkParamsJNA. Commit40e5ee069eshows they were attached to the pre-try-with-resources form, so they suppressed a resource leak that wrapping the statement had already fixed, and have suppressed nothing since.Verification
Full gate green from clean: install, spotless, checkstyle, forbiddenapis, javadoc, and 1509 tests successful / 0 failed.
Summary by CodeRabbit
Bug Fixes
Tests
Chores