SHOW:
|
|
- or go back to the newest paste.
| 1 | // simpilied version of http://pastebin.com/M1LCdiA4 | |
| 2 | ||
| 3 | - | import java.util.AbstractMap.SimpleImmutableEntry; |
| 3 | + | |
| 4 | - | import java.util.Map.Entry; |
| 4 | + | |
| 5 | public class SomeClass {
| |
| 6 | ||
| 7 | public static void main(final String[] args) {
| |
| 8 | ||
| 9 | class Ref {
| |
| 10 | Object value1; | |
| 11 | - | Object value; |
| 11 | + | Object value2; |
| 12 | ||
| 13 | @Override | |
| 14 | public String toString() {
| |
| 15 | try {
| |
| 16 | - | return this.value.toString(); |
| 16 | + | return this.value1.toString() + "," + this.value2.toString(); |
| 17 | - | } catch (final StackOverflowError e) {
|
| 17 | + | } catch (final OutOfMemoryError | StackOverflowError e) {
|
| 18 | - | return "..."; |
| 18 | + | |
| 19 | return "..."; | |
| 20 | } | |
| 21 | } | |
| 22 | - | Entry<Ref, Ref> entry; |
| 22 | + | |
| 23 | final Ref ar2 = new Ref(); | |
| 24 | ar1.value1 = ar2; | |
| 25 | - | entry = new SimpleImmutableEntry<>(ar1, ar2); |
| 25 | + | ar1.value2 = ar1; |
| 26 | - | ar1.value = entry; |
| 26 | + | ar2.value1 = ar1; |
| 27 | - | ar2.value = ar1; |
| 27 | + | ar2.value2 = ar2; |
| 28 | - | // Object-graph contains loop: |
| 28 | + | // Object-graph contains loops! |
| 29 | - | // Entry[key=Entry, value=key] |
| 29 | + | |
| 30 | System.out.println(ar1.toString()); | |
| 31 | - | System.out.println(entry.toString()); |
| 31 | + | |
| 32 | e.printStackTrace(); | |
| 33 | } | |
| 34 | } | |
| 35 | } |