Skip to content

[duplicate-code] Duplicate Code: Repeated WeekendPlan Constructor Pattern in WeekendPlanService #56

Description

@github-actions

🔍 Duplicate Code Detected: Repeated WeekendPlan Constructor Pattern

Analysis of latest commit on main

Assignee: @copilot

Summary

WeekendPlanService.getWeekendPlans() contains 20 nearly identical inline new WeekendPlan(...) constructor invocations, each passing 5 string arguments. This is a classic copy-paste data initialization pattern that should be externalized to a data source (JSON, YAML, or database) rather than hardcoded as repeated constructor calls in a service method.

Duplication Details

Pattern: Inline hardcoded data instantiation via repeated constructor calls

  • Severity: Medium
  • Occurrences: 20 instances
  • Location: src/main/java/com/example/demo/service/WeekendPlanService.java (lines 14–113, getWeekendPlans() method)
  • Code Sample:
// All 20 entries follow the exact same pattern:
new WeekendPlan(
    "LAN party de precision quirurgica",
    "Ranking de juegos + benchmark de quien tiene mejor setup",
    "0-20 EUR",
    "Alta",
    "Si baja el ping, sube el autoestima"
),
new WeekendPlan(
    "Hackaton casera de side projects",
    "4 horas para lanzar algo inutil pero legendario",
    "0-15 EUR",
    "Media",
    "No facturara, pero tendra README bonito"
),
// ... 18 more identical-structure entries

Impact Analysis

  • Maintainability: Adding, removing, or reordering plans requires editing source code and recompiling. The 5-argument positional constructor is error-prone — swapping vibe and socialBattery would compile silently but produce wrong output.
  • Bug Risk: Any change to the WeekendPlan constructor signature (e.g., adding a field) requires updating all 20 call sites.
  • Code Bloat: ~100 lines of data embedded in a service class obscures the actual business logic (getFridayHeadline()).
  • Testability: Tests cannot vary the dataset without modifying service source code.

Refactoring Recommendations

  1. Externalize data to JSON/YAML

    • Create src/main/resources/weekend-plans.json (or .yml)
    • Inject via @Value or load with ObjectMapper/YamlPropertiesFactoryBean
    • Estimated effort: 1–2 hours
    • Benefits: Data changes without recompile; easy to add/remove plans; supports i18n
  2. Use a builder or factory with named parameters

    • Replace positional 5-arg constructor with a builder (or Java record) to reduce swap errors
    • Estimated effort: 30 minutes
    • Benefits: Self-documenting call sites, compile-time safety
  3. Store in a database (longer term)

    • Move plans to an H2/PostgreSQL table seeded via data.sql
    • Estimated effort: 3–4 hours
    • Benefits: Runtime updates, pagination, filtering

Implementation Checklist

  • Review duplication findings
  • Choose externalization strategy (JSON/YAML resource file recommended for this demo app)
  • Create weekend-plans.json or weekend-plans.yml in src/main/resources/
  • Update WeekendPlanService to load plans from the resource file
  • Update tests to reflect new data loading mechanism
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 6 source files (controller/, model/, service/)
  • Detection Method: Semantic code analysis — structural pattern repetition
  • Analysis Date: 2026-05-29

Generated by Duplicate Code Detector · sonnet46 558.3K ·

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 May 31, 2026, 7:36 AM 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