Reviewed By: sblackshear Differential Revision: D6424928 fbshipit-source-id: d3a1735master
parent
735b0b2ef7
commit
700adc2d44
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
|
||||
import com.facebook.infer.annotation.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
class DeepOwnership {
|
||||
DeepOwnership next;
|
||||
static DeepOwnership global;
|
||||
|
||||
void globalNotOwnedBad() {
|
||||
global.next = null;
|
||||
}
|
||||
|
||||
void reassignBaseToGlobalBad(){
|
||||
DeepOwnership x = new DeepOwnership();
|
||||
x = global;
|
||||
x.next = null;
|
||||
}
|
||||
|
||||
void FN_reassignPathToGlobalBad() {
|
||||
DeepOwnership x = new DeepOwnership();
|
||||
x.next = global;
|
||||
x.next.next = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void deepIntraOk(){
|
||||
DeepOwnership x = new DeepOwnership();
|
||||
x.next.next = null; // doesn't warn here
|
||||
}
|
||||
|
||||
void deepInterOk(){
|
||||
DeepOwnership x = new DeepOwnership();
|
||||
deepPrivate(x.next);
|
||||
}
|
||||
|
||||
private void deepPrivate(DeepOwnership y){
|
||||
y.next = null;
|
||||
}
|
||||
|
||||
DeepOwnership deepFromOwnedThisOk(){
|
||||
return new DeepOwnership();
|
||||
}
|
||||
|
||||
DeepOwnership arr[];
|
||||
|
||||
DeepOwnership(){
|
||||
next.next = null;
|
||||
arr[0] = null;
|
||||
}
|
||||
|
||||
private void loseOwnershipOfNext() {
|
||||
synchronized (this) {
|
||||
this.next = global;
|
||||
}
|
||||
}
|
||||
|
||||
void FN_loseOwnershipInCalleeBad() {
|
||||
DeepOwnership x = new DeepOwnership();
|
||||
x.next = new DeepOwnership();
|
||||
loseOwnershipOfNext();
|
||||
x.next.next = null; // doesn't warn here
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
|
||||
import com.facebook.infer.annotation.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
class ShallowOwnership {
|
||||
ShallowOwnership next;
|
||||
static ShallowOwnership global;
|
||||
|
||||
void globalNotOwnedBad() {
|
||||
global.next = null;
|
||||
}
|
||||
|
||||
void reassignBaseToGlobalBad(){
|
||||
ShallowOwnership x = new ShallowOwnership();
|
||||
x = global;
|
||||
x.next = null;
|
||||
}
|
||||
|
||||
void reassignPathToGlobalBad() {
|
||||
ShallowOwnership x = new ShallowOwnership();
|
||||
x.next = global;
|
||||
x.next.next = null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue