Search 6 groundwork - Implement safer type checking for bridge type parameters

Description

See org.hibernate.search.v6poc.entity.pojo.mapping.building.impl.PojoIndexModelBinderImpl#addValueBridge in particular: we just compare raw types, which might not be enough when a bridge is defined as something like ValueBridge<List<? extends Integer>, Integer> for example.

*Another problem*: when a bridge is defined as something like MyBridge<T> implements ValueBridge<T, Integer>, we will accept properties that have a type that match T, which means anything that extends Object, which means everything. But the bridge itself might not accept everything: it might rely on some internal component that only accepts the runtime value of T, which can be more precise than Object. There really isn't much we can do in that case, so we should detect value bridges where the first argument to ValueBridge<T, F> is a type variable, and throw an exception.

A safer approach would be to:

1. Check that the type argument is not a type variable and does not contain any type variable (might be done in step 2), and fail if it does.
2. use the TypePatternMatcherFactory to create a pattern from the type argument, and ask that pattern to check that the value we're passing to the bridge has a supported type.

We wouldn't support everything, that's for sure, but at least we would get safety by default: we would fail when an unsupported type pattern is encountered. And we could improve in the future, adding new supported patterns.

Activity

Show:
Fixed

Details

Assignee

Reporter

Components

Sprint

Fix versions

Priority

Created July 20, 2018 at 11:34 AM
Updated October 8, 2020 at 12:30 PM
Resolved September 16, 2020 at 8:08 AM