Object (@Nullable Object o) { if (o != null && !(o instanceof Serializable)) { synchronized (myInstanceCache) { Object instance = myInstanceCache.get(o); if (instance == null) { final ClassLoader loader = o.getClass().getClassLoader(); final Class<?>[] interfaces = o.getClass().getInterfaces(); final EDTGuard guard = new EDTGuard(o, myQueue, myPausedRef); myInstanceCache.put(o, instance = Proxy.newProxyInstance(loader, interfaces, guard)); } return instance; } } else if (o instanceof List) { final List<Object> list = (List<Object>)o; for (int i = 0; i < list.size(); i++) { final Object e = list.remove(i); list.add(i, convert(e)); } } else if (o instanceof Set) { final Set<Object> set = (Set<Object>)o; final List<Object> s2 = new ArrayList<>(); for (Iterator<Object> iterator = set.iterator(); iterator.hasNext(); ) { Object o1 = iterator.next(); final Object o2 = convert(o1); if (o1 != o2) { iterator.remove(); s2.add(o2); } } set.addAll(s2); } return o; }