Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with Collaboration Kit #90

Merged
merged 8 commits into from Nov 8, 2023
Merged

Conversation

MatthewVaadin
Copy link
Contributor

@MatthewVaadin MatthewVaadin commented Nov 1, 2023

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

  • Bugfix
  • Feature

Copy link
Member

@heruan heruan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to extract all the formatting changes to a separate PR, so we keep the relevant change on a clean commit.

@mcollovati
Copy link
Contributor

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.

@heruan heruan merged commit 4e345d4 into main Nov 8, 2023
2 checks passed
@heruan heruan deleted the feat/collaboration-kit branch November 8, 2023 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants