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 (tree of types).
255d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao */
265d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaopublic class Clash4 {
275d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public static void main(String[] args) {
285d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        InvocationHandler handler = new Clash4InvocationHandler();
295d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
305d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        try {
315d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            Proxy.newProxyInstance(Clash.class.getClassLoader(),
325d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                new Class[] {
335d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface4a.class,
345d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface4aa.class,
355d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface4base.class,
365d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface4b.class,
375d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                    Interface4bb.class },
385d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao                handler);
395d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.err.println("Clash4 did not throw expected exception");
405d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        } catch (IllegalArgumentException iae) {
415d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.out.println("Clash4 threw expected exception");
425d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            //System.out.println(iae);
435d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        }
445d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
455d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
465d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
475d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R4base { int mBlah;  }
485d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R4a extends R4base { int mBlah_a;  }
495d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R4aa extends R4a { int mBlah_aa;  }
505d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R4b extends R4base { int mBlah_b;  }
515d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass R4bb extends R4b { int mBlah_bb;  }
525d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
535d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface4base {
545d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R4base thisIsTrouble();
555d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
565d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
575d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface4a {
585d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R4a thisIsTrouble();
595d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
605d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface4aa {
615d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R4aa thisIsTrouble();
625d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
635d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface4b {
645d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R4b thisIsTrouble();
655d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
665d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaointerface Interface4bb {
675d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public R4bb thisIsTrouble();
685d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
695d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
705d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass Clash4InvocationHandler implements InvocationHandler {
715d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    /* don't really need to do anything -- should never get this far */
725d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public Object invoke(Object proxy, Method method, Object[] args)
735d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        throws Throwable {
745d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
755d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        return null;
765d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
775d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
78