@@ -0,0 +1,884 @@
+%0Apackage net.restlesscoder.sandbox;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Apublic class CollectionReferenceRecursion %7B%0A%0A%09public static void main(final String... args) %7B%0A%09%09final List%3CObject%3E l1 = new ArrayList%3C%3E(Arrays.asList(1, 2, 3));%0A%09%09final List%3CObject%3E l2 = new ArrayList%3C%3E(Arrays.asList(4, 5, 6));%0A%0A%09%09System.out.println(%22-- BEFORE --%22);%0A%09%09System.out.println(%22l1 = %22 + l1);%0A%09%09System.out.println(%22l2 = %22 + l2);%0A%0A%09%09// Java is OK when a collection contains itself directly.%0A%09%09l1.add(l1);%0A%09%09l2.add(l2);%0A%09%09System.out.println(%22-- DIRECT-REFERENCED --%22);%0A%09%09System.out.println(%22l1 = %22 + l1);%0A%09%09System.out.println(%22l2 = %22 + l2);%0A%0A%09%09// But Java fails when a collection contains itself indirectly.%0A%09%09l1.add(l2);%0A%09%09l2.add(l1);%0A%09%09System.out.println(%22-- CROSS-REFERENCED --%22);%0A%09%09System.out.println(%22l1 = %22 + l1);%0A%09%09System.out.println(%22l2 = %22 + l2);%0A%09%7D%0A%0A%7D%0A

Add a collections infinite recursion bug