Source:
<code>private void parseAndValidate() { <START> if (composeFileContent == null) { <END> return; } Map<String, ?> map = (Map<String, ?>) composeFileContent; final Map<String, ?> servicesMap; if (map.containsKey("version")) { if ("2.0".equals(map.get("version"))) { log.warn("Testcontainers may not be able to clean up networks spawned using Docker Compose v2.0 files. " + "Please see <LINK_0>, and specify 'version: \"2.1\"' or " + "higher in {}", composeFileName); } if (!map.containsKey("services")) { log.debug("Compose file has an unknown format: 'version' is set but 'services' is not defined", composeFileName); return; } Object services = map.get("services"); if (!(services instanceof Map)) { log.debug("Compose file has an unknown format: 'services' is not Map", composeFileName); return; } servicesMap = (Map<String, ?>) services; } else { servicesMap = map; } for (Map.Entry<String, ?> entry : servicesMap.entrySet()) { String serviceName = entry.getKey(); Object serviceDefinition = entry.getValue(); if (!(serviceDefinition instanceof Map)) { log.debug("Compose file has an unknown format: service '{}' is not Map", composeFileName, serviceName); break; } final Map serviceDefinitionMap = (Map) serviceDefinition; if (serviceDefinitionMap.containsKey("container_name")) { throw new IllegalStateException(String.format( "Compose file %s has 'container_name' property set for service '%s' but this property is not supported by Testcontainers, consider removing it", composeFileName, serviceName )); } if (serviceDefinitionMap.containsKey("image") && serviceDefinitionMap.get("image") instanceof String) { imageNames.add((String) serviceDefinitionMap.get("image")); } } }</code><technical_language>Is this necessary? yaml.load() return if yaml is valid other constructor is for testing</technical_language>

Target:
private void parseAndValidate() { final Map<String, ?> servicesMap; if (composeFileContent.containsKey("version")) { if ("2.0".equals(composeFileContent.get("version"))) { log.warn("Testcontainers may not be able to clean up networks spawned using Docker Compose v2.0 files. " + "Please see <LINK_0>, and specify 'version: \"2.1\"' or " + "higher in {}", composeFileName); } final Object servicesElement = composeFileContent.get("services"); if (servicesElement == null) { log.debug("Compose file has an unknown format: 'version' is set but 'services' is not defined", composeFileName); return; } if (!(servicesElement instanceof Map)) { log.debug("Compose file has an unknown format: 'services' is not Map", composeFileName); return; } servicesMap = (Map<String, ?>) servicesElement; } else { servicesMap = composeFileContent; } for (Map.Entry<String, ?> entry : servicesMap.entrySet()) { String serviceName = entry.getKey(); Object serviceDefinition = entry.getValue(); if (!(serviceDefinition instanceof Map)) { log.debug("Compose file has an unknown format: service '{}' is not Map", composeFileName, serviceName); break; } final Map serviceDefinitionMap = (Map) serviceDefinition; if (serviceDefinitionMap.containsKey("container_name")) { throw new IllegalStateException(String.format( "Compose file %s has 'container_name' property set for service '%s' but this property is not supported by Testcontainers, consider removing it", composeFileName, serviceName )); } if (serviceDefinitionMap.containsKey("image") && serviceDefinitionMap.get("image") instanceof String) { serviceImageNames.add((String) serviceDefinitionMap.get("image")); } } }