Skip to content

Commit

Permalink
WELD-2781 workaround stack overflow with DEBUG logging and firing PAT…
Browse files Browse the repository at this point in the history
… for enums
  • Loading branch information
manovotn committed Mar 9, 2024
1 parent dafdd3b commit df5e8e0
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions impl/src/main/java/org/jboss/weld/util/reflection/Formats.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,29 @@ public static String addSpaceIfNeeded(String string) {
}
}

public static String formatAsFormalParameterList(Iterable<? extends AnnotatedParameter<?>> parameters) {
return "(" + formatIterable(parameters, new Function<AnnotatedParameter<?>>() {
public static String formatAsFormalParameterList(Iterable<? extends AnnotatedParameter<?>> parameters,
boolean belongsToMethodInEnum) {
// For any method params coming from an enum (which cannot become a bean but can have PAT fired for) we simplify
// logging to avoid possible stack overflow during several methods; see WELD-2781
Function<AnnotatedParameter<?>> parameterFunction;
if (belongsToMethodInEnum) {
parameterFunction = new Function<AnnotatedParameter<?>>() {
@Override
public String apply(AnnotatedParameter<?> from, int position) {
return commaDelimiterFunction().apply(from.getJavaParameter().getType().getName(), position);
}
};
} else {
parameterFunction = new Function<AnnotatedParameter<?>>() {

@Override
public String apply(AnnotatedParameter<?> from, int position) {
return commaDelimiterFunction().apply(formatParameter(from), position);
}
@Override
public String apply(AnnotatedParameter<?> from, int position) {
return commaDelimiterFunction().apply(formatParameter(from), position);
}

}) + ")";
};
}
return "(" + formatIterable(parameters, parameterFunction) + ")";
}

public static String formatParameter(AnnotatedParameter<?> parameter) {
Expand Down Expand Up @@ -617,7 +631,7 @@ public static String formatAnnotatedConstructor(AnnotatedConstructor<?> construc
+ Formats.addSpaceIfNeeded(Formats.formatAnnotations(constructor.getAnnotations()))
+ Formats.addSpaceIfNeeded(Formats.formatModifiers(constructor.getJavaMember().getModifiers()))
+ constructor.getDeclaringType().getJavaClass().getName()
+ Formats.formatAsFormalParameterList(constructor.getParameters());
+ Formats.formatAsFormalParameterList(constructor.getParameters(), false);
}

public static String formatAnnotatedField(AnnotatedField<?> field) {
Expand All @@ -633,7 +647,8 @@ public static String formatAnnotatedMethod(AnnotatedMethod<?> method) {
+ Formats.addSpaceIfNeeded(Formats.formatAnnotations(method.getAnnotations()))
+ Formats.addSpaceIfNeeded(Formats.formatModifiers(method.getJavaMember().getModifiers()))
+ method.getDeclaringType().getJavaClass().getName() + "."
+ method.getJavaMember().getName() + Formats.formatAsFormalParameterList(method.getParameters());
+ method.getJavaMember().getName() + Formats.formatAsFormalParameterList(method.getParameters(),
method.getDeclaringType().getJavaClass().isEnum());
}

public static String formatAnnotatedParameter(AnnotatedParameter<?> parameter) {
Expand Down

0 comments on commit df5e8e0

Please sign in to comment.