Skip to content

Commit

Permalink
Fixing "best" constructor choice.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 15, 2020
1 parent 48d817f commit 683a60e
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -397,13 +397,17 @@ public MethodVisitor wrap(
.getDeclaredMethods()
.filter(isConstructor().and(not(isPrivate())));
int arguments = Integer.MAX_VALUE;
boolean visible = false;
boolean packagePrivate = true;
MethodDescription.InDefinedShape current = null;
for (MethodDescription.InDefinedShape constructor : constructors) {
// We are choosing the shortest constructor with regards to arguments.
// Yet, we prefer a non-package-private constructor since they require
// the super class to be on the same class loader.
if (constructor.getParameters().size() < arguments
&& (!visible || constructor.isPackagePrivate())) {
&& (packagePrivate || !constructor.isPackagePrivate())) {
arguments = constructor.getParameters().size();
packagePrivate = constructor.isPackagePrivate();
current = constructor;
visible = constructor.isPackagePrivate();
}
}
if (current != null) {
Expand Down

0 comments on commit 683a60e

Please sign in to comment.