Repository navigation
Deduplicate InstalledApps registry-value parsing into a shared helper - #3481
Conversation
…kends can't diverge Both backends had their own registryValueToString/registryValueToLong. The registryValueToString copies had diverged: the JNA copy handled String and REG_BINARY (byte[]) but not REG_DWORD (Integer), while the FFM copy handled String and Integer but not byte[]. Extract one RegistryValueUtil into oshi-common handling all three types (String, Integer, byte[]) and have both backends call it. Move the conversion tests to oshi-common alongside it.
|
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. (15)
📝 WalkthroughWalkthroughIntroduces a shared Windows Registry value parser, routes JNA and FFM installed-application handling through it, removes duplicate conversion logic, and adds focused tests and changelog coverage. ChangesWindows Registry conversion
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 #3481 +/- ##
============================================
+ Coverage 74.56% 75.11% +0.55%
+ Complexity 2624 76 -2548
============================================
Files 589 590 +1
Lines 21553 21535 -18
Branches 3615 3610 -5
============================================
+ Hits 16070 16176 +106
+ Misses 3524 3390 -134
- Partials 1959 1969 +10
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.
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.java (2)
35-39: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTreat
REG_DWORDvalues as unsigned.Windows Registry
REG_DWORDvalues are inherently unsigned 32-bit integers, but JNA and FFM mappings return them as signed JavaIntegerobjects. UsingInteger.toUnsignedStringprevents unexpectedly formatting large DWORDs (those where the highest bit is set) as negative strings.♻️ Proposed refactor
// REG_DWORD if (val instanceof Integer) { - return Integer.toString((Integer) val); + return Integer.toUnsignedString((Integer) val); } // REG_BINARY🤖 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/driver/common/windows/registry/RegistryValueUtil.java` around lines 35 - 39, Update the REG_DWORD handling in RegistryValueUtil to format Integer values with unsigned 32-bit semantics, using the standard unsigned conversion so values with the high bit set are never returned as negative strings.
61-67: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winEvaluate
REG_DWORDtimestamps as unsigned values.Similarly, treating
REG_DWORDvalues as unsigned longs prevents large values (such as timestamps after 2038) from evaluating to negative numbers. A negative number would incorrectly fail thevalue > minSaneTimestampcheck and return the raw negative value instead of the expected milliseconds.♻️ Proposed refactor
if (val instanceof Integer) { - int value = (Integer) val; + long value = Integer.toUnsignedLong((Integer) val); if (value > minSaneTimestamp && value < currentTimeSecs) { return value * 1000L; } return value; - } else if (val instanceof String) { + } else if (val instanceof String) {🤖 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/driver/common/windows/registry/RegistryValueUtil.java` around lines 61 - 67, Update the Integer branch of the timestamp conversion logic in RegistryValueUtil to interpret REG_DWORD values as unsigned 32-bit values before comparing against minSaneTimestamp and currentTimeSecs. Preserve the existing sane-range conversion to milliseconds and raw-value fallback, while ensuring post-2038 timestamps are not rejected due to signed overflow.
🤖 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/driver/common/windows/registry/RegistryValueUtil.java`:
- Around line 35-39: Update the REG_DWORD handling in RegistryValueUtil to
format Integer values with unsigned 32-bit semantics, using the standard
unsigned conversion so values with the high bit set are never returned as
negative strings.
- Around line 61-67: Update the Integer branch of the timestamp conversion logic
in RegistryValueUtil to interpret REG_DWORD values as unsigned 32-bit values
before comparing against minSaneTimestamp and currentTimeSecs. Preserve the
existing sane-range conversion to milliseconds and raw-value fallback, while
ensuring post-2038 timestamps are not rejected due to signed overflow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fb345500-9c28-4a1e-931c-532316259154
📒 Files selected for processing (6)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/RegistryUtil.java
📜 Review details
⏰ Context from checks skipped due to timeout. (11)
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (2)
📚 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/driver/common/windows/registry/RegistryValueUtil.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/driver/common/windows/registry/RegistryValueUtil.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.javaoshi-core/src/main/java/oshi/util/platform/windows/RegistryUtil.java
🪛 ast-grep (0.44.1)
oshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.java
[warning] 66-66: Use a randomly-generated IV
Context: byte[] cp1252 = new byte[] { 't', 'e', 's', 't', 0x00 };
Note: [CWE-329] Generation of Predictable IV with CBC Mode.
(random-iv)
[warning] 73-73: Use a randomly-generated IV
Context: byte[] utf16 = new byte[] { 't', 0, 'e', 0, 's', 0, 't', 0, 0, 0 };
Note: [CWE-329] Generation of Predictable IV with CBC Mode.
(random-iv)
🔇 Additional comments (5)
oshi-core/src/main/java/oshi/util/platform/windows/RegistryUtil.java (1)
46-46: LGTM!Also applies to: 78-78, 88-88
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.java (1)
69-82: LGTM!Also applies to: 107-107
CHANGELOG.md (1)
14-14: LGTM!oshi-common/src/test/java/module-info.test (1)
51-52: LGTM!oshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.java (1)
18-47: LGTM!Also applies to: 48-75
Render Integer (REG_DWORD) values with Integer.toUnsignedString and compare timestamps using Integer.toUnsignedLong, so DWORDs with the high bit set are not returned as negative strings or rejected as pre-epoch (a pre-existing issue that would affect Unix-timestamp DWORDs after 2038).
Last consistency item from the JNA↔FFM audit before 7.4.1.
The JNA (
RegistryUtil) and FFM (InstalledAppsDataFFM) backends each carried their ownregistryValueToString/registryValueToLong, and the string versions had drifted apart:String(REG_SZ) andbyte[](REG_BINARY), but notInteger(REG_DWORD).StringandInteger, but notbyte[].Because
InstalledAppsdrops any entry whoseDisplayNameresolves tonull, an app whoseDisplayNamehappened to be stored as REG_DWORD would appear under FFM but not JNA (and a REG_BINARY name vice-versa). It's a rare case in practice —DisplayNameis almost always REG_SZ — but the two backends should not be able to disagree.Change
oshi.driver.common.windows.registry.RegistryValueUtilin oshi-common, withregistryValueToString(String → trim, Integer → decimal,byte[]→ParseUtil.decodeBinaryToString) andregistryValueToLong(the shared timestamp/date heuristic, which was already identical in both backends).RegistryUtil(JNA) andInstalledAppsDataFFM(FFM) now both delegate to it; their private copies and the duplicatedTHIRTY_YEARS_IN_SECSconstant are removed.RegistryValueUtilTest(now also covering the Integer→String case), and the date-string test is made timezone-independent so the suite runs cross-platform.Net effect: both backends resolve all three registry value types identically, so
InstalledAppsresults no longer depend on which backend is active.Summary by CodeRabbit
REG_DWORDorREG_BINARY.