Skip to content
Draft
Show file tree
Hide file tree
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
19 changes: 9 additions & 10 deletions api/src/main/java/org/jboss/marshalling/TraceInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.jboss.marshalling;

import java.util.Arrays;
import org.jboss.marshalling.reflect.SerializableClass;
import org.jboss.marshalling.reflect.SerializableField;

Expand Down Expand Up @@ -59,17 +60,15 @@ private static TraceInformation getOrAddTraceInformation(Throwable t) {
if (t == null) {
throw new NullPointerException("t is null");
}
Throwable c;
while (! (t instanceof TraceInformation)) {
c = t.getCause();
if (c == null) try {
t.initCause(c = new TraceInformation());
} catch (RuntimeException e) {
// ignored
}
t = c;
var optionalTi = Arrays.stream(t.getSuppressed()).filter(TraceInformation.class::isInstance).map(TraceInformation.class::cast).findFirst();
TraceInformation ti;
if (optionalTi.isEmpty()) {
ti = new TraceInformation();
t.addSuppressed(ti);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems sensible. Did you notice if there was any test coverage for this facility?

} else {
ti = optionalTi.get();
}
return (TraceInformation) t;
return ti;
}

private static String getNiceClassName(Class<?> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ Object doReadNestedObject(final boolean unshared, final String enclosingClassNam
} catch (RuntimeException e) {
TraceInformation.addIncompleteObjectInformation(e, enclosingClassName);
throw e;
} catch (StackOverflowError e) {
throw new RuntimeException(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be calling TraceInformation.addIncompleteObjectInformation here too? I suppose it would be added by the next stack frame up?

}
}

Expand All @@ -222,6 +224,8 @@ Object doReadCollectionObject(final boolean unshared, final int idx, final int s
} catch (RuntimeException e) {
TraceInformation.addIndexInformation(e, idx, size, TraceInformation.IndexType.ELEMENT);
throw e;
} catch (StackOverflowError e) {
throw new RuntimeException(e);
}
}

Expand All @@ -237,6 +241,8 @@ Object doReadMapObject(final boolean unshared, final int idx, final int size, fi
} catch (RuntimeException e) {
TraceInformation.addIndexInformation(e, idx, size, key ? TraceInformation.IndexType.MAP_KEY : TraceInformation.IndexType.MAP_VALUE);
throw e;
} catch (StackOverflowError e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -1620,6 +1626,8 @@ protected Object doReadNewObject(final int streamClassType, final boolean unshar
TraceInformation.addIncompleteObjectInformation(e, descriptor.getType());
exceptionListener.handleUnmarshallingException(e, descriptor.getType());
throw e;
} catch (StackOverflowError e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -1988,6 +1996,8 @@ protected void readFields(final Object obj, final SerializableClassDescriptor de
TraceInformation.addFieldInformation(e, descriptor.getSerializableClass(), serializableField);
TraceInformation.addObjectInformation(e, obj);
throw e;
} catch (StackOverflowError e) {
throw new RuntimeException(e);
}
}
}
Expand Down Expand Up @@ -2042,6 +2052,8 @@ protected void discardFields(final SerializableClassDescriptor descriptor) throw
} catch (RuntimeException e) {
TraceInformation.addFieldInformation(e, descriptor.getSerializableClass(), serializableField);
throw e;
} catch (StackOverflowError e) {
throw new RuntimeException(e);
}
}
}
Expand Down