CollectionFactory API is not type-safe [SPR-12537] #17142
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: declined
A suggestion or change that we don't feel we should currently apply
Sam Brannen opened SPR-12537 and commented
Status Quo
The changes made to
CollectionFactory
in conjunction with #15691 resulted in method signatures that are not type-safe, and the changes made in conjunction with #17089 further exacerbated the issue.For example, the parameterized type
E
is not bound to the type of elements contained in thecollection
argument passed tocreateApproximateCollection()
. Thus casting the value returned byEnumSet#copyOf(EnumSet)
to(Collection<E>)
can never guarantee that the returned collection actually contains elements of typeE
.Example Tests
Each of the following tests (adapted from
CollectionFactoryTests
) compiles but throws aClassCastException
due to the lacking type safety of the method signatures.Deliverables
CollectionFactory
are type-safe.Collection<Object>
andMap<Object, Object>
as was done by the Spring Data Team.CollectionFactoryTests
accordingly.Affects: 4.0 GA
Issue Links:
The text was updated successfully, but these errors were encountered: