01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.drlvm.tests.regression.h2259;
19:
20: import junit.framework.TestCase;
21:
22: import java.lang.reflect.InvocationHandler;
23: import java.lang.reflect.Method;
24: import java.lang.reflect.Proxy;
25: import java.lang.reflect.UndeclaredThrowableException;
26:
27: interface I1 {
28: String string(String s) throws ParentException;
29: }
30:
31: interface I2 {
32: String string(String s) throws SubException;
33: }
34:
35: class ParentException extends Exception {
36: }
37:
38: class SubException extends ParentException {
39: }
40:
41: public class H2259 extends TestCase {
42:
43: /*
44: * When multiple interfaces define the same method, the list of thrown
45: * exceptions are those which can be mapped to another exception in the
46: * other method:
47: *
48: * String foo(String s) throws SubException, LinkageError;
49: *
50: * UndeclaredThrowableException wrappers any checked exception which is not
51: * in the merged list. So ParentException would be wrapped, BUT LinkageError
52: * would not be since its not an Error/RuntimeException.
53: *
54: * interface I1 { String foo(String s) throws ParentException, LinkageError; }
55: * interface I2 { String foo(String s) throws SubException, Error; }
56: */
57:
58: public void test_H2259() {
59:
60: Object p = Proxy.newProxyInstance(I1.class.getClassLoader(),
61: new Class[] { I1.class, I2.class },
62: new InvocationHandler() {
63: public Object invoke(Object proxy, Method method,
64: Object[] args) throws Throwable {
65: throw new ArrayStoreException();
66: }
67: });
68:
69: I1 proxy = (I1) p;
70: int res = 0;
71:
72: try {
73: proxy.string("error");
74: } catch (ParentException e) { // is never thrown
75: } catch (UndeclaredThrowableException e) {
76: } catch (RuntimeException e) {
77: res = 104;
78: }
79: assertFalse("RuntimeException was not thrown", res == 0);
80: }
81: }
|