Skip to content

Commit

Permalink
Merge pull request #163 from jglick/ObjectInfo
Browse files Browse the repository at this point in the history
More informative `ObjectInfo`
  • Loading branch information
dmlloyd authored Feb 25, 2025
2 parents c0f5437 + 11e6b02 commit 5aa4cf6
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions api/src/main/java/org/jboss/marshalling/TraceInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ public static void addFieldInformation(Throwable t, SerializableClass owner, Ser
*/
public static void addObjectInformation(Throwable t, Object targetObject) {
final TraceInformation ti = getOrAddTraceInformation(t);
final String targetClassName = getNiceClassName(targetObject.getClass());
int targetHashCode = 0;
String toString;
try {
targetHashCode = targetObject.hashCode();
} catch (Throwable ignored) {
// guess we won't know the hash code!
toString = targetObject.toString();
} catch (Throwable error) {
toString = targetObject.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(targetObject)) + " [" + error + "]";
}
final Info oldInfo = ti.info;
ti.info = new ObjectInfo(oldInfo, targetClassName, targetHashCode);
ti.info = new ObjectInfo(oldInfo, toString);
}

/**
Expand Down Expand Up @@ -244,26 +243,20 @@ public static final class ObjectInfo extends Info implements Serializable {

private static final long serialVersionUID = -8580895864558204394L;

private final String targetClassName;
private final int targetHashCode;
private final String toString;

ObjectInfo(final Info cause, final String targetClassName, final int targetHashCode) {
ObjectInfo(final Info cause, final String toString) {
super(cause);
this.targetClassName = targetClassName;
this.targetHashCode = targetHashCode;
}

public String getTargetClassName() {
return targetClassName;
this.toString = toString;
}

public int getTargetHashCode() {
return targetHashCode;
public String getToString() {
return toString;
}

protected void toString(final StringBuilder builder) {
super.toString(builder);
builder.append("\n\tin object ").append(targetClassName).append('@').append(Integer.toHexString(targetHashCode));
builder.append("\n\tin object ").append(toString);
}
}

Expand Down

0 comments on commit 5aa4cf6

Please sign in to comment.