-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Issue with Requires condition with missingClasses as string values #11087
Conversation
package test; | ||
|
||
import io.micronaut.context.annotation.*; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there is an issue in micronaut-core 4.6.x when declaring something like this
@Requires(missingClasses = "org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder")
because this code in MatchesConditionUtils
if (requirement.contains(RequiresCondition.MEMBER_MISSING_CLASSES)) {
AnnotationClassValue<?>[] classes = requirement.annotationClassValues(RequiresCondition.MEMBER_MISSING_CLASSES);
if (classes.length > 0) {
preConditions.add(new MatchesAbsenceOfClassesCondition(classes));
}
}
expects to get classes in annotation value
public AnnotationClassValue<?>[] annotationClassValues(@NonNull String member) {
if (StringUtils.isEmpty(member)) {
return AnnotationClassValue.ZERO_ANNOTATION_CLASS_VALUES;
}
Object o = values.get(member);
if (o instanceof AnnotationClassValue<?> annotationClassValue) {
return new AnnotationClassValue[]{annotationClassValue};
}
if (o instanceof AnnotationClassValue<?>[] annotationClassValues) {
return annotationClassValues;
}
return AnnotationClassValue.ZERO_ANNOTATION_CLASS_VALUES;
}
in this case, instanceof returns AnnotationClassValue.ZERO_ANNOTATION_CLASS_VALUES
since value is string and then fails to match condition, actually condition will not be evaluated.
The "problem" is actually with:
Previous version would use But I think your fix is also correct, you might want to fix and test the singular method |
Added util method, will improve coverage as well.
|
* @return AnnotationClassValue for given class name | ||
*/ | ||
private static AnnotationClassValue<?> getAnnotationClassValue(String className) { | ||
Optional<Class<?>> theClass = ClassUtils.forName(className, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference from previous version is that it was using classloader from beanContext.getClassLoader()
and this will fallback to current thread classloader.
if (classLoader == null) {
classLoader = Thread.currentThread().getContextClassLoader();
}
if (classLoader == null) {
classLoader = ClassLoader.getSystemClassLoader();
}
Not sure if this could cause other issues.
Quality Gate passedIssues Measures |
@sdelamo and @radovanradic, could the issue reported be related to the problem described in micronaut-projects/micronaut-platform/discussions/1704? |
No description provided.