Main.java revision fbdcfb9ea9e2a78f295834424c3f24986ea45dac
1// Copyright 2008 The Android Open Source Project
2
3import java.util.Timer;
4import java.util.TimerTask;
5
6/*
7 * Throw an exception from a finalizer and make sure it's harmless.  Under
8 * Dalvik this may also generate a warning in the log file.
9 */
10public class Main {
11    static Object waiter = new Object();
12    static volatile boolean didFinal = false;
13
14    static void createAndForget() {
15        Main main = new Main();
16    }
17
18    public static void main(String[] args) {
19        createAndForget();
20
21        System.gc();
22        System.runFinalization();
23
24        new Timer().schedule(new TimerTask() {
25                public void run() {
26                    System.out.println("Timed out, exiting");
27                    System.exit(1);
28                }
29            }, 30000);
30
31        while (!didFinal) {
32            try {
33                Thread.sleep(500);
34            } catch (InterruptedException ie) {
35                System.err.println(ie);
36            }
37        }
38
39        /* give it a chance to cause mayhem */
40        try {
41            Thread.sleep(750);
42        } catch (InterruptedException ie) {
43            System.err.println(ie);
44        }
45
46        System.out.println("done");
47    }
48
49    protected void finalize() throws Throwable {
50        System.out.println("In finalizer");
51
52        didFinal = true;
53
54        throw new InterruptedException("whee");
55    }
56}
57