@GuardedBy annotations.

parent 8c25732d
Pipeline #3006 passed with stage
in 9 minutes and 5 seconds
......@@ -14,6 +14,7 @@ import java.io.File;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.inject.Inject;
import static java.util.logging.Logger.getLogger;
......@@ -39,7 +40,7 @@ class AndroidAccountManager extends AccountManagerImpl
appContext = app.getApplicationContext();
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
@Override
@Nullable
protected String loadEncryptedDatabaseKey() {
......@@ -49,7 +50,7 @@ class AndroidAccountManager extends AccountManagerImpl
return key;
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
@Nullable
private String getDatabaseKeyFromPreferences() {
String key = prefs.getString(PREF_DB_KEY, null);
......@@ -58,7 +59,7 @@ class AndroidAccountManager extends AccountManagerImpl
return key;
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
private void migrateDatabaseKeyToFile(String key) {
if (storeEncryptedDatabaseKey(key)) {
if (prefs.edit().remove(PREF_DB_KEY).commit())
......@@ -83,7 +84,7 @@ class AndroidAccountManager extends AccountManagerImpl
return PreferenceManager.getDefaultSharedPreferences(appContext);
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
private void deleteAppData(SharedPreferences... clear) {
// Clear and commit shared preferences
for (SharedPreferences prefs : clear) {
......
......@@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
......@@ -37,10 +38,12 @@ public class RenewableWakeLock {
private final Runnable renewTask;
private final Object lock = new Object();
@GuardedBy("lock")
@Nullable
private PowerManager.WakeLock wakeLock; // Locking: lock
private PowerManager.WakeLock wakeLock;
@GuardedBy("lock")
@Nullable
private ScheduledFuture future; // Locking: lock
private ScheduledFuture future;
public RenewableWakeLock(PowerManager powerManager,
ScheduledExecutorService scheduler, int levelAndFlags, String tag,
......
......@@ -17,6 +17,7 @@ import java.io.InputStreamReader;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.inject.Inject;
import static java.util.logging.Level.WARNING;
......@@ -67,7 +68,7 @@ class AccountManagerImpl implements AccountManager {
return databaseKey;
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
@Nullable
protected String loadEncryptedDatabaseKey() {
String key = readDbKeyFromFile(dbKeyFile);
......@@ -82,7 +83,7 @@ class AccountManagerImpl implements AccountManager {
return key;
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
@Nullable
private String readDbKeyFromFile(File f) {
if (!f.exists()) {
......@@ -101,7 +102,7 @@ class AccountManagerImpl implements AccountManager {
}
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
boolean storeEncryptedDatabaseKey(String hex) {
LOG.info("Storing database key in file");
// Create the directory if necessary
......@@ -139,7 +140,7 @@ class AccountManagerImpl implements AccountManager {
}
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
private void writeDbKeyToFile(String key, File f) throws IOException {
FileOutputStream out = new FileOutputStream(f);
out.write(key.getBytes("UTF-8"));
......@@ -169,7 +170,7 @@ class AccountManagerImpl implements AccountManager {
}
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
private boolean encryptAndStoreDatabaseKey(SecretKey key, String password) {
byte[] plaintext = key.getBytes();
byte[] ciphertext = crypto.encryptWithPassword(plaintext, password);
......@@ -196,7 +197,7 @@ class AccountManagerImpl implements AccountManager {
}
}
// Locking: stateChangeLock
@GuardedBy("stateChangeLock")
@Nullable
private SecretKey loadAndDecryptDatabaseKey(String password) {
String hex = loadEncryptedDatabaseKey();
......
......@@ -52,6 +52,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import static java.lang.System.arraycopy;
import static java.sql.Types.INTEGER;
......@@ -319,11 +320,13 @@ abstract class JdbcDatabase implements Database<Connection> {
private final Clock clock;
private final DatabaseTypes dbTypes;
// Locking: connectionsLock
@GuardedBy("connectionsLock")
private final LinkedList<Connection> connections = new LinkedList<>();
private int openConnections = 0; // Locking: connectionsLock
private boolean closed = false; // Locking: connectionsLock
@GuardedBy("connectionsLock")
private int openConnections = 0;
@GuardedBy("connectionsLock")
private boolean closed = false;
protected abstract Connection createConnection() throws SQLException;
......
......@@ -36,6 +36,7 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
......@@ -59,7 +60,8 @@ class Poller implements EventListener {
private final SecureRandom random;
private final Clock clock;
private final Lock lock;
private final Map<TransportId, ScheduledPollTask> tasks; // Locking: lock
@GuardedBy("lock")
private final Map<TransportId, ScheduledPollTask> tasks;
Poller(@IoExecutor Executor ioExecutor,
@Scheduler ScheduledExecutorService scheduler,
......
......@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
......@@ -111,7 +112,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
return rotationResult;
}
// Locking: lock
@GuardedBy("lock")
private void addKeys(Collection<KeySet> keys) {
for (KeySet ks : keys) {
addKeys(ks.getKeySetId(), ks.getContactId(),
......@@ -119,7 +120,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
// Locking: lock
@GuardedBy("lock")
private void addKeys(KeySetId keySetId, ContactId contactId,
MutableTransportKeys m) {
MutableKeySet ks = new MutableKeySet(keySetId, contactId, m);
......@@ -130,7 +131,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
considerReplacingOutgoingKeys(ks);
}
// Locking: lock
@GuardedBy("lock")
private void encodeTags(KeySetId keySetId, ContactId contactId,
MutableIncomingKeys inKeys) {
for (long streamNumber : inKeys.getWindow().getUnseen()) {
......@@ -143,7 +144,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
// Locking: lock
@GuardedBy("lock")
private void considerReplacingOutgoingKeys(MutableKeySet ks) {
// Use the active outgoing keys with the highest key set ID
if (ks.getTransportKeys().getCurrentOutgoingKeys().isActive()) {
......
......@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
......@@ -45,7 +46,8 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
private final Map<String, Object> options;
private boolean initialised = false; // Locking: lock
@GuardedBy("lock")
private boolean initialised = false;
WindowsShutdownManagerImpl() {
// Use the Unicode versions of Win32 API calls
......@@ -71,7 +73,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
return new StartOnce(r);
}
// Locking: lock
@GuardedBy("lock")
private void initialise() {
if (isWindows()) {
new EventLoop().start();
......
......@@ -182,7 +182,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
}
}
// Locking: stateChange
@GuardedBy("stateChange")
private void hangUpInner() throws IOException {
ReliabilityLayer reliability;
lock.lock();
......
......@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Locale;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import static android.os.Build.VERSION.SDK_INT;
import static org.briarproject.briar.android.settings.SettingsFragment.LANGUAGE;
......@@ -17,7 +18,7 @@ import static org.briarproject.briar.android.settings.SettingsFragment.LANGUAGE;
@NotNullByDefault
public class Localizer {
// Locking: class
@GuardedBy("Localizer.class")
@Nullable
private static Localizer INSTANCE;
private final Locale systemLocale;
......
......@@ -9,6 +9,7 @@ import java.util.TimeZone;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import static java.util.Locale.US;
......@@ -18,8 +19,10 @@ import static java.util.Locale.US;
public class BriefLogFormatter extends Formatter {
private final Object lock = new Object();
private final DateFormat dateFormat; // Locking: lock
private final Date date; // Locking: lock
@GuardedBy("lock")
private final DateFormat dateFormat;
@GuardedBy("lock")
private final Date date;
public BriefLogFormatter() {
synchronized (lock) {
......
......@@ -9,6 +9,7 @@ import java.util.Queue;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
......@@ -18,7 +19,7 @@ public class CachingLogHandler extends Handler {
private static final int MAX_RECENT_RECORDS = 100;
private final Object lock = new Object();
// Locking: lock
@GuardedBy("lock")
private final Queue<LogRecord> recent = new LinkedList<>();
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment