Skip to content

Fix Sonar violations for InterruptedException handling in waitForRapidResults #1492

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.blackduck.integration.blackduck.bdio2.model.BdioFileContent;
import com.blackduck.integration.detect.configuration.enumeration.RapidCompareMode;
Expand Down Expand Up @@ -257,7 +256,6 @@ public class OperationRunner {
private static final String INTELLIGENT_SCAN_SCASS_CONTENT_TYPE = "application/vnd.blackducksoftware.intelligent-persistence-scan-4+protobuf-jsonld";
public static final ImmutableList<Integer> RETRYABLE_AFTER_WAIT_HTTP_EXCEPTIONS = ImmutableList.of(408, 429, 502, 503, 504);
public static final ImmutableList<Integer> RETRYABLE_WITH_BACKOFF_HTTP_EXCEPTIONS = ImmutableList.of(425, 500);
private static final String POLICY_STATUS_RESOLVED = "RESOLVED";
private List<File> binaryUserTargets = new ArrayList<>();
BinaryScanFindMultipleTargetsOperation binaryScanFindMultipleTargetsOperation;

Expand Down Expand Up @@ -721,10 +719,11 @@ public List<DeveloperScansScanView> waitForRapidResults(BlackDuckRunData blackDu
mode,
calculateMaxWaitInSeconds(fibonacciSequenceIndex)
);
} catch (InterruptedException e) {
throw new InterruptedException(e.getMessage());
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

Creating a new InterruptedException and throwing it loses the original stack trace and interrupt status. Instead, you should re-interrupt the current thread using Thread.currentThread().interrupt() and then rethrow the original exception or wrap it in an unchecked exception.

Suggested change
throw new InterruptedException(e.getMessage());
Thread.currentThread().interrupt();
throw new OperationException("Thread was interrupted during rapid scan wait.", e);

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.

This might be a good suggestion. You could simply throw e;.
If you follow what auditLog.namedInternal() does, you'll see that eventually OperationWrapper.wrapped() is called which handles InterruptedException as described here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. I've updated it as per the suggestion.

} catch (IntegrationRestException e) {
throw handleRapidScanException(e);
} catch (Exception e) {
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

The removal of the error logging statement means that exceptions other than InterruptedException and IntegrationRestException will no longer be logged before being wrapped in OperationException. This could make debugging more difficult as the original exception details may be lost.

Suggested change
} catch (Exception e) {
} catch (Exception e) {
logger.error("An unexpected error occurred during the rapid wait operation.", e);

Copilot uses AI. Check for mistakes.

logger.error("Exception while waiting for rapid results: {}", e.getMessage(), e);
throw new OperationException(e);
}
});
Expand Down