**Build scan:**
https://gradle-enterprise.elastic.co/s/o53eofdiy4zi6/tests/:modules:legacy-geo:test/org.elasticsearch.legacygeo.search.LegacyGeoShapeQueryTests/testRandomGeoCollectionQuery

**Reproduction line:**
`./gradlew ':modules:legacy-geo:test' --tests "org.elasticsearch.legacygeo.search.LegacyGeoShapeQueryTests.testRandomGeoCollectionQuery" -Dtests.seed=1283CBC9A6A14C18 -Dtests.locale=ar-MA -Dtests.timezone=Pacific/Rarotonga -Druntime.java=17`

**Applicable branches:**
master

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.legacygeo.search.LegacyGeoShapeQueryTests&tests.test=testRandomGeoCollectionQuery

**Failure excerpt:**
```
org.elasticsearch.index.mapper.MapperParsingException: failed to parse

  at __randomizedtesting.SeedInfo.seed([1283CBC9A6A14C18:7AFEC56AF0829390]:0)
  at org.elasticsearch.index.mapper.DocumentParser.wrapInMapperParsingException(DocumentParser.java:229)
  at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:82)
  at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:78)
  at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:999)
  at org.elasticsearch.index.shard.IndexShard.applyIndexOperation(IndexShard.java:948)
  at org.elasticsearch.index.shard.IndexShard.applyIndexOperationOnPrimary(IndexShard.java:892)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:321)
  at org.elasticsearch.action.bulk.TransportShardBulkAction$2.doRun(TransportShardBulkAction.java:187)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.performOnPrimary(TransportShardBulkAction.java:253)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:133)
  at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:72)
  at org.elasticsearch.action.support.replication.TransportWriteAction$1.doRun(TransportWriteAction.java:211)
  at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:768)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  at java.lang.Thread.run(Thread.java:833)

  Caused by: org.locationtech.spatial4j.exception.InvalidShapeException: Self-intersection at or near point (-7.263028500846136E-215, 1.6091640925070122E-219, NaN)

    at org.locationtech.spatial4j.shape.jts.JtsGeometry.validate(JtsGeometry.java:127)
    at org.locationtech.spatial4j.shape.jts.JtsGeometry.assertValidate(JtsGeometry.java:113)
    at org.locationtech.spatial4j.shape.jts.JtsGeometry.<init>(JtsGeometry.java:84)
    at org.elasticsearch.legacygeo.builders.ShapeBuilder.jtsGeometry(ShapeBuilder.java:181)
    at org.elasticsearch.legacygeo.builders.PolygonBuilder.buildS4J(PolygonBuilder.java:246)
    at org.elasticsearch.legacygeo.builders.PolygonBuilder.buildS4J(PolygonBuilder.java:44)
    at org.elasticsearch.legacygeo.builders.GeometryCollectionBuilder.buildS4J(GeometryCollectionBuilder.java:162)
    at org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper.index(LegacyGeoShapeFieldMapper.java:594)
    at org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper.index(LegacyGeoShapeFieldMapper.java:86)
    at org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.lambda$parse$0(AbstractGeometryFieldMapper.java:187)
    at org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper$LegacyGeoShapeParser.parse(LegacyGeoShapeFieldMapper.java:404)
    at org.elasticsearch.index.mapper.AbstractGeometryFieldMapper.parse(AbstractGeometryFieldMapper.java:187)
    at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:409)
    at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:460)
    at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:313)
    at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:278)
    at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:127)
    at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:79)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:78)
    at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:999)
    at org.elasticsearch.index.shard.IndexShard.applyIndexOperation(IndexShard.java:948)
    at org.elasticsearch.index.shard.IndexShard.applyIndexOperationOnPrimary(IndexShard.java:892)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:321)
    at org.elasticsearch.action.bulk.TransportShardBulkAction$2.doRun(TransportShardBulkAction.java:187)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.performOnPrimary(TransportShardBulkAction.java:253)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:133)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.dispatchedShardOperationOnPrimary(TransportShardBulkAction.java:72)
    at org.elasticsearch.action.support.replication.TransportWriteAction$1.doRun(TransportWriteAction.java:211)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:768)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.lang.Thread.run(Thread.java:833)

```
test/framework/src/main/java/org/elasticsearch/search/geo/GeoShapeQueryTestCase.java
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.GeometryCollection;
import org.elasticsearch.geometry.Line;
import org.elasticsearch.geometry.LinearRing;
import org.elasticsearch.geometry.Point;
import org.elasticsearch.geometry.Polygon;
import org.elasticsearch.geometry.Rectangle;
import org.elasticsearch.geometry.utils.StandardValidator;
import org.elasticsearch.geometry.utils.WellKnownText;
import org.elasticsearch.index.query.ExistsQueryBuilder;
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.elasticsearch.index.query.QueryBuilders.geoIntersectionQuery;
import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
public abstract class GeoShapeQueryTestCase extends GeoPointShapeQueryTestCase {