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

AnnotatedCreatorCollector should avoid processing synthetic static (factory) methods #2928

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,

// First find all potentially relevant static methods
for (Method m : ClassUtil.getClassMethods(type.getRawClass())) {
if (!Modifier.isStatic(m.getModifiers())) {
if (!_isIncludableFactoryMethod(m)) {
continue;
}
// all factory methods are fine:
Expand Down Expand Up @@ -233,7 +233,7 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
if (primaryMixIn != null) {
MemberKey[] methodKeys = null;
for (Method mixinFactory : primaryMixIn.getDeclaredMethods()) {
if (!Modifier.isStatic(mixinFactory.getModifiers())) {
if (!_isIncludableFactoryMethod(mixinFactory)) {
continue;
}
if (methodKeys == null) {
Expand Down Expand Up @@ -270,6 +270,14 @@ private List<AnnotatedMethod> _findPotentialFactories(TypeFactory typeFactory,
return result;
}

private static boolean _isIncludableFactoryMethod(Method m)
{
return Modifier.isStatic(m.getModifiers())
// 09-Nov-2020, ckozak: Avoid considering synthetic methods such as
// lambdas used within methods because they're not relevant.
&& !m.isSynthetic();
}

protected AnnotatedConstructor constructDefaultConstructor(ClassUtil.Ctor ctor,
ClassUtil.Ctor mixin)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected void _addMethodMixIns(TypeResolutionContext tc, Class<?> targetClass,
}
}

private boolean _isIncludableMemberMethod(Method m)
private static boolean _isIncludableMemberMethod(Method m)
{
if (Modifier.isStatic(m.getModifiers())
// Looks like generics can introduce hidden bridge and/or synthetic methods.
Expand Down