1 /* 2 * Copyright (C) 2014 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 public class Main { 18 19 public static void doNothing(boolean b) { 20 System.out.println("In do nothing."); 21 } 22 23 public static void inIf() { 24 System.out.println("In if."); 25 } 26 27 public static int bar() { 28 return 42; 29 } 30 31 public static int foo1() { 32 int b = bar(); 33 doNothing(b == 42); 34 // This second `b == 42` will be GVN'ed away. 35 if (b == 42) { 36 inIf(); 37 return b; 38 } 39 return 0; 40 } 41 42 public static int foo2() { 43 int b = bar(); 44 doNothing(b == 41); 45 // This second `b == 41` will be GVN'ed away. 46 if (b == 41) { 47 inIf(); 48 return 0; 49 } 50 return b; 51 } 52 53 public static void main(String[] args) { 54 System.out.println("foo1"); 55 int res = foo1(); 56 if (res != 42) { 57 throw new Error("Unexpected return value for foo1: " + res + ", expected 42."); 58 } 59 60 System.out.println("foo2"); 61 res = foo2(); 62 if (res != 42) { 63 throw new Error("Unexpected return value for foo2: " + res + ", expected 42."); 64 } 65 } 66 } 67