/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ class Parameters { private static void syncOnParam(Object x) { synchronized (x) { } } // Next two methods will deadlock public synchronized void oneWaySyncOnParamBad(Object x) { syncOnParam(x); } public void otherWaySyncOnParamBad(Object x) { synchronized (x) { synchronized (this) { } } } private static void emulateSynchronized(Parameters self) { synchronized (self) { } } Parameters someObject; // Next two methods will deadlock public synchronized void oneWayEmulateSyncBad() { emulateSynchronized(someObject); } public void anotherWayEmulateSyncBad() { synchronized (someObject) { synchronized (this) { } } } }