🔍 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
-
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
-
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
-
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
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
🔍 Duplicate Code Detected: Repeated
WeekendPlanConstructor PatternAnalysis of latest commit on
mainAssignee:
@copilotSummary
WeekendPlanService.getWeekendPlans()contains 20 nearly identical inlinenew 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
src/main/java/com/example/demo/service/WeekendPlanService.java(lines 14–113,getWeekendPlans()method)Impact Analysis
vibeandsocialBatterywould compile silently but produce wrong output.WeekendPlanconstructor signature (e.g., adding a field) requires updating all 20 call sites.getFridayHeadline()).Refactoring Recommendations
Externalize data to JSON/YAML
src/main/resources/weekend-plans.json(or.yml)@Valueor load withObjectMapper/YamlPropertiesFactoryBeanUse a builder or factory with named parameters
Store in a database (longer term)
data.sqlImplementation Checklist
weekend-plans.jsonorweekend-plans.ymlinsrc/main/resources/WeekendPlanServiceto load plans from the resource fileAnalysis Metadata
controller/,model/,service/)Add this agentic workflows to your repo
To install this agentic workflow, run