Skip to content

Conversation

@soul2zimate
Copy link
Contributor

fix: handle package name format mismatch in dependency ignore logic

fixes #309

@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Handle package name format mismatch in dependency ignore

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Handle package name format mismatch in dependency ignore logic
• Support both underscore and hyphen formats in crate names
• Check both original and normalized package name formats
Diagram
flowchart LR
  A["Dependency name<br/>with underscores"] -->|normalize| B["Replace underscores<br/>with hyphens"]
  A -->|check| C["ignoredDeps set"]
  B -->|check| C
  C -->|match found| D["Skip dependency"]
  C -->|no match| E["Process dependency"]
Loading

Grey Divider

File Changes

1. src/main/java/io/github/guacsec/trustifyda/providers/CargoProvider.java 🐞 Bug fix +7/-1

Add package name format normalization for dependency filtering

• Enhanced shouldSkipDependency() method to handle package name format variations
• Added logic to normalize crate names by replacing underscores with hyphens
• Checks both original crate name and normalized format against ignored dependencies set
• Includes explanatory comment about crate name format handling

src/main/java/io/github/guacsec/trustifyda/providers/CargoProvider.java


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Possible NPE on dep.name 🐞 Bug ⛯ Reliability
Description
shouldSkipDependency now calls crateName.replace('_','-') without checking for null, so a
missing/invalid name field in cargo metadata will throw a NullPointerException and abort
dependency processing/SBOM creation.
Code

src/main/java/io/github/guacsec/trustifyda/providers/CargoProvider.java[R444-451]

+    // dep.name() returns the crate name (may have underscores)
+    String crateName = dep.name();
+    if (ignoredDeps.contains(crateName)) {
+      return true;
+    }
+    String packageNameFormat = crateName.replace('_', '-');
+    if (!crateName.equals(packageNameFormat) && ignoredDeps.contains(packageNameFormat)) {
      return true;
Evidence
CargoDep.name is a plain String record component populated via JSON deserialization (no
non-null/required enforcement in the model). The updated code dereferences it via replace(...),
and shouldSkipDependency is called from dependency-processing loops without being wrapped in a
try/catch, so an NPE will bubble up and break analysis.

src/main/java/io/github/guacsec/trustifyda/providers/CargoProvider.java[443-452]
src/main/java/io/github/guacsec/trustifyda/providers/rust/model/CargoDep.java[23-26]
src/main/java/io/github/guacsec/trustifyda/providers/CargoProvider.java[418-422]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`shouldSkipDependency` now dereferences `dep.name()` by calling `replace(&#x27;_&#x27;,&#x27;-&#x27;)`. If `name` is absent/null in the deserialized cargo metadata, this will throw a NullPointerException and abort SBOM generation.

### Issue Context
`CargoDep.name` is deserialized from external `cargo metadata` JSON into a plain `String` record component with no non-null/required enforcement. Call sites invoke `shouldSkipDependency` in dependency loops without catching exceptions.

### Fix Focus Areas
- src/main/java/io/github/guacsec/trustifyda/providers/CargoProvider.java[443-452]
- src/main/java/io/github/guacsec/trustifyda/providers/rust/model/CargoDep.java[23-26]

### Suggested change
In `shouldSkipDependency`:
- `String crateName = dep.name();`
- if `crateName == null || crateName.isBlank()` then `return false;` (or just skip the name-based checks)
- then run the existing ignore checks and depKinds logic as today.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@soul2zimate soul2zimate requested a review from ruromero February 11, 2026 07:02
@soul2zimate soul2zimate enabled auto-merge (squash) February 11, 2026 08:39
@soul2zimate soul2zimate merged commit 89707d8 into guacsec:main Feb 11, 2026
24 of 39 checks passed
@soul2zimate soul2zimate deleted the ignore_fix branch February 11, 2026 08:52
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.

Dependency ignore functionality fails for package names with hyphens

2 participants