vaadin / kubernetes-kit

Other
3 stars 3 forks source link

Make compatible with Collaboration Kit #90

Closed MatthewVaadin closed 11 months ago

MatthewVaadin commented 12 months ago

Description

As part of the work to allow Collaboration Kit to work with the Kubernetes Kit session serialization, it was found that K8s Kit has an issue when trying to determine if a bean has been defined for transient fields. If the class is just Object, Spring returns a prototype bean.

Type of change

mcollovati commented 12 months ago

I propose another little change related to SpringTransientHandler. To prevent runtime errors, like the one with the Object.class bean detection resolved by this PR, The matchesPrototype method could check if the bean name effectively exists before calling isPrototype because the latter throws an exception if the bean is not defined.

    private boolean matchesPrototype(String beanName, Object beanDefinition,
            Class<?> fieldValueType) {
        return appCtx.containsBean(beanName) && appCtx.isPrototype(beanName);
    }

In addition, as discussed with @MatthewVaadin, prototype beans may cause issues in deserialization: for example, if there's a prototype Consumer bean registered and a class has a transient field of type Consumer that is however not injected (e.g. assigned a lambda in the constructor), the handler will potentially detect it as injectable and during deserialization inject an undesired object. I wonder if we should remove the prototype detection or find a more precise way to detect if the field instance is really a prototype bean.