@@ -147,11 +147,10 @@ public void processResponseError(Exchange exchange) {
147147 var providerName = getProviderName (exchange );
148148 ProviderStatus status = new ProviderStatus ().ok (false ).name (providerName );
149149 Exception exception = (Exception ) exchange .getProperty (Exchange .EXCEPTION_CAUGHT );
150- if (exception == null ) {}
151150
152- Throwable cause = exception .getCause ();
151+ Throwable cause = exception != null ? exception .getCause () : null ;
153152
154- while (cause instanceof RuntimeCamelException && cause != null ) {
153+ while (cause instanceof RuntimeCamelException ) {
155154 cause = cause .getCause ();
156155 }
157156 if (cause == null ) {
@@ -327,55 +326,14 @@ private Source buildReportForSource(Map<String, PackageItem> pkgItemsData, Depen
327326 var packageItem = getPackageItem (packageRef , pkgItemsData );
328327 var directReport = new DependencyReport ().ref (packageRef );
329328
330- // Set issues if available
331- if (packageItem != null
332- && packageItem .issues () != null
333- && !packageItem .issues ().isEmpty ()) {
334- var issues =
335- packageItem .issues ().stream ()
336- .sorted (Comparator .comparing (Issue ::getCvssScore ).reversed ())
337- .collect (Collectors .toList ());
338- directReport .issues (issues );
339- directReport .setHighestVulnerability (issues .stream ().findFirst ().orElse (null ));
340- }
341-
342- // Set recommendation if available (extract PackageRef from TcRecommendation)
343- if (packageItem != null
344- && packageItem .recommendation () != null
345- && packageItem .recommendation ().packageName () != null ) {
346- directReport .recommendation (packageItem .recommendation ().packageName ());
347- }
329+ setIssues (packageItem , directReport );
330+ setRecommendations (packageItem , directReport );
348331
349332 List <TransitiveDependencyReport > transitiveReports =
350333 depEntry .getValue ().transitive ().stream ()
351334 .map (
352335 t -> {
353- var transitiveItem = getPackageItem (t , pkgItemsData );
354- List <Issue > transitiveIssues = Collections .emptyList ();
355- if (transitiveItem != null
356- && transitiveItem .issues () != null
357- && !transitiveItem .issues ().isEmpty ()) {
358- transitiveIssues =
359- transitiveItem .issues ().stream ()
360- .sorted (Comparator .comparing (Issue ::getCvssScore ).reversed ())
361- .collect (Collectors .toList ());
362- }
363- var highestTransitive = transitiveIssues .stream ().findFirst ();
364- if (highestTransitive .isPresent ()) {
365- if (directReport .getHighestVulnerability () == null
366- || directReport .getHighestVulnerability ().getCvssScore ()
367- < highestTransitive .get ().getCvssScore ()) {
368- directReport .setHighestVulnerability (highestTransitive .get ());
369- }
370- }
371- var transitiveReport =
372- new TransitiveDependencyReport ()
373- .ref (t )
374- .issues (transitiveIssues )
375- .highestVulnerability (highestTransitive .orElse (null ));
376- // Note: TransitiveDependencyReport doesn't have a recommendation field
377- // Recommendations are only set on direct dependencies
378- return transitiveReport ;
336+ return getTransitiveReport (pkgItemsData , directReport , t );
379337 })
380338 .filter (transitiveReport -> !transitiveReport .getIssues ().isEmpty ())
381339 .collect (Collectors .toList ());
@@ -387,39 +345,93 @@ private Source buildReportForSource(Map<String, PackageItem> pkgItemsData, Depen
387345 }
388346 });
389347
390- // Process packages with recommendations-only that are not in the tree
391- // (these are recommendations for packages that might not be direct dependencies)
392348 if (pkgItemsData != null ) {
393- pkgItemsData .entrySet ().stream ()
394- .filter (
395- entry -> {
396- var packageItem = entry .getValue ();
397- // Include if it has a recommendation but no issues and wasn't already processed
398- return !processedRefs .contains (entry .getKey ())
399- && (packageItem .issues () == null || packageItem .issues ().isEmpty ())
400- && packageItem .recommendation () != null
401- && packageItem .recommendation ().packageName () != null ;
402- })
403- .forEach (
404- entry -> {
405- try {
406- var packageRef = new PackageRef (entry .getKey ());
407- var packageItem = entry .getValue ();
408- var directReport = new DependencyReport ().ref (packageRef );
409- directReport .recommendation (packageItem .recommendation ().packageName ());
410- sourceReport .add (directReport );
411- } catch (Exception e ) {
412- // Skip if packageRef cannot be created from the string
413- // This shouldn't happen but handle gracefully
414- }
415- });
349+ addRecommendationsWithoutIssues (pkgItemsData , sourceReport , processedRefs );
416350 }
417351
418352 sourceReport .sort (Collections .reverseOrder (new DependencyScoreComparator ()));
419353 var summary = buildSummary (pkgItemsData , tree , sourceReport );
420354 return new Source ().summary (summary ).dependencies (sourceReport );
421355 }
422356
357+ private void addRecommendationsWithoutIssues (
358+ Map <String , PackageItem > pkgItemsData ,
359+ List <DependencyReport > sourceReport ,
360+ Set <String > processedRefs ) {
361+ pkgItemsData .entrySet ().stream ()
362+ .filter (
363+ entry -> {
364+ var packageItem = entry .getValue ();
365+ // Include if it has a recommendation but no issues and wasn't already processed
366+ return !processedRefs .contains (entry .getKey ())
367+ && (packageItem .issues () == null || packageItem .issues ().isEmpty ())
368+ && packageItem .recommendation () != null
369+ && packageItem .recommendation ().packageName () != null ;
370+ })
371+ .forEach (
372+ entry -> {
373+ try {
374+ var packageRef = new PackageRef (entry .getKey ());
375+ var packageItem = entry .getValue ();
376+ var directReport = new DependencyReport ().ref (packageRef );
377+ directReport .recommendation (packageItem .recommendation ().packageName ());
378+ sourceReport .add (directReport );
379+ } catch (Exception e ) {
380+ // Skip if packageRef cannot be created from the string
381+ // This shouldn't happen but handle gracefully
382+ }
383+ });
384+ }
385+
386+ private TransitiveDependencyReport getTransitiveReport (
387+ Map <String , PackageItem > pkgItemsData , DependencyReport directReport , PackageRef t ) {
388+ var transitiveItem = getPackageItem (t , pkgItemsData );
389+ List <Issue > transitiveIssues = Collections .emptyList ();
390+ if (transitiveItem != null
391+ && transitiveItem .issues () != null
392+ && !transitiveItem .issues ().isEmpty ()) {
393+ transitiveIssues =
394+ transitiveItem .issues ().stream ()
395+ .sorted (Comparator .comparing (Issue ::getCvssScore ).reversed ())
396+ .collect (Collectors .toList ());
397+ }
398+ var highestTransitive = transitiveIssues .stream ().findFirst ();
399+ if (highestTransitive .isPresent ()) {
400+ if (directReport .getHighestVulnerability () == null
401+ || directReport .getHighestVulnerability ().getCvssScore ()
402+ < highestTransitive .get ().getCvssScore ()) {
403+ directReport .setHighestVulnerability (highestTransitive .get ());
404+ }
405+ }
406+ var transitiveReport =
407+ new TransitiveDependencyReport ()
408+ .ref (t )
409+ .issues (transitiveIssues )
410+ .highestVulnerability (highestTransitive .orElse (null ));
411+ // Note: TransitiveDependencyReport doesn't have a recommendation field
412+ // Recommendations are only set on direct dependencies
413+ return transitiveReport ;
414+ }
415+
416+ private void setRecommendations (PackageItem packageItem , DependencyReport directReport ) {
417+ if (packageItem != null
418+ && packageItem .recommendation () != null
419+ && packageItem .recommendation ().packageName () != null ) {
420+ directReport .recommendation (packageItem .recommendation ().packageName ());
421+ }
422+ }
423+
424+ private void setIssues (PackageItem packageItem , DependencyReport directReport ) {
425+ if (packageItem != null && packageItem .issues () != null && !packageItem .issues ().isEmpty ()) {
426+ var issues =
427+ packageItem .issues ().stream ()
428+ .sorted (Comparator .comparing (Issue ::getCvssScore ).reversed ())
429+ .collect (Collectors .toList ());
430+ directReport .issues (issues );
431+ directReport .setHighestVulnerability (issues .stream ().findFirst ().orElse (null ));
432+ }
433+ }
434+
423435 private PackageItem getPackageItem (PackageRef ref , Map <String , PackageItem > pkgItemsData ) {
424436 return pkgItemsData .get (ref .ref ());
425437 }
@@ -452,8 +464,9 @@ private void incrementCounter(PackageItem item, VulnerabilityCounter counter, bo
452464 .forEach (
453465 i -> {
454466 var vulnerabilities = countVulnerabilities (i );
455- if (i .getSeverity () != null ) {
456- switch (i .getSeverity ()) {
467+ var severity = i .getSeverity ();
468+ if (severity != null ) {
469+ switch (severity ) {
457470 case CRITICAL -> counter .critical .addAndGet (vulnerabilities );
458471 case HIGH -> counter .high .addAndGet (vulnerabilities );
459472 case MEDIUM -> counter .medium .addAndGet (vulnerabilities );
0 commit comments