Source:
<code>public void populateSpatial( WebClient client, @Nullable Geometry geometry, @Nullable BoundingBox boundingBox, @Nullable Polygon polygon, @Nullable PointRadius pointRadius, List<String> parameters) { if (Stream.of(geometry, boundingBox, polygon, pointRadius).filter(Objects::nonNull).count() > 1) { throw new IllegalArgumentException("Only one spatial search may be populated"); } if (geometry != null) { <START> checkAndReplace(client, new WKTWriter().write(geometry), OpenSearchConstants.GEOMETRY, parameters); <END> } else if (boundingBox != null) { checkAndReplace( client, Stream.of( boundingBox.getWest(), boundingBox.getSouth(), boundingBox.getEast(), boundingBox.getNorth()) .map(String::valueOf) .collect(Collectors.joining(OpenSearchConstants.BBOX_DELIMITER)), OpenSearchConstants.BBOX, parameters); } else if (polygon != null) { checkAndReplace( client, Arrays.stream(polygon.getCoordinates()) .flatMap(coordinate -> Stream.of(coordinate.y, coordinate.x)) .map(String::valueOf) .collect(Collectors.joining(OpenSearchConstants.POLYGON_LON_LAT_DELIMITER)), OpenSearchConstants.POLYGON, parameters); } else if (pointRadius != null) { checkAndReplace( client, String.valueOf(pointRadius.getLat()), OpenSearchConstants.LAT, parameters); checkAndReplace( client, String.valueOf(pointRadius.getLon()), OpenSearchConstants.LON, parameters); checkAndReplace( client, String.valueOf(pointRadius.getRadius()), OpenSearchConstants.RADIUS, parameters); } }</code><technical_language>Pretty private static final ThreadLocal<WKTWriter> WKT_WRITER_THREAD_LOCAL = ThreadLocal.withInitial(WKTWriter::new) instead performance benefit of repeatedly constructing new WKTWriters. WKT_WRITER_THREAD_LOCAL.get().write(geometry). Keeping is fine in test code, though</technical_language>

Target:
public void populateSpatial( WebClient client, @Nullable Geometry geometry, @Nullable BoundingBox boundingBox, @Nullable Polygon polygon, @Nullable PointRadius pointRadius, List<String> parameters) { if (Stream.of(geometry, boundingBox, polygon, pointRadius).filter(Objects::nonNull).count() > 1) { throw new IllegalArgumentException("Only one spatial search may be populated"); } if (geometry != null) { checkAndReplace( client, WKT_WRITER_THREAD_LOCAL.get().write(geometry), OpenSearchConstants.GEOMETRY, parameters); } else if (boundingBox != null) { checkAndReplace( client, Stream.of( boundingBox.getWest(), boundingBox.getSouth(), boundingBox.getEast(), boundingBox.getNorth()) .map(String::valueOf) .collect(Collectors.joining(OpenSearchConstants.BBOX_DELIMITER)), OpenSearchConstants.BBOX, parameters); } else if (polygon != null) { checkAndReplace( client, Arrays.stream(polygon.getCoordinates()) .flatMap(coordinate -> Stream.of(coordinate.y, coordinate.x)) .map(String::valueOf) .collect(Collectors.joining(OpenSearchConstants.POLYGON_LON_LAT_DELIMITER)), OpenSearchConstants.POLYGON, parameters); } else if (pointRadius != null) { checkAndReplace( client, String.valueOf(pointRadius.getLat()), OpenSearchConstants.LAT, parameters); checkAndReplace( client, String.valueOf(pointRadius.getLon()), OpenSearchConstants.LON, parameters); checkAndReplace( client, String.valueOf(pointRadius.getRadius()), OpenSearchConstants.RADIUS, parameters); } }