Skip to content

Deduplicate InstalledApps registry-value parsing into a shared helper - #3481

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:installed-apps-registry-dedup
Jul 18, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:installed-apps-registry-dedup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Last consistency item from the JNA↔FFM audit before 7.4.1.

The JNA (RegistryUtil) and FFM (InstalledAppsDataFFM) backends each carried their own registryValueToString/registryValueToLong, and the string versions had drifted apart:

  • JNA handled String (REG_SZ) and byte[] (REG_BINARY), but not Integer (REG_DWORD).
  • FFM handled String and Integer, but not byte[].

Because InstalledApps drops any entry whose DisplayName resolves to null, an app whose DisplayName happened 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 — DisplayName is almost always REG_SZ — but the two backends should not be able to disagree.

Change

  • Add oshi.driver.common.windows.registry.RegistryValueUtil in oshi-common, with registryValueToString (String → trim, Integer → decimal, byte[] → ParseUtil.decodeBinaryToString) and registryValueToLong (the shared timestamp/date heuristic, which was already identical in both backends).
  • RegistryUtil (JNA) and InstalledAppsDataFFM (FFM) now both delegate to it; their private copies and the duplicated THIRTY_YEARS_IN_SECS constant are removed.
  • The conversion tests move to oshi-common as 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 InstalledApps results no longer depend on which backend is active.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows installed-application detection when registry values use REG_DWORD or REG_BINARY.
    • Ensured consistent application resolution across supported Windows backends.
    • Enhanced decoding of registry dates, text values, and encoded binary data.
  • Tests
    • Added unit test coverage for registry value conversions (including trimming, unsigned numbers, and date parsing).

…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.
@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 70801a07-5250-4005-97f7-07d3a45ffada

📥 Commits

Reviewing files that changed from the base of the PR and between 64dc2c9 and f3bba71.

📒 Files selected for processing (2)
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.java
  • oshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.java
  • oshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • 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: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

Introduces 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.

Changes

Windows Registry conversion

Layer / File(s) Summary
Registry conversion contracts
oshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.java
Adds shared string and long conversion methods for trimmed strings, unsigned integers, binary values, timestamps, and date strings.
Registry consumer integration
oshi-core/src/main/java/oshi/util/platform/windows/RegistryUtil.java, oshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.java, CHANGELOG.md
Routes registry lookups and FFM installed-application fields through the shared parser and removes duplicate conversion helpers.
Conversion test coverage
oshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.java, oshi-common/src/test/java/module-info.test
Tests numeric, date, string, and binary conversions and opens the package for test access.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit found values tucked under the keys,
Now JNA and FFM parse them with ease.
Strings, bytes, and dates hop into one line,
Shared by the registry, working just fine.
“No duplicate burrows!” the bunny cheers bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: deduplicating InstalledApps registry-value parsing into a shared helper.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.11%. Comparing base (1e49a16) to head (f3bba71).

Files with missing lines Patch % Lines
...ver/common/windows/registry/RegistryValueUtil.java 91.30% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
freebsd 27.80% <67.74%> (+0.12%) ⬆️
linux 32.34% <67.74%> (+1.07%) ⬆️
macos 32.87% <67.74%> (+0.07%) ⬆️
openbsd 27.10% <67.74%> (+0.13%) ⬆️
solaris 29.59% <67.74%> (+0.12%) ⬆️
windows 40.91% <93.54%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.java (2)

35-39: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Treat REG_DWORD values as unsigned.

Windows Registry REG_DWORD values are inherently unsigned 32-bit integers, but JNA and FFM mappings return them as signed Java Integer objects. Using Integer.toUnsignedString prevents 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 win

Evaluate REG_DWORD timestamps as unsigned values.

Similarly, treating REG_DWORD values as unsigned longs prevents large values (such as timestamps after 2038) from evaluating to negative numbers. A negative number would incorrectly fail the value > minSaneTimestamp check 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e49a16 and 64dc2c9.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/RegistryValueUtil.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/driver/common/windows/registry/RegistryValueUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.java
  • oshi-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.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.java
  • oshi-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).
@dbwiddis
dbwiddis merged commit 8604353 into oshi:master Jul 18, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the installed-apps-registry-dedup branch July 18, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant