Skip to content

Fix: Gradle Native Inspection Adds Invalid Suffix to Version in BDIO Entry #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2025

Conversation

zahidblackduck
Copy link
Collaborator

JIRA Ticket

IDETECT-4736

Description:
This merge request aims to fix an issue where the Gradle Native Inspector adds a +FAILED suffix to the version field in BDIO entries. This was causing incorrect GAV parsing. The version is now split on whitespace to discard any trailing status indicators like FAILED, ensuring only the clean semantic version is captured.

@zahidblackduck zahidblackduck marked this pull request as draft July 18, 2025 05:06
@zahidblackduck zahidblackduck requested a review from Copilot July 18, 2025 05:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where the Gradle Native Inspector was incorrectly including status suffixes like +FAILED in version strings within BDIO entries, causing GAV parsing issues.

  • Strips trailing status indicators from version strings by splitting on whitespace and taking only the first part
  • Ensures clean semantic versions are captured in dependency parsing

@@ -69,7 +69,7 @@ public GradleTreeNode parseLine(String line, Map<String, String> metadata) {
} else {
String group = gav.get(0);
String name = gav.get(1);
String version = gav.get(2);
String version = gav.get(2).split("\\s")[0];
Copy link
Preview

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

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

The code assumes that splitting on whitespace will always produce at least one element, but if gav.get(2) is an empty string, split() will return an empty array and accessing index [0] will throw an IndexOutOfBoundsException. Consider using trim() first and adding a null/empty check.

Suggested change
String version = gav.get(2).split("\\s")[0];
String version;
if (StringUtils.isNotBlank(gav.get(2))) {
version = gav.get(2).split("\\s")[0];
} else {
logger.trace(String.format("The version part of GAV is empty or null: %s", line));
return GradleTreeNode.newUnknown(level);
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 ^
Not 100% sure due to layers, but at first glance it looks like the possibility that a version can be an empty string exists (line 127 in GradleReportLineParser). Maybe we could add a test case (or do a manual test) to confirm?

Copy link
Collaborator Author

@zahidblackduck zahidblackduck Jul 30, 2025

Choose a reason for hiding this comment

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

It is highly unlikely that ./gradlew dependencies would ever return a tree with a dependency that has no version. That’s why we currently treat such lines as UNKNOWN nodes. I’ve added a test case to confirm this behavior just to be thorough.

@zahidblackduck zahidblackduck requested a review from dterrybd July 29, 2025 06:35
@shantyk
Copy link
Contributor

shantyk commented Jul 29, 2025

Would the transitives of a dependency that has +FAILED suffix be missing from the BDIO in this case? In the ticket, it looks like a +FAILED line is a leaf in any subtree that contains it. I do not recall a clear answer from the discussions/see it in the comments under IDETECT-4736.

@@ -69,7 +69,7 @@ public GradleTreeNode parseLine(String line, Map<String, String> metadata) {
} else {
String group = gav.get(0);
String name = gav.get(1);
String version = gav.get(2);
String version = StringUtils.substringBefore(gav.get(2), " ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Some unit test cases would be nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added unit tests to validate the change.

@zahidblackduck
Copy link
Collaborator Author

zahidblackduck commented Jul 30, 2025

Would the transitives of a dependency that has +FAILED suffix be missing from the BDIO in this case? In the ticket, it looks like a +FAILED line is a leaf in any subtree that contains it. I do not recall a clear answer from the discussions/see it in the comments under IDETECT-4736.

Yes, you are right. If a dependency has FAILED suffix in it, all the transitive dependencies brought up by that dependency are cut off from the tree. But, gradle build succeeds. It is a gradle native behavior. It was discussed with the team. As, gradle build succeeds, so should detect while parsing the dependency tree.

@zahidblackduck zahidblackduck marked this pull request as ready for review July 31, 2025 10:04
@zahidblackduck zahidblackduck merged commit 4ac93ae into master Aug 1, 2025
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.

4 participants