[Medium] FreePlayCodeExecutorFactory silently picks last duplicate registration #66

Closed
opened 2026-05-05 04:16:06 +00:00 by spikerj · 1 comment
Owner

Severity: Medium (DI safety)

File: SpikerSoft.Business/Domain/CodeExecution/Execution/FreePlayCodeExecutorFactory.cs (~16-18)

Problem: GroupBy(...).ToDictionary(..., g => g.Last()) silently picks the last registrar for duplicate LanguageId values. Misconfiguration (duplicate registrations) goes unnoticed.

Fix: Throw a descriptive exception when a duplicate is detected:

var duplicates = executors.GroupBy(e => e.LanguageId).Where(g => g.Count() > 1).ToList();
if (duplicates.Any())
    throw new InvalidOperationException($"Duplicate FreePlay executor registrations: {string.Join(', ', duplicates.Select(d => d.Key))}");

Acceptance criteria:

  • Duplicate registration throws on factory construction
  • Existing single-registration behavior unchanged
**Severity:** Medium (DI safety) **File:** `SpikerSoft.Business/Domain/CodeExecution/Execution/FreePlayCodeExecutorFactory.cs` (~16-18) **Problem:** `GroupBy(...).ToDictionary(..., g => g.Last())` silently picks the last registrar for duplicate `LanguageId` values. Misconfiguration (duplicate registrations) goes unnoticed. **Fix:** Throw a descriptive exception when a duplicate is detected: ```csharp var duplicates = executors.GroupBy(e => e.LanguageId).Where(g => g.Count() > 1).ToList(); if (duplicates.Any()) throw new InvalidOperationException($"Duplicate FreePlay executor registrations: {string.Join(', ', duplicates.Select(d => d.Key))}"); ``` **Acceptance criteria:** - [ ] Duplicate registration throws on factory construction - [ ] Existing single-registration behavior unchanged
Author
Owner

Resolved.

The factory now scans for duplicate LanguageId registrations and throws InvalidOperationException with the offending key(s) and counts during construction:

var duplicates = grouped.Where(g => g.Count() > 1).Select(g => $"{g.Key} ({g.Count()})").ToList();
if (duplicates.Count > 0)
    throw new InvalidOperationException("Duplicate IFreePlayCodeExecutor registrations detected: ...");

Single-registration behaviour is unchanged. Misconfiguration now fails loudly at startup instead of silently selecting the last registrant.

File: SpikerSoft.Business/Domain/CodeExecution/Execution/FreePlayCodeExecutorFactory.cs.

**Resolved.** The factory now scans for duplicate `LanguageId` registrations and throws `InvalidOperationException` with the offending key(s) and counts during construction: ```csharp var duplicates = grouped.Where(g => g.Count() > 1).Select(g => $"{g.Key} ({g.Count()})").ToList(); if (duplicates.Count > 0) throw new InvalidOperationException("Duplicate IFreePlayCodeExecutor registrations detected: ..."); ``` Single-registration behaviour is unchanged. Misconfiguration now fails loudly at startup instead of silently selecting the last registrant. File: `SpikerSoft.Business/Domain/CodeExecution/Execution/FreePlayCodeExecutorFactory.cs`.
Sign in to join this conversation.