ThrowableTest.java revision 4557728efb66c455a52b7669a8eefef7a9e54854
1e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes/*
2e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * Copyright (C) 2010 The Android Open Source Project
3e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes *
4e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * you may not use this file except in compliance with the License.
6e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * You may obtain a copy of the License at
7e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes *
8e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes *
10e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * See the License for the specific language governing permissions and
14e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes * limitations under the License.
15e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes */
16e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes
174557728efb66c455a52b7669a8eefef7a9e54854Jesse Wilsonpackage libcore.java.lang;
18e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes
19e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughesimport java.io.PrintWriter;
20e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughesimport java.io.StringWriter;
21e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughesimport junit.framework.TestCase;
22e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes
23e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughespublic class ThrowableTest extends TestCase {
24e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes    private static class NoStackTraceException extends Exception {
25e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes        @Override
26e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes        public synchronized Throwable fillInStackTrace() {
27e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes            return null;
28e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes        }
29e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes    }
30e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes    public void testNullStackTrace() {
31e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes        try {
32e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes            throw new NoStackTraceException();
33e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes        } catch (NoStackTraceException ex) {
34e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes            // We used to throw NullPointerException when printing an exception with no stack trace.
35e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes            ex.printStackTrace(new PrintWriter(new StringWriter()));
36e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes        }
37e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes    }
38e8ca15fac603d1adb0fd9007ea6343584a15db67Elliott Hughes}
39