1 /* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 */ 25 package org.graalvm.compiler.jtt.except; 26 27 import org.junit.Test; 28 29 import org.graalvm.compiler.jtt.JTTTest; 30 31 public class Except_Synchronized05 extends JTTTest { 32 33 static class Foo { 34 35 Object field; 36 37 public synchronized Object bar(int arg) { 38 try { 39 String f = foo1(arg); 40 if (f == null) { 41 field = new Object(); 42 } 43 } catch (NullPointerException e) { 44 // do nothing 45 } 46 return field; 47 } 48 49 public Object baz(int arg) { 50 synchronized (this) { 51 try { 52 String f = foo1(arg); 53 if (f == null) { 54 field = new Object(); 55 } 56 } catch (NullPointerException e) { 57 // do nothing 58 } 59 return field; 60 } 61 } 62 63 @SuppressWarnings("static-method") 64 private String foo1(int arg) { 65 if (arg == 0) { 66 throw null; 67 } 68 return null; 69 } 70 71 } 72 73 public static int test(int arg) { 74 Foo obj = new Foo(); 75 int a = obj.bar(arg) != null ? 1 : 0; 76 int b = obj.baz(arg) != null ? 1 : 0; 77 return a + b; 78 } 79 80 @Test 81 public void run0() throws Throwable { 82 runTest("test", 0); 83 } 84 85 @Test 86 public void run1() throws Throwable { 87 runTest("test", 1); 88 } 89 90 }