Skip to content

Handle binary registry values in WindowsGraphicsCard - #3064

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:reg-qword
Jan 26, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:reg-qword

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jan 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #3063

Summary by CodeRabbit

Bug Fixes

  • Fixed Windows graphics card memory detection for binary registry values.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 26, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updates CHANGELOG.md with a bug fix entry for PR #3064 addressing Windows registry value type handling in graphics card VRAM detection. Refactors WindowsGraphicsCard.java to defensively check registry keys and their types before retrieval, falling back gracefully when keys are absent or incompatible.

Changes

Cohort / File(s) Summary
Changelog Update
CHANGELOG.md
Replaces placeholder with specific bug fix entry describing PR #3064: "Handle binary registry values in WindowsGraphicsCard" for version 6.9.3
Graphics Card VRAM Detection
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
Refactors memory key retrieval logic to check QW_MEMORY_SIZE first, then fall back to MEMORY_SIZE, with null guard before registry access. Handles Long, Integer, and byte[] types; improves robustness for systems with mismatched registry value types

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A registry quest, once rigid and tight,
Now bends to the data in binary light,
QW first, then SIZE—a fallback so wise,
No crashes when types wear a surprise! 📖✨

🚥 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 accurately describes the main change: handling binary registry values in WindowsGraphicsCard to fix the REG_BINARY type issue.
Linked Issues check ✅ Passed The PR implementation addresses issue #3063 by making QW_MEMORY_SIZE registry reading more defensive, checking for QW_MEMORY_SIZE first then MEMORY_SIZE, and handling binary registry types without throwing exceptions.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the WindowsGraphicsCard registry reading issue; CHANGELOG update documents the fix and code change implements defensive registry value handling as required.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (1)

84-88: Consider extracting the nested ternary to improve readability.

The nested ternary works correctly but is harder to parse at a glance. A helper method or simple if-else chain would be clearer.

♻️ Optional: Extract to helper method
+    private static String getMemoryKey(String fullKey) {
+        if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, QW_MEMORY_SIZE)) {
+            return QW_MEMORY_SIZE;
+        } else if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, MEMORY_SIZE)) {
+            return MEMORY_SIZE;
+        }
+        return null;
+    }

Then in getGraphicsCards():

-                String memKey = Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, QW_MEMORY_SIZE)
-                        ? QW_MEMORY_SIZE
-                        : (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, fullKey, MEMORY_SIZE)
-                                ? MEMORY_SIZE
-                                : null);
+                String memKey = getMemoryKey(fullKey);
📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9b5e1 and b51a112.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
CHANGELOG.md

3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 11, macos-latest
🔇 Additional comments (3)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCard.java (2)

2-2: LGTM!

Copyright year update is appropriate.


89-99: LGTM! Solid defensive handling of registry value types.

The implementation correctly:

  • Guards against missing keys with null check
  • Uses generic registryGetValue to avoid type-specific exceptions
  • Handles REG_QWORD (Long), REG_DWORD (Integer), and REG_BINARY (byte[]) appropriately
  • Defaults to 0L for unrecognized types, which is safe fallback behavior

This directly addresses the issue where REG_BINARY values caused RuntimeException.

CHANGELOG.md (1)

3-4: LGTM! Changelog entry is accurate and well-formatted.

The changelog entry correctly documents the fix for handling binary registry values in WindowsGraphicsCard, which addresses the RuntimeException reported in issue #3063. The format is consistent with other entries in the changelog.

Note: The markdownlint warning about heading level increments is a false positive—the h5 heading format for "Bug fixes / Improvements" is the established convention used throughout this project's changelog.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

@dbwiddis
dbwiddis merged commit d875aee into oshi:master Jan 26, 2026
26 of 30 checks passed
dbwiddis added a commit to dyorgio/oshi that referenced this pull request Jan 27, 2026
@dbwiddis
dbwiddis deleted the reg-qword branch April 3, 2026 05:03
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.

"Unexpected registry type 3, expected REG_QWORD" when getting graphics cards on Windows

1 participant