Fix StackOverflowError and map exceptions in Browse Beans

This commit is contained in:
Alex Osborne
2024-11-24 20:30:16 +09:00
parent 6de204c53c
commit a02a339830
@@ -91,6 +91,7 @@ public abstract class JobRelatedResource extends BaseResource {
if (obj == null
|| (obj instanceof Optional && !((Optional<?>) obj).isPresent())
|| obj instanceof Class
|| obj instanceof Logger
|| alreadyWritten.contains(obj)
|| obj.getClass().getName().startsWith("org.springframework.")) {
return;
@@ -235,7 +236,8 @@ public abstract class JobRelatedResource extends BaseResource {
info.put("propValue", null);
return info;
}
if (object instanceof String || BeanUtils.isSimpleValueType(object.getClass()) || object instanceof File) {
if (object instanceof String || BeanUtils.isSimpleValueType(object.getClass()) || object instanceof File ||
object instanceof Logger) {
info.put("class", object.getClass().getName());
info.put("propValue", object);
return info;
@@ -256,24 +258,6 @@ public abstract class JobRelatedResource extends BaseResource {
info.put("class", object.getClass().getName());
Collection<Object> properties = new LinkedList<Object>();
BeanWrapperImpl bwrap = new BeanWrapperImpl(object);
for (PropertyDescriptor pd : getPropertyDescriptors(bwrap)) {
if (pd.getReadMethod() != null && !pd.isHidden()) {
String propName = pd.getName();
if (beanPath != null) {
beanPathPrefix = beanPath + ".";
}
Object propValue = makePresentableMapFor(propName,
bwrap.getPropertyValue(propName),
alreadyWritten, beanPathPrefix);
properties.add(propValue);
}
}
if (properties.size() > 0) {
info.put("properties", properties);
}
Collection<Object> propValues = new LinkedList<Object>();
if(object.getClass().isArray()) {
// TODO: may want a special handling for an array of
@@ -287,8 +271,7 @@ public abstract class JobRelatedResource extends BaseResource {
propValues.add(makePresentableMapFor(i + "", Array.get(object, i),
alreadyWritten, beanPathPrefix));
}
}
if (object instanceof List<?>) {
} else if (object instanceof List<?>) {
List<?> list = (List<?>) object;
for (int i = 0; i < list.size(); i++) {
if (beanPath != null) {
@@ -302,13 +285,7 @@ public abstract class JobRelatedResource extends BaseResource {
LOGGER.warning(list + ".get(" + i + ") -" + e);
}
}
} else if (object instanceof Iterable<?>) {
for (Object next : (Iterable<?>) object) {
propValues.add(makePresentableMapFor("#", next, alreadyWritten,
beanPathPrefix));
}
}
if (object instanceof Map<?,?>) {
} else if (object instanceof Map<?,?>) {
for (Object next : ((Map<?,?>) object).entrySet()) {
// TODO: protect against giant maps?
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) next;
@@ -318,8 +295,32 @@ public abstract class JobRelatedResource extends BaseResource {
propValues.add(makePresentableMapFor(entry.getKey().toString(),
entry.getValue(), alreadyWritten, beanPathPrefix));
}
} else if (object instanceof Iterable<?>) {
for (Object next : (Iterable<?>) object) {
propValues.add(makePresentableMapFor("#", next, alreadyWritten,
beanPathPrefix));
}
} else {
BeanWrapperImpl bwrap = new BeanWrapperImpl(object);
for (PropertyDescriptor pd : getPropertyDescriptors(bwrap)) {
if (pd.getReadMethod() != null && !pd.isHidden()) {
String propName = pd.getName();
if (beanPath != null) {
beanPathPrefix = beanPath + ".";
}
Object propValue = makePresentableMapFor(propName,
bwrap.getPropertyValue(propName),
alreadyWritten, beanPathPrefix);
properties.add(propValue);
}
}
}
if (propValues.size() > 0) {
if (!properties.isEmpty()) {
info.put("properties", properties);
}
if (!propValues.isEmpty()) {
info.put("propValue", propValues);
}