Skip to content

Commit

Permalink
Fix accidental invocation of fillInStackTrace()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaisiKoleni committed Mar 23, 2021
1 parent fd907f2 commit d6f7bdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public boolean canSanitize(Throwable t) {
public Throwable sanitize(Throwable t, MessageTransformer messageTransformer) {
Class<? extends Throwable> type = t.getClass();
// this is OK because we are only dealing with safe types here
ThrowableInfo info = ThrowableInfo.of(type, ThrowableUtils.retrievePropertyValues(t));
ThrowableInfo info = ThrowableInfo.of(type, ThrowableUtils.retrievePropertyValues(t,
ThrowableUtils.getRelevantPropertiesWithMethods(type, ThrowableUtils.IGNORE_PROPERTIES)));
info.sanitize(ThrowableUtils.PROPERTY_SANITIZER);
info.setMessage(messageTransformer.apply(info));
var throwableCreator = cachedThrowableCreators.computeIfAbsent(type, this::findThrowableCreator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ static Comparator<Constructor<?>> getConstructorPreferenceOrder() {
.reversed();
}

static Set<Entry<String, Method>> getPropertiesWithMethods(Class<?> type) {
return getRelevantPropertiesWithMethods(type, Set.of());
}

static Set<Entry<String, Method>> getRelevantPropertiesWithMethods(Class<?> type, Set<String> namesToIgnore) {
return Stream.of(type.getMethods()).map(method -> {
var propertyName = extractProperty(method);
Expand All @@ -115,24 +119,13 @@ static Set<Entry<String, Method>> getRelevantPropertiesWithMethods(Class<?> type
}).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet());
}

static Map<String, Object> retrievePropertyValues(Object instance) {
return retrievePropertyValues(instance, getPropertiesWithMethods(instance.getClass()));
}

static Map<String, Object> retrievePropertyValues(Object instance, Set<Entry<String, Method>> properties) {
return properties.stream()
.collect(Collectors.groupingBy(Map.Entry::getKey,
Collectors.mapping(property -> ReflectionSupport.invokeMethod(property.getValue(), instance),
Collectors.reducing(null, (a, b) -> a != null ? a : b))));
}

static Set<Entry<String, Method>> getPropertiesWithMethods(Class<?> type) {
return Stream.of(type.getMethods()).map(method -> {
var propertyName = extractProperty(method);
return propertyName == null ? null : Map.entry(propertyName, method);
}).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet());
}

static Map<Class<?>, List<Object>> getValuesByPropertyType(Stream<Entry<String, Method>> propertiesWithMethods,
Map<String, Object> concretePropertyValues) {
return propertiesWithMethods.collect(Collectors.groupingBy(property -> property.getValue().getReturnType(),
Expand Down

0 comments on commit d6f7bdc

Please sign in to comment.