Summary: Catch methods annotated (transitively) as `Lockless` which acquire a lock (transitively). Reviewed By: artempyanykh Differential Revision: D17396575 fbshipit-source-id: f9f2cfc1bmaster
parent
c20bda0350
commit
3543c89c19
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.infer.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE})
|
||||||
|
|
||||||
|
// Any method, override of a method annotated @Lockless,
|
||||||
|
// or a method whose class or superclass is annotated @Lockless, may not acquire a lock
|
||||||
|
public @interface Lockless {}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.facebook.infer.annotation.Lockless;
|
||||||
|
|
||||||
|
class LocklessTests {}
|
||||||
|
|
||||||
|
interface Listener {
|
||||||
|
@Lockless
|
||||||
|
void locklessMethod();
|
||||||
|
|
||||||
|
void normalMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocklessTestsA implements Listener {
|
||||||
|
// should warn
|
||||||
|
@Override
|
||||||
|
public void locklessMethod() {
|
||||||
|
synchronized (this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no warnings here
|
||||||
|
@Override
|
||||||
|
public void normalMethod() {
|
||||||
|
synchronized (this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocklessTestsB implements Listener {
|
||||||
|
// should warn
|
||||||
|
@Lockless
|
||||||
|
@Override
|
||||||
|
public synchronized void locklessMethod() {}
|
||||||
|
|
||||||
|
// no warnings here
|
||||||
|
@Override
|
||||||
|
public synchronized void normalMethod() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocklessTestsC implements Listener {
|
||||||
|
private synchronized void takeLock() {}
|
||||||
|
|
||||||
|
// should warn
|
||||||
|
@Override
|
||||||
|
public void locklessMethod() {
|
||||||
|
takeLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// no warnings here
|
||||||
|
@Override
|
||||||
|
public synchronized void normalMethod() {}
|
||||||
|
}
|
Loading…
Reference in new issue