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