Repository navigation
Replace org.slf4j.event.Level with an OSHI-owned LogLevel enum - #3525
Conversation
ExceptionUtil and its callers across oshi-common, oshi-core, and oshi-core-ffm carried the log level as org.slf4j.event.Level, a type that only exists from slf4j-api 1.7.15 and was referenced on non-exceptional code paths (e.g. the getOrDefault convenience overloads delegate with an explicit Level.DEBUG, and call sites pass Level.WARN as a plain argument). Embedders relying on a host-provided slf4j older than 1.7.15 -- such as a Java agent loaded as an Apache Maven 3.3.x core extension, which resolves slf4j from Maven's bundled 1.7.5 -- therefore hit NoClassDefFoundError: org/slf4j/event/Level on ordinary calls, not just when an exception was actually logged (oshi#3524). logAtLevel dispatches only to the classic Logger#debug/info/warn/error/trace methods (present since slf4j 1.0), so carrying the level with an OSHI enum removes the 1.7.15 floor without changing any logging behavior. The now-unused org.slf4j.event OSGi import is dropped as well. Split the SLF4J 1.7 compatibility check into two profiles, since no single 1.7.x version exercises both constraints: verify-slf4j-17 pins 1.7.5 (the API floor) and skips module-info, because Automatic-Module-Name: org.slf4j only arrived in 1.7.27; verify-slf4j-17-jpms pins 1.7.27 and compiles module-info to keep verifying that `requires org.slf4j` resolves on the module path. Both run in CI.
|
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 (2)
💤 Files with no reviewable changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (11)
🔇 Additional comments (1)
📝 WalkthroughWalkthroughOSHI introduces ChangesLogLevel migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 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 |
There was a problem hiding this comment.
Pull request overview
This PR removes OSHI’s runtime dependency on org.slf4j.event.Level by introducing an OSHI-owned oshi.util.LogLevel enum and updating ExceptionUtil (and related helpers/callers across oshi-common, oshi-core, and oshi-core-ffm) to carry logging levels without class-loading SLF4J types that are absent in older 1.7.x releases (fixing #3524).
Changes:
- Add
oshi.util.LogLeveland replaceorg.slf4j.event.Levelusages across the codebase. - Update
ExceptionUtil/FFM/JNA sysctl helpers and platform utilities to acceptLogLevel. - Adjust Maven/CI verification to test both the SLF4J 1.7.5 API floor and JPMS resolution against SLF4J 1.7.27, and drop the now-unused OSGi import for
org.slf4j.event.
Reviewed changes
Copilot reviewed 62 out of 62 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Drops OSGi import of org.slf4j.event and splits SLF4J 1.7 compatibility checks into API-floor vs JPMS profiles. |
| .github/workflows/pr.yaml | Runs the new SLF4J 1.7 JPMS compatibility build in CI. |
| CHANGELOG.md | Documents the behavioral/compatibility fix for #3524. |
| oshi-common/src/main/java/oshi/util/LogLevel.java | Introduces an OSHI-owned log level enum to avoid SLF4J event.Level linkage. |
| oshi-common/src/main/java/oshi/util/ExceptionUtil.java | Switches exception-level dispatch from SLF4J Level to OSHI LogLevel. |
| oshi-common/src/test/java/oshi/util/ExceptionUtilTest.java | Updates tests to use LogLevel and validates behavior across all levels. |
| oshi-core/src/main/java/oshi/util/platform/windows/PerfDataUtil.java | Replaces SLF4J Level with LogLevel for Windows PDH error logging decisions. |
| oshi-core/src/test/java/oshi/util/platform/windows/PerfDataUtilTest.java | Updates tests to iterate over LogLevel values. |
| oshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.java | Passes OSHI LogLevel into shared sysctl helper calls. |
| oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java | Passes OSHI LogLevel into shared sysctl helper calls. |
| oshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.java | Passes OSHI LogLevel into shared sysctl helper calls. |
| oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java | Passes OSHI LogLevel into shared sysctl helper calls. |
| oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java | Changes sysctl helper signatures from SLF4J Level to OSHI LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java | Switches arena-call helpers to carry LogLevel and reuse ExceptionUtil.logAtLevel. |
| oshi-core-ffm/src/test/java/oshi/ffm/ForeignFunctionsTest.java | Updates tests to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdNetworkParamsFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsFFM.java | Updates static imports and ExceptionUtil usage to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOSProcessFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxFileSystemFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsVirtualMemoryFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGlobalMemoryFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdSensorsFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdCentralProcessorFFM.java | Updates FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacVirtualMemoryFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacGlobalMemoryFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java | Updates static imports and ExceptionUtil usage to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java | Updates static imports and FFM call wrappers to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java | Updates sysctl FFM helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.java | Updates Windows perf FFM helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/IPHlpAPIUtilFFM.java | Updates Windows IP helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java | Updates Windows advapi helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.java | Updates macOS sysctl FFM helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/IOKitUtilFFM.java | Updates macOS IOKit helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java | Updates registry helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/mac/IOReportClientFFM.java | Updates macOS IOReport helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatProtocolFFM.java | Updates AIX perfstat helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatProcessFFM.java | Updates AIX perfstat helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatNetInterfaceFFM.java | Updates AIX perfstat helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatMemoryFFM.java | Updates AIX perfstat helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatDiskFFM.java | Updates AIX perfstat helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatCpuFFM.java | Updates AIX perfstat helper to use LogLevel. |
| oshi-core-ffm/src/main/java/oshi/driver/unix/aix/perfstat/PerfstatConfigFFM.java | Updates AIX perfstat helper to use LogLevel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3525 +/- ##
============================================
- Coverage 78.45% 78.43% -0.03%
- Complexity 76 195 +119
============================================
Files 696 697 +1
Lines 24100 24106 +6
Branches 3993 3993
============================================
- Hits 18908 18907 -1
- Misses 2992 2997 +5
- Partials 2200 2202 +2
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:
|
LogLevel also drives direct, non-ExceptionUtil logging (SysctlUtilJNA, PerfDataUtil, ForeignFunctions), so describe it as a general severity level rather than specifically ExceptionUtil's swallowed-exception level.
The verify-slf4j-17 profile did a full `clean compile` against slf4j 1.7.5, which failed on oshi-core-ffm: unlike oshi-common/oshi-core (main at release 8, module-info isolated in a separate release-9 execution that the profile can skip), oshi-core-ffm compiles module-info.java in its release-25 default-compile, where maven-compiler-plugin force-compiles it regardless of excludes. Its `requires org.slf4j` then cannot resolve, because slf4j gained Automatic-Module-Name only in 1.7.27. Scope the 1.7.5 API-floor check to oshi-common and oshi-core, the classpath modules whose module-info can be skipped and which carry the affected code. Guard the actual oshi#3524 regression -- any reference to org.slf4j.event.Level -- across every module, including oshi-core-ffm, with forbiddenapis, which checks by name independent of the compiled slf4j version. The verify-slf4j-17-jpms profile still compiles the full reactor (including oshi-core-ffm's module-info) against 1.7.27, covering JPMS resolution and SLF4J-2.0-only Logger methods there.
dbwiddis
left a comment
There was a problem hiding this comment.
Overall LGTM.
I don't think we need the pom.xml changes (and corresponding added PR test).
The additional profile and dancing around JPMS complexity adds very little value, given the forbiddenapis check.
The chances of us using any other logging features that this guards against are near-zero.
| * OSHI loggable against host-provided slf4j-api versions older than 1.7.15 (e.g. the 1.7.5 bundled by Apache Maven | ||
| * 3.3.x, which loads OSHI-based extensions against its own slf4j). | ||
| */ | ||
| @ThreadSafe |
There was a problem hiding this comment.
I don't think we annotate any of our enums in the codebase. If we did, Immutable would probably be a better choice here, but I think this annotation is unnecessary.
The forbiddenapis ban on org.slf4j.event.Level already guards the oshi#3524 regression in every module, including oshi-core-ffm, so pinning the build to 1.7.5, the separate JPMS profile, and the added CI step add little value. Restore verify-slf4j-17 to its prior form (1.7.36, guarding SLF4J-2.0-only Logger methods). The dropped org.slf4j.event OSGi import stays dropped.
OSHI does not annotate its enums, and the enum is trivially thread-safe.
Removed. Thank you for the quick review! |
PerfDataUtil.handleError and ExceptionUtil.logAtLevel each carried their own five-way LogLevel switch. Hoist the dispatch into oshi.util.LogUtil and have both delegate. ExceptionUtil.logAtLevel keeps its signature, so oshi-core-ffm and any downstream caller are unaffected. LogUtil.isEnabled restores the capability of Logger#isEnabledForLevel that #3432 had to drop for slf4j 1.x compatibility. That lets handleError keep skipping FormatUtil.formatError when the level is off, without reintroducing an inline switch to do it. handleError also double-formatted an already-formatted string: FormatUtil.formatError returns the output of String.format, and the result was passed through String.format again with no arguments. PerfCounterQueryHandler had the same copy-paste, fixed there as well; its isWarnEnabled guards are left alone, since both log at a level known at the call site and can check it directly. Widen the forbidden-apis ban from org.slf4j.event.Level to the whole org.slf4j.event package. slf4j-api 1.7.5 has no such package at all, so every type in it breaks the same hosts that motivated #3524 and #3525. The level switch now lives in oshi-common, where a cross-platform test covers all ten branches. Previously the only fully covered copy was in PerfDataUtil, reachable only on Windows CI.
ExceptionUtil and its callers across oshi-common, oshi-core, and oshi-core-ffm carried the log level as org.slf4j.event.Level, a type that only exists from slf4j-api 1.7.15 and was referenced on non-exceptional code paths (e.g. the getOrDefault convenience overloads delegate with an explicit Level.DEBUG, and call sites pass Level.WARN as a plain argument). Embedders relying on a host-provided slf4j older than 1.7.15 -- such as a Java agent loaded as an Apache Maven 3.3.x core extension, which resolves slf4j from Maven's bundled 1.7.5 -- therefore hit NoClassDefFoundError: org/slf4j/event/Level on ordinary calls, not just when an exception was actually logged (#3524).
logAtLevel dispatches only to the classic Logger#debug/info/warn/error/trace methods (present since slf4j 1.0), so carrying the level with an OSHI enum removes the 1.7.15 floor without changing any logging behavior. The now-unused org.slf4j.event OSGi import is dropped as well.
Split the SLF4J 1.7 compatibility check into two profiles, since no single 1.7.x version exercises both constraints: verify-slf4j-17 pins 1.7.5 (the API floor) and skips module-info, because Automatic-Module-Name: org.slf4j only arrived in 1.7.27; verify-slf4j-17-jpms pins 1.7.27 and compiles module-info to keep verifying that
requires org.slf4jresolves on the module path. Both run in CI.Summary by CodeRabbit
New Features
Bug Fixes