Skip to content

Commit

Permalink
fixed accessible getter selection for conditional bean loading
Browse files Browse the repository at this point in the history
  • Loading branch information
GavrilovSV committed Feb 23, 2022
1 parent c5a99f6 commit 9869ddb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Expand Up @@ -209,7 +209,7 @@
* Can be used in combination with {@link #beanProperty()} to specify the required bean property
*
* @return The configuration properties class
* @since 3.3.0
* @since 3.4.0
*/
Class bean() default void.class;

Expand All @@ -219,7 +219,7 @@
* set for the bean to load.
*
* @return The configuration property that should be set.
* @since 3.3.0
* @since 3.4.0
*/
String beanProperty() default "";

Expand Down
Expand Up @@ -1812,12 +1812,13 @@ public void visitAnnotationMemberPropertyInjectionPoint(TypedElement annotationM
.getValue(AccessorsStyle.class, "readPrefixes", String[].class)
.orElse(new String[]{AccessorsStyle.DEFAULT_READ_PREFIX});

memberPropertyGetter = annotationMemberClassElement.getEnclosedElements(ElementQuery.ALL_METHODS)
.stream()
.filter(methodElement -> NameUtils.getPropertyNameForGetter(methodElement.getSimpleName(), readPrefixes).equals(annotationMemberProperty))
.filter(this::isMethodAccessible)
.findFirst()
.orElse(null);
memberPropertyGetter = annotationMemberClassElement.getEnclosedElement(
ElementQuery.ALL_METHODS
.onlyAccessible(beanTypeElement)
.onlyInstance()
.named((name) -> name.equals(NameUtils.getterNameFor(annotationMemberProperty, readPrefixes)))
.filter((e) -> !e.hasParameters())
).orElse(null);
}

if (memberPropertyGetter == null) {
Expand All @@ -1830,16 +1831,6 @@ public void visitAnnotationMemberPropertyInjectionPoint(TypedElement annotationM
}
}

private boolean isMethodAccessible(MethodElement methodElement) {
if (methodElement.isPublic()) {
return true;
} else if (methodElement.isPrivate()) {
return false;
} else {
return beanTypeElement.getPackage().equals(methodElement.getDeclaringType().getPackage());
}
}

@Override
public void visitFieldValue(
TypedElement declaringType,
Expand Down

0 comments on commit 9869ddb

Please sign in to comment.