Skip to content

Commit

Permalink
Merge pull request #624 from barspi/avoid-exceptions-ctx-dump
Browse files Browse the repository at this point in the history
Avoid exceptions when dumping ctx
  • Loading branch information
ar authored Nov 21, 2024
2 parents 82151e2 + 2d8c4d3 commit e5066cf
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions jpos/src/main/java/org/jpos/transaction/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,12 @@ public synchronized Map<Object,Object> getMap() {
}

protected void dumpMap (PrintStream p, String indent) {
if (map != null) {
Map<Object,Object> cloned;
cloned = Collections.synchronizedMap (new LinkedHashMap<>());
synchronized(map) {
cloned.putAll(map);
}
cloned.entrySet().forEach(e -> dumpEntry(p, indent, e));
Map<Object,Object> m = getMap();
Map<Object,Object> cloned = Collections.synchronizedMap (new LinkedHashMap<>());
synchronized(m) {
cloned.putAll(m);
}
cloned.entrySet().forEach(e -> dumpEntry(p, indent, e));
}

protected void dumpEntry (PrintStream p, String indent, Map.Entry<Object,Object> entry) {
Expand All @@ -298,7 +296,11 @@ protected void dumpEntry (PrintStream p, String indent, Map.Entry<Object,Object>
Object value = entry.getValue();
if (value instanceof Loggeable) {
p.println("");
((Loggeable) value).dump(p, indent + " ");
try {
((Loggeable) value).dump(p, indent + " ");
} catch (Exception ex) {
ex.printStackTrace(p);
}
p.print(indent);
} else if (value instanceof Element) {
p.println("");
Expand Down Expand Up @@ -329,10 +331,15 @@ else if (value instanceof LogEvent) {
((LogEvent) value).dump(p, indent);
p.print(indent);
} else if (value != null) {
LogUtil.dump(p, indent, value.toString());
try {
LogUtil.dump(p, indent, value.toString());
} catch (Exception ex) {
ex.printStackTrace(p);
}
}
p.println();
}

/**
* return a LogEvent used to store trace information
* about this transaction.
Expand Down Expand Up @@ -402,7 +409,7 @@ public PausedTransaction getPausedTransaction() {
public PausedTransaction getPausedTransaction(long timeout) {
return get (PAUSED_TRANSACTION.toString(), timeout);
}

public void setTimeout (long timeout) {
this.timeout = timeout;
}
Expand Down

0 comments on commit e5066cf

Please sign in to comment.