1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package libcore.build;
18 
19 import java.lang.Enum;
20 import java.lang.NoSuchMethodException;
21 import java.lang.reflect.Method;
22 
23 import libcore.io.IoTracker;
24 
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 import static org.junit.Assert.*;
29 
30 @RunWith(JUnit4.class)
31 public final class DuplicateBridgeMethodsTest {
32 
33     /**
34      * Checks that javac+turbine is not causing duplicate bridge methods to be inserted into
35      * subclasses (b/65645120).  Turbine doesn't generate bridge methods.  When javac
36      * compiles a subclass against a superclass that is missing bridge methods it will by
37      * default insert the missing bridge methods into the subclass.  Android's bundled javac
38      * prebuilts support a -XDskipDuplicateBridges=true flag to not insert the missing bridge
39      * methods.  If the prebuilt javac is not being used then TURBINE_ENABLED=false should be
40      * passed on the command line to make for the platform build.
41      * This test ensures that an extra bridge method did not get inserted into the
42      * libcore.io.IoTracker.Mode enum.
43      */
44     @Test
testSubclassHasNoBridgeMethod()45     public void testSubclassHasNoBridgeMethod() throws NoSuchMethodException {
46         Method method = IoTracker.Mode.class.getMethod("compareTo",
47                                                        new Class[]{java.lang.Object.class});
48         assertTrue(method.isBridge());
49         assertTrue(method.isSynthetic());
50         assertSame("Extra bridge methods found, use a javac that supports " +
51                    "-XDskipDuplicateBridges=true or set TURBINE_ENABLED=false " +
52                    "when building the platform",
53                    method.getDeclaringClass(), java.lang.Enum.class);
54     }
55 }
56