Skip to content

Improve null checking in MacInstalledApps - #3069

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix-null
Jan 27, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix-null

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jan 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #3068

Summary by CodeRabbit

  • Bug Fixes
    • Improved stability when parsing application data on macOS by preventing null reference errors that could occur during app discovery.

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

@coderabbitai

coderabbitai Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A null-safety fix in the MacInstalledApps parser that guards against null returns from parseStringArray when processing array values. Instead of allowing null propagation, the code now defaults to an empty string, preventing potential null dereference errors.

Changes

Cohort / File(s) Summary
Null-safety guard in array parsing
oshi-core/src/main/java/oshi/software/os/mac/MacInstalledApps.java
Introduces temporary variable and null check in parseDict method when handling <array> values; defaults to empty string if parseStringArray returns null instead of propagating null

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A null that could not break my heart,
With guards so swift and smart,
Arrays now safely turn to string,
No dereference sting!
✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: improving null checking in MacInstalledApps, which aligns with the PR's primary objective.
Linked Issues check ✅ Passed The PR addresses the null-dereference risk reported in #3068 by adding null guards in parseDict when encountering array values, preventing null dereferencing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing null-checking issues in MacInstalledApps as specified in issue #3068; no unrelated modifications detected.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

@codecov

codecov Bot commented Jan 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.32%. Comparing base (9e16b82) to head (43d1d9b).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3069      +/-   ##
==========================================
+ Coverage   84.56%   85.32%   +0.75%     
==========================================
  Files          32       32              
  Lines        1458     1458              
  Branches      215      215              
==========================================
+ Hits         1233     1244      +11     
+ Misses        130      116      -14     
- Partials       95       98       +3     

☔ View full report in Codecov by Sentry.
📢 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@oshi-core/src/main/java/oshi/software/os/mac/MacInstalledApps.java`:
- Around line 183-185: The code sets val to "" when parseStringArray returns
null, which uses an empty-string sentinel that downstream logic may treat as a
real value; update the logic in MacInstalledApps (around extractBalancedInner
and parseStringArray) to avoid the empty-string sentinel: when parsed == null
either set val to Constants.UNKNOWN (importing/using the project Constants) or
omit inserting the map entry altogether so missing arrays are represented as
UNKNOWN/absent rather than "". Change the assignment of val (the variable
holding the parsed array result) and any subsequent map insertion to implement
the chosen behavior consistently.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c65a450 and 43d1d9b.

📒 Files selected for processing (1)
  • oshi-core/src/main/java/oshi/software/os/mac/MacInstalledApps.java
⏰ 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). (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Analyze (java)

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

@dbwiddis
dbwiddis merged commit 8de881c into oshi:master Jan 27, 2026
14 checks passed
dbwiddis added a commit to dyorgio/oshi that referenced this pull request Jan 27, 2026
@dbwiddis
dbwiddis deleted the fix-null 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.

Null dereference in MacInstalledApps

1 participant