Skip to content

Commit

Permalink
Merge pull request internetarchive#95 from kngenie/patch-beanbrowser-…
Browse files Browse the repository at this point in the history
…failure

FIX corner-case of bean browser failing due to an exception from hashCode()
  • Loading branch information
nlevitt committed Oct 4, 2014
2 parents 0f1760f + 5821fe7 commit 5f7dc49
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,19 @@ protected void addPresentableNestedNames(Collection<Object> namedBeans, Object o
namedBeans = new LinkedList<Object>();
bean.put("children", namedBeans);
}

if (!alreadyWritten.contains(obj)) {
// alreadyWritten.contains() can fail on exception from hashCode()
// method. For example, ArrayList.hashCode() iterates over elements
// to compute hash. It can fail with ConcurrentModificationException.
// We need to use a set based on object identity, instead of regular
// java.util.Set which is equals-based. For now, error from contains()
// is simply ignored (assuming not written).
boolean writtenBefore = false;
try {
writtenBefore = alreadyWritten.contains(obj);
} catch (Exception ex) {
// pass
}
if (!writtenBefore) {
alreadyWritten.add(obj);

BeanWrapperImpl bwrap = new BeanWrapperImpl(obj);
Expand Down

0 comments on commit 5f7dc49

Please sign in to comment.