diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 6c16b6a8a..315175f82 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -103,8 +103,8 @@ public class Executables { /** * Finds all executable elements within the given type element, including executable elements defined in super - * classes and implemented interfaces. Methods defined in {@link java.lang.Object} are ignored, as well as - * implementations of {@link java.lang.Object#equals(Object)}. + * classes and implemented interfaces. Methods defined in {@link java.lang.Object}, + * implementations of {@link java.lang.Object#equals(Object)} and private methods are ignored * * @param elementUtils element helper * @param element the element to inspect @@ -182,7 +182,7 @@ public class Executables { List methodsToAdd, TypeElement parentType) { List safeToAdd = new ArrayList<>( methodsToAdd.size() ); for ( ExecutableElement toAdd : methodsToAdd ) { - if ( isNotObjectEquals( toAdd ) + if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { safeToAdd.add( new ExecutableElementAccessor( toAdd ) ); } @@ -217,6 +217,15 @@ public class Executables { return true; } + /** + * @param executable the executable to check + * + * @return {@code true}, iff the executable does not have a private modifier + */ + private static boolean isNotPrivate(ExecutableElement executable) { + return !executable.getModifiers().contains( Modifier.PRIVATE ); + } + /** * @param elementUtils the elementUtils * @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to