SHOW:
|
|
- or go back to the newest paste.
| 1 | package com.example.foo; | |
| 2 | ||
| 3 | public class SomeClass {
| |
| 4 | public static volatile SomeClass leak = null; | |
| 5 | public final byte[] data; | |
| 6 | public final String string; | |
| 7 | - | public SomeClass(final boolean tru3) {
|
| 7 | + | |
| 8 | public SomeClass() {
| |
| 9 | - | if (tru3)// always true! |
| 9 | + | |
| 10 | - | throw new RuntimeException(); |
| 10 | + | this.data = new byte[Integer.MAX_VALUE]; |
| 11 | - | // This is the only place where something is assigned to "string": |
| 11 | + | |
| 12 | } | |
| 13 | ||
| 14 | @Override | |
| 15 | public String toString() {
| |
| 16 | return this.string; | |
| 17 | } | |
| 18 | ||
| 19 | public static void main(final String[] args) throws Exception {
| |
| 20 | Object object = "nothing"; | |
| 21 | try {
| |
| 22 | object = new SomeClass(); | |
| 23 | - | object = new SomeClass(true); |
| 23 | + | } catch (final Throwable e) { }
|
| 24 | - | } catch (final Exception e) {
|
| 24 | + | |
| 25 | - | } |
| 25 | + | System.out.printf("leak = %s (%s)\n", leak, leak.getClass().getSimpleName());
|
| 26 | } | |
| 27 | } |