From 4927f71ce13f7a90241bd208e3643f2f2c0b58fe Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Thu, 8 Oct 2026 10:15:40 -0500 Subject: [PATCH] fix(ecs): look up a task definition without failing on a stored record with no ARN (#5296) * fix(ecs): look up a task definition without failing on a stored record with no ARN resolveTaskDefinitionOrThrow compared each stored definition's ARN with d.getTaskDefinitionArn().equals(ref), so a family or family:revision lookup threw a NullPointerException when the region held a definition with no ARN. The comparison is now null-safe, and EcsTaskDefinitionLegacyKeyTest covers a family lookup next to such a record. * fix(ecs): answer a missing task definition reference with ClientException A null or blank reference reached the lookup's comparisons and threw a NullPointerException, a 500, once the region held any task definition: the family fallback's family.equals(...) failed even before the null-safe ARN comparison. It is now refused up front with the same ClientException an unknown reference gets. * test(ecs): cover the family lookup in the existing no-ARN test --- .../floci/services/ecs/EcsService.java | 5 ++++- .../ecs/EcsTaskDefinitionLegacyKeyTest.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java index b33f1bfbae..1d355871bf 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java @@ -5265,10 +5265,13 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab } private TaskDefinition resolveTaskDefinitionOrThrow(String ref, String region) { + if (ref == null || ref.isBlank()) { + throw new AwsException("ClientException", "Unable to describe task definition: " + ref, 400); + } TaskDefinition td = taskDefinitions.get(familyKey(region, ref)); if (td != null) { return td; } td = taskDefinitionsIn(region) - .filter(d -> d.getTaskDefinitionArn().equals(ref) + .filter(d -> ref.equals(d.getTaskDefinitionArn()) || (d.getFamily() + ":" + d.getRevision()).equals(ref)) .findFirst().orElse(null); if (td != null) { return td; } diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsTaskDefinitionLegacyKeyTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsTaskDefinitionLegacyKeyTest.java index a05638daac..95ab57fb0a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsTaskDefinitionLegacyKeyTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsTaskDefinitionLegacyKeyTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ecs; import com.fasterxml.jackson.core.type.TypeReference; import io.github.hectorvent.floci.config.EmulatorConfig; +import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend; import io.github.hectorvent.floci.core.storage.StorageBackend; @@ -16,6 +17,7 @@ import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -74,6 +76,8 @@ class EcsTaskDefinitionLegacyKeyTest { assertEquals(List.of(registered.getTaskDefinitionArn()), arns(service, REGION)); assertEquals(registered.getTaskDefinitionArn(), service.describeTaskDefinition(FAMILY + ":1", REGION).getTaskDefinitionArn()); + assertEquals(registered.getTaskDefinitionArn(), + service.describeTaskDefinition(FAMILY, REGION).getTaskDefinitionArn()); } @Test @@ -93,6 +97,18 @@ class EcsTaskDefinitionLegacyKeyTest { assertEquals(2, register(service, REGION).getRevision()); } + // Catches: a missing reference dereferenced while searching a populated region, a 500 + // NullPointerException instead of the ClientException any unknown reference gets. + @Test + void aMissingReferenceInAPopulatedRegionIsAClientException() { + EcsService service = newService(new InMemoryStorageFactory()); + register(service, REGION); + + AwsException e = assertThrows(AwsException.class, () -> service.describeTaskDefinition(null, REGION)); + + assertEquals("ClientException", e.getErrorCode()); + } + private static TaskDefinition legacyDefinition() { TaskDefinition td = new TaskDefinition(); td.setFamily(FAMILY);