Summary: Should stop us from reporting on benign races of fields that are caching resources. Reviewed By: peterogithub Differential Revision: D4538037 fbshipit-source-id: 15236b4master
parent
4f33ecef1e
commit
f085023aff
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.checkers;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
class MyResources extends Resources {
|
||||
|
||||
public MyResources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
|
||||
super(assets, metrics, config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public class AndroidModels {
|
||||
|
||||
Resources mResources;
|
||||
MyResources mMyResources;
|
||||
|
||||
Object mField;
|
||||
|
||||
// assume that some Resources methods are annotated with @Functional
|
||||
public void resourceMethodFunctionalOk() {
|
||||
mField = mResources.getString(0);
|
||||
}
|
||||
|
||||
// and subclasses of Resources too
|
||||
public void customResourceMethodFunctionalOk() {
|
||||
mField = mResources.getString(0);
|
||||
}
|
||||
|
||||
// but not all of them
|
||||
public void someResourceMethodsNotFunctionalBad() {
|
||||
// configuration can change whenever the device rotates
|
||||
mField = mResources.getConfiguration();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue