15d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao/*
25d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Copyright (C) 2008 The Android Open Source Project
35d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao *
45d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Licensed under the Apache License, Version 2.0 (the "License");
55d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * you may not use this file except in compliance with the License.
65d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * You may obtain a copy of the License at
75d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao *
85d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao *      http://www.apache.org/licenses/LICENSE-2.0
95d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao *
105d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Unless required by applicable law or agreed to in writing, software
115d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * distributed under the License is distributed on an "AS IS" BASIS,
125d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * See the License for the specific language governing permissions and
145d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * limitations under the License.
155d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao */
165d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
175d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoimport java.lang.reflect.InvocationHandler;
185d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoimport java.lang.reflect.InvocationTargetException;
195d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoimport java.lang.reflect.Method;
205d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoimport java.lang.reflect.Proxy;
215d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
225d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao/*
235d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Try to instantiate a proxy class with interfaces that have conflicting
245d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * duplicate methods (type tree with interface).
255d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao */
265d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaopublic class Clash3 {
275d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public static void main(String[] args) {
285d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        InvocationHandler handler = new Clash3InvocationHandler();
295d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
305d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        try {
315d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            Proxy.newProxyInstance(Clash.class.getClassLoader(),
325d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                new Class[] {
335d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface3a.class,
345d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface3base.class,
355d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface3aa.class,
365d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface3b.class },
375d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                handler);
385d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.err.println("Clash3 did not throw expected exception");
395d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        } catch (IllegalArgumentException iae) {
405d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.out.println("Clash3 threw expected exception");
415d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        }
425d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
435d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
445d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
455d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R3base implements I3 { int mBlah; public void x() {} }
465d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R3a extends R3base { int mBlah_a;  }
475d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R3aa extends R3a { int mBlah_aa;  }
485d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R3b implements I3 { int mBlah_b; public void x() {} }
495d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
505d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface I3 {
515d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    void x();
525d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
535d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
545d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface3base {
555d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R3base thisIsTrouble();
565d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
575d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
585d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface3a {
595d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R3a thisIsTrouble();
605d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
615d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface3aa {
625d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R3aa thisIsTrouble();
635d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
645d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface3b {
655d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R3b thisIsTrouble();
665d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
675d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
685d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass Clash3InvocationHandler implements InvocationHandler {
695d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    /* don't really need to do anything -- should never get this far */
705d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public Object invoke(Object proxy, Method method, Object[] args)
715d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        throws Throwable {
725d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
735d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        return null;
745d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
755d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
76