• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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 import java.lang.reflect.Type;
18 
19 /**
20  * Throw a few things at the verifier, all of which are expected to pass.
21  */
22 public class Main {
main(String[] args)23     static public void main(String[] args) {
24         tryBlah(1);
25 
26         System.out.println("Zorch.");
27         System.out.println("10 == " + instanceOfTest(10));
28     }
29 
30     /*
31      * Make sure the verifier is handling type merge of arrays of
32      * references correctly.
33      */
arrayCheck1(int wanted)34     static Object[] arrayCheck1(int wanted) {
35         String[] arrayOne;
36         Integer[] arrayTwo;
37 
38         arrayOne = new String[1];
39         arrayTwo = new Integer[1];
40 
41         switch (wanted) {
42             case 0:     return arrayOne;
43             case 1:     return arrayTwo;
44             default:    return null;
45         }
46     }
47 
arrayCheck1b(int wanted)48     static Object arrayCheck1b(int wanted) {
49         String[] arrayOne;
50         Integer[] arrayTwo;
51         int[] arrayThree;
52 
53         arrayOne = new String[1];
54         arrayTwo = new Integer[1];
55         arrayThree = new int[1];
56 
57         switch (wanted) {
58             case 0:     return arrayOne;
59             case 1:     return arrayTwo;
60             case 2:     return arrayThree;
61             default:    return null;
62         }
63     }
64 
arrayCheck2(int wanted)65     static Object[] arrayCheck2(int wanted) {
66         String[][] arrayOne;
67         String[][] arrayTwo;
68         Integer[][] arrayThree;
69 
70         arrayOne = new String[1][];
71         arrayTwo = new String[1][];
72         arrayThree = new Integer[1][];
73 
74         switch (wanted) {
75             case 0:     return arrayOne;
76             case 1:     return arrayTwo;
77             case 2:     return arrayThree;
78             default:    return null;
79         }
80     }
81 
arrayCheck3(int wanted)82     static Object[] arrayCheck3(int wanted) {
83         String[][] arrayTwo;
84         String[][][][] arrayFour;
85 
86         arrayTwo = new String[1][];
87         arrayFour = new String[1][][][];
88 
89         switch (wanted) {
90             case 0:     return arrayTwo;
91             case 1:     return arrayFour;
92             default:    return null;
93         }
94     }
95 
96     /*
97      * Check return type merge.
98      */
typeTest()99     private Type[] typeTest() {
100         if(this == null) {
101             return (Class<?>[])null;
102         }
103         return (Type[])null;
104     }
105 
106 
107     /*
108      * Exercise the blahs.
109      */
tryBlah(int num)110     static void tryBlah(int num) {
111         BlahFeature feature = null;     // interface ref
112 
113         switch (num) {
114             case 1:
115                 feature = new BlahOne();
116                 break;
117             default:
118                 feature = new BlahTwo();
119                 break;
120         }
121 
122         feature.doStuff();
123     }
124 
instanceOfTest(Integer x)125     static int instanceOfTest(Integer x) {
126       Object y = x;
127       if (y instanceof String) {
128         // Bug: 15808277
129         // Non-sensical instance-of to check merging after the branch doesn't result in a verifier
130         // error.
131         ((String)y).charAt(0);
132       }
133       return x.intValue();
134     }
135 }
136