### Question:
SpatialIndexCache extends IndexPartsCache<CoordinateReferenceSystem,T> { T uncheckedSelect( CoordinateReferenceSystem crs ) { T existing = cache.get( crs ); if ( existing != null ) { return existing; } instantiateCloseLock.lock(); try { assertOpen(); return cache.computeIfAbsent( crs, key -> { try { return factory.newSpatial( crs ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } } ); } finally { instantiateCloseLock.unlock(); } } SpatialIndexCache( Factory<T> factory );   }### Answer:
@Test public void stressInstantiationWithClose() throws Throwable { StringFactory factory = new StringFactory(); SpatialIndexCache<String> cache = new SpatialIndexCache<>( factory ); Race race = new Race().withRandomStartDelays(); MutableInt instantiatedAtClose = new MutableInt(); race.addContestant( () -> { try { cache.uncheckedSelect( CoordinateReferenceSystem.WGS84 ); cache.uncheckedSelect( CoordinateReferenceSystem.Cartesian_3D ); } catch ( IllegalStateException e ) { } }, 1 ); race.addContestant( () -> { cache.closeInstantiateCloseLock(); instantiatedAtClose.setValue( count( cache ) ); }, 1 ); race.go(); try { cache.uncheckedSelect( CoordinateReferenceSystem.Cartesian ); fail( "No instantiation after closed" ); } catch ( IllegalStateException e ) { } assertEquals( instantiatedAtClose.intValue(), count( cache ) ); }