Skip to content

[🧬 Duplicate Code Report 🔍] Duplicate Code: Response Map Building Pattern in SecurityDependencyDemoController #122

Description

@github-actions

Analysis of commit b16c75a

Assignee: @copilot

Summary

Three methods in SecurityDependencyDemoController share identical structural code for building LinkedHashMap<String, Object> response maps, creating ~18 lines of structural duplication across the class.

Duplication Details

Pattern: LinkedHashMap Response Building

  • Severity: Medium
  • Occurrences: 3
  • Locations:
    • src/main/java/com/example/demo/controller/SecurityDependencyDemoController.java (lines 24–29)
    • src/main/java/com/example/demo/controller/SecurityDependencyDemoController.java (lines 38–43)
    • src/main/java/com/example/demo/controller/SecurityDependencyDemoController.java (lines 48–53)
  • Code Sample:
// Repeated ~3 times with minor value differences
Map<String, Object> response = new LinkedHashMap<>();
response.put("mode", "non-exploitable");
response.put("dependency", "com.google.guava:guava:24.1.1-jre");
response.put("entries", demo);
return response;

Impact Analysis

  • Maintainability: Adding/renaming response fields requires changes in multiple places
  • Bug Risk: Inconsistent response structure if one method is updated without the others
  • Code Bloat: ~18 lines of structurally identical scaffolding reducible to a helper

Refactoring Recommendations

  1. Extract a buildResponse helper method

    • Signature: private Map<String, Object> buildResponse(String mode, String dependency, Map<String, Object> extras)
    • Location: SecurityDependencyDemoController (private helper) or a shared utility class
    • Estimated effort: 30 minutes
    • Benefits: Single place to update response structure
  2. Use a dedicated response DTO / record

    • Define SecurityDemoResponse(String mode, String dependency, Object data) as a Java record
    • Estimated effort: 1 hour
    • Benefits: Type safety, cleaner serialization contract

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 6 source files (ItemService, WeekendPlanService, DemoApplication, HomeController, ItemController, SecurityDependencyDemoController)
  • Detection Method: Semantic code analysis
  • Commit: b16c75a9e84e2410f95522da186bf4f75be2785b
  • Analysis Date: 2026-06-21T12:56:29Z

Generated by Duplicate Code Detector · sonnet46 883.8K ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/duplicate-code-detector.md@298f992955146a6731d380a9de808e17861708e5
  • expires on Jun 23, 2026, 1:00 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions