Skip to content

[BUG] ConcurrentModificationException when calling usingRecipe() from within a cook() callback (ie usingRecipe is not Reentrant) #146

@lestephane

Description

@lestephane

Describe the bug
I called usingRecipe from within a cook() callback, because the callback receives a MapMaidBuilder, and MapMaidBuilder has a usingRecipe() method. A ConcurrentModificationException is thrown.

To Reproduce

private fun MapMaidBuilder.withBigDecimalMappingSupport(): MapMaidBuilder {
    return usingRecipe(BigDecimalMappingRecipe)
}

private object BigDecimalMappingRecipe : Recipe {
    override fun cook(mapMaidBuilder: MapMaidBuilder) {
        mapMaidBuilder.serializingAndDeserializing(
            DuplexType.customPrimitive(
                BigDecimal::class.java,
                { it.toPlainString() },
                { BigDecimal(it) }
            )
        )
    }
}

private object ReproductionMappingConfiguration : Recipe {
    override fun cook(mapMaidBuilder: MapMaidBuilder) {
        mapMaidBuilder.withBigDecimalMappingSupport()
    }
}

fun main() {
    MapMaid.aMapMaid().usingRecipe(ReproductionMappingConfiguration).build().serializeToJson(BigDecimal(1))
}

Expected behavior

  • If the cook() callback does not support calling usingRecipe(), then it should not be given a MapMaidBuilder, but rather a subset of only those operations that are allowed at that point.
  • If the cook() callback sould support calling usingRecipe(), then it should work without throwing a ConcurrentModificationException

Environment description

  • project version used: 0.9.108
  • Java version used: N/A

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions