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

WELD-2781 workaround stack overflow with DEBUG logging and firing PAT… #2915

Merged
merged 1 commit into from
Mar 9, 2024
Merged
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
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
Loading