@Test
  public void createRegionFactoryShouldReturnNewInstanceWithDefaultValues() {
    PartitionAttributesFactory<Integer, String> paf = new PartitionAttributesFactory<>();
    paf.setTotalNumBuckets(111);
    paf.setRedundantCopies(0);
    paf.addFixedPartitionAttributes(createFixedPartition("one", true, 111));

    RegionFactory<Integer, String> regionFactory1 =
        cache.createRegionFactory(RegionShortcut.PARTITION);
    regionFactory1.setPartitionAttributes(paf.create());

    Region<Integer, String> region1 = regionFactory1.create("region1");

    PartitionAttributesFactory<String, Object> paf2 = new PartitionAttributesFactory<>();
    paf2.setColocatedWith(region1.getFullPath());
    paf2.setTotalNumBuckets(111);
    paf2.setRedundantCopies(0);

    RegionFactory<String, Object> regionFactory2 =
        cache.createRegionFactory(RegionShortcut.PARTITION);

    PartitionAttributes<String, Object> attrs2 = paf2.create();
    regionFactory2.setPartitionAttributes(attrs2);
    assertThatCode(() -> regionFactory2.create("region2")).doesNotThrowAnyException();
  }
Cache.createRegionFactory should return a new instance with default values.

<p>
Prior to the bug fix, Cache.createRegionFactory was internally reusing a modifiable instance of
RegionAttributes.

<p>
TRAC #51616: Cache.getRegionAttributes returns modifiable RegionAttributes, with unintended side
effects

<p>
Before the bug was fixed, the 2nd regionFactory.create threw this call stack:

<pre>
java.lang.IllegalStateException: FixedPartitionAttributes "[FixedPartitionAttributes@[partitionName=one;isPrimary=true;numBuckets=111]]" can not be specified in PartitionAttributesFactory if colocated-with is specified.
    at com.gemstone.gemfire.internal.cache.PartitionAttributesImpl.validateWhenAllAttributesAreSet(PartitionAttributesImpl.java:569)
    at com.gemstone.gemfire.cache.AttributesFactory.validateAttributes(AttributesFactory.java:1515)
    at com.gemstone.gemfire.cache.AttributesFactory.create(AttributesFactory.java:1392)
    at com.gemstone.gemfire.cache.RegionFactory.create(RegionFactory.java:839)
    at PartitionAttributesTest.modifiedVcopsCreateCollocatedFixedRegions(PartitionAttributesTest.java:155)
    at PartitionAttributesTest.main(PartitionAttributesTest.java:47)
</pre>
geode-core/src/integrationTest/java/org/apache/geode/internal/CreateRegionFactoryNewInstanceRegressionTest.java