diff --git a/briar-android/src/org/briarproject/android/util/AndroidUtils.java b/briar-android/src/org/briarproject/android/util/AndroidUtils.java index 5fed2f5a2e3e95b34bcd027db8e486e9a9ddd456..6a0e6b9da30b31ddaabd85af3077b4b18e78589f 100644 --- a/briar-android/src/org/briarproject/android/util/AndroidUtils.java +++ b/briar-android/src/org/briarproject/android/util/AndroidUtils.java @@ -31,7 +31,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import static android.content.Context.MODE_PRIVATE; @@ -63,7 +62,7 @@ public class AndroidUtils { abis.add(Build.CPU_ABI); if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2); } - return Collections.unmodifiableList(abis); + return abis; } public static void setError(TextInputLayout til, String error, diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java index d1ba7d858208ceea83441b838ca8093d30b6bca2..f60e52bebb514e3ac016d077b7590215a1cf1356 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java @@ -40,6 +40,7 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -578,7 +579,7 @@ class DroidtoothPlugin implements DuplexPlugin { private static class DiscoveryReceiver extends BroadcastReceiver { private final CountDownLatch finished = new CountDownLatch(1); - private final List<String> addresses = new ArrayList<>(); + private final List<String> addresses = new CopyOnWriteArrayList<>(); @Override public void onReceive(Context ctx, Intent intent) { @@ -598,8 +599,9 @@ class DroidtoothPlugin implements DuplexPlugin { private List<String> waitForAddresses() throws InterruptedException { finished.await(); - Collections.shuffle(addresses); - return Collections.unmodifiableList(addresses); + List<String> shuffled = new ArrayList<>(addresses); + Collections.shuffle(shuffled); + return shuffled; } } diff --git a/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java b/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java index b593dfce74807f1b5820aa627b97fb81029a31ae..ecc5991fa3001a0fb39fad70d9f380449082f18d 100644 --- a/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java +++ b/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java @@ -396,7 +396,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, blogs.add(b); } } - return Collections.unmodifiableList(blogs); + return blogs; } @Override @@ -419,7 +419,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, } finally { db.endTransaction(txn); } - return Collections.unmodifiableList(blogs); + return blogs; } catch (FormatException e) { throw new DbException(e); } diff --git a/briar-core/src/org/briarproject/clients/ClientHelperImpl.java b/briar-core/src/org/briarproject/clients/ClientHelperImpl.java index e78e1d36f121db4b652b259c991bcc3620e42c83..7356ca1d1cd164b42d2f71b2e124a6af8b2ac561 100644 --- a/briar-core/src/org/briarproject/clients/ClientHelperImpl.java +++ b/briar-core/src/org/briarproject/clients/ClientHelperImpl.java @@ -29,7 +29,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.security.GeneralSecurityException; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -208,7 +207,7 @@ class ClientHelperImpl implements ClientHelper { new HashMap<MessageId, BdfDictionary>(raw.size()); for (Entry<MessageId, Metadata> e : raw.entrySet()) parsed.put(e.getKey(), metadataParser.parse(e.getValue())); - return Collections.unmodifiableMap(parsed); + return parsed; } @Override @@ -236,7 +235,7 @@ class ClientHelperImpl implements ClientHelper { new HashMap<MessageId, BdfDictionary>(raw.size()); for (Entry<MessageId, Metadata> e : raw.entrySet()) parsed.put(e.getKey(), metadataParser.parse(e.getValue())); - return Collections.unmodifiableMap(parsed); + return parsed; } @Override diff --git a/briar-core/src/org/briarproject/clients/MessageTreeImpl.java b/briar-core/src/org/briarproject/clients/MessageTreeImpl.java index b1cd81a5714e4ffb248ca0214a9da26f407b1efb..0ef7c230ab6bbc2fabc317a3a8df87b65e9178e4 100644 --- a/briar-core/src/org/briarproject/clients/MessageTreeImpl.java +++ b/briar-core/src/org/briarproject/clients/MessageTreeImpl.java @@ -103,7 +103,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode> for (T root : roots) { traverse(orderedList, root, 0); } - return Collections.unmodifiableList(orderedList); + return orderedList; } } diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java index 392c0b90b18a086ee7c529ffcb858ed1318e04c6..bac6f84ad019e6d3673d3c97f9efdf153a6a4466 100644 --- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java +++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java @@ -329,7 +329,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { if (ids.isEmpty()) return null; db.lowerRequestedFlag(txn, c, ids); transaction.attach(new MessagesSentEvent(c, ids)); - return Collections.unmodifiableList(messages); + return messages; } @Nullable @@ -379,7 +379,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { if (ids.isEmpty()) return null; db.lowerRequestedFlag(txn, c, ids); transaction.attach(new MessagesSentEvent(c, ids)); - return Collections.unmodifiableList(messages); + return messages; } @Override diff --git a/briar-core/src/org/briarproject/forum/ForumManagerImpl.java b/briar-core/src/org/briarproject/forum/ForumManagerImpl.java index ff88d9fdbeb7537d14f34756e577abb2a6ee3eb7..b4d7d84cba70f78f6c388ee4e6562b5d9062a8ed 100644 --- a/briar-core/src/org/briarproject/forum/ForumManagerImpl.java +++ b/briar-core/src/org/briarproject/forum/ForumManagerImpl.java @@ -199,7 +199,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager { } List<Forum> forums = new ArrayList<Forum>(); for (Group g : groups) forums.add(parseForum(g)); - return Collections.unmodifiableList(forums); + return forums; } catch (FormatException e) { throw new DbException(e); } diff --git a/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java b/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java index c7f726a985c9086ebbf11d90d1efd15e8b99df93..7b687f9355b1115893f53a5e252b659ff6fbc9be 100644 --- a/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java +++ b/briar-core/src/org/briarproject/plugins/ConnectionRegistryImpl.java @@ -42,6 +42,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry { contactCounts = new HashMap<ContactId, Integer>(); } + @Override public void registerConnection(ContactId c, TransportId t, boolean incoming) { if (LOG.isLoggable(INFO)) { @@ -76,6 +77,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry { } } + @Override public void unregisterConnection(ContactId c, TransportId t, boolean incoming) { if (LOG.isLoggable(INFO)) { @@ -112,6 +114,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry { } } + @Override public Collection<ContactId> getConnectedContacts(TransportId t) { lock.lock(); try { @@ -120,12 +123,13 @@ class ConnectionRegistryImpl implements ConnectionRegistry { List<ContactId> ids = new ArrayList<ContactId>(m.keySet()); if (LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected"); - return Collections.unmodifiableList(ids); + return ids; } finally { lock.unlock(); } } + @Override public boolean isConnected(ContactId c, TransportId t) { lock.lock(); try { @@ -136,6 +140,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry { } } + @Override public boolean isConnected(ContactId c) { lock.lock(); try { diff --git a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java index f9aa0ec1796bcb1fe041063d1558b2c881a77259..010e75da58a4ce255be62582839d619b25b3f4a4 100644 --- a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java +++ b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java @@ -156,12 +156,12 @@ class PluginManagerImpl implements PluginManager, Service { @Override public Collection<SimplexPlugin> getSimplexPlugins() { - return Collections.unmodifiableList(simplexPlugins); + return new ArrayList<SimplexPlugin>(simplexPlugins); } @Override public Collection<DuplexPlugin> getDuplexPlugins() { - return Collections.unmodifiableList(duplexPlugins); + return new ArrayList<DuplexPlugin>(duplexPlugins); } @Override @@ -169,7 +169,7 @@ class PluginManagerImpl implements PluginManager, Service { List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>(); for (DuplexPlugin d : duplexPlugins) if (d.supportsInvitations()) supported.add(d); - return Collections.unmodifiableList(supported); + return supported; } @Override @@ -177,7 +177,7 @@ class PluginManagerImpl implements PluginManager, Service { List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>(); for (DuplexPlugin d : duplexPlugins) if (d.supportsKeyAgreement()) supported.add(d); - return Collections.unmodifiableList(supported); + return supported; } private class PluginStarter implements Runnable { diff --git a/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java b/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java index 405d252b927027ce845ad401f50e93e6388b7c92..62b4be0c03b7f2626db5f4612df5e938d85d03ed 100644 --- a/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java +++ b/briar-core/src/org/briarproject/properties/TransportPropertyManagerImpl.java @@ -22,7 +22,6 @@ import org.briarproject.api.sync.Message; import org.briarproject.api.sync.MessageId; import org.briarproject.api.system.Clock; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -101,7 +100,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, } finally { db.endTransaction(txn); } - return Collections.unmodifiableMap(local); + return local; } @Override @@ -176,7 +175,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager, } finally { db.endTransaction(txn); } - return Collections.unmodifiableMap(remote); + return remote; } catch (FormatException e) { throw new DbException(e); } diff --git a/briar-core/src/org/briarproject/sharing/SharingManagerImpl.java b/briar-core/src/org/briarproject/sharing/SharingManagerImpl.java index 2768d4a7eda5e88b1640c8f0e7452820980a8535..fbb0276f2a939bdce466ea17e7ea9ec2e2d57562 100644 --- a/briar-core/src/org/briarproject/sharing/SharingManagerImpl.java +++ b/briar-core/src/org/briarproject/sharing/SharingManagerImpl.java @@ -46,7 +46,6 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -443,7 +442,8 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS @Override public Collection<SharingInvitationItem> getInvitations() throws DbException { - List<SharingInvitationItem> invitations = new ArrayList<SharingInvitationItem>(); + List<SharingInvitationItem> invitations = + new ArrayList<SharingInvitationItem>(); Transaction txn = db.startTransaction(true); try { Set<S> shareables = new HashSet<S>(); @@ -474,7 +474,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS invitations.add(invitation); } db.commitTransaction(txn); - return Collections.unmodifiableCollection(invitations); + return invitations; } catch (FormatException e) { throw new DbException(e); } finally { @@ -523,7 +523,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS } finally { db.endTransaction(txn); } - return Collections.unmodifiableList(subscribers); + return subscribers; } private List<Contact> getSharedBy(Transaction txn, GroupId g) @@ -556,7 +556,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS } finally { db.endTransaction(txn); } - return Collections.unmodifiableList(shared); + return shared; } catch (FormatException e) { throw new DbException(e); } diff --git a/briar-core/src/org/briarproject/sync/PacketReaderImpl.java b/briar-core/src/org/briarproject/sync/PacketReaderImpl.java index 4eea8831e8bce33edff90f80fefd2afbc2c45505..abe24fa6b4551a34ebc6486442bb7ebaf7c30707 100644 --- a/briar-core/src/org/briarproject/sync/PacketReaderImpl.java +++ b/briar-core/src/org/briarproject/sync/PacketReaderImpl.java @@ -15,7 +15,6 @@ import org.briarproject.util.ByteUtils; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static org.briarproject.api.sync.PacketTypes.ACK; @@ -74,19 +73,22 @@ class PacketReaderImpl implements PacketReader { state = State.BUFFER_FULL; } + @Override public boolean eof() throws IOException { if (state == State.BUFFER_EMPTY) readPacket(); if (state == State.BUFFER_EMPTY) throw new IllegalStateException(); return state == State.EOF; } + @Override public boolean hasAck() throws IOException { return !eof() && header[1] == ACK; } + @Override public Ack readAck() throws IOException { if (!hasAck()) throw new FormatException(); - return new Ack(Collections.unmodifiableList(readMessageIds())); + return new Ack(readMessageIds()); } private List<MessageId> readMessageIds() throws IOException { @@ -102,10 +104,12 @@ class PacketReaderImpl implements PacketReader { return ids; } + @Override public boolean hasMessage() throws IOException { return !eof() && header[1] == MESSAGE; } + @Override public Message readMessage() throws IOException { if (!hasMessage()) throw new FormatException(); if (payloadLength <= MESSAGE_HEADER_LENGTH) throw new FormatException(); @@ -125,21 +129,25 @@ class PacketReaderImpl implements PacketReader { return new Message(messageId, groupId, timestamp, raw); } + @Override public boolean hasOffer() throws IOException { return !eof() && header[1] == OFFER; } + @Override public Offer readOffer() throws IOException { if (!hasOffer()) throw new FormatException(); - return new Offer(Collections.unmodifiableList(readMessageIds())); + return new Offer(readMessageIds()); } + @Override public boolean hasRequest() throws IOException { return !eof() && header[1] == REQUEST; } + @Override public Request readRequest() throws IOException { if (!hasRequest()) throw new FormatException(); - return new Request(Collections.unmodifiableList(readMessageIds())); + return new Request(readMessageIds()); } } diff --git a/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java b/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java index 602d27f75e00508692237eb0b0320cebe4f38ed5..764f25f6005e59fc0f38ce768aa75b9156ddaab7 100644 --- a/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java +++ b/briar-desktop/src/org/briarproject/lifecycle/WindowsShutdownManagerImpl.java @@ -1,19 +1,5 @@ package org.briarproject.lifecycle; -import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER; -import static com.sun.jna.Library.OPTION_TYPE_MAPPER; -import static java.util.logging.Level.WARNING; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; -import java.util.logging.Logger; - -import org.briarproject.util.OsUtils; - import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.platform.win32.WinDef.HINSTANCE; @@ -28,6 +14,20 @@ import com.sun.jna.win32.StdCallLibrary.StdCallCallback; import com.sun.jna.win32.W32APIFunctionMapper; import com.sun.jna.win32.W32APITypeMapper; +import org.briarproject.util.OsUtils; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Logger; + +import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER; +import static com.sun.jna.Library.OPTION_TYPE_MAPPER; +import static java.util.logging.Level.WARNING; + class WindowsShutdownManagerImpl extends ShutdownManagerImpl { private static final Logger LOG = @@ -44,7 +44,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl { WindowsShutdownManagerImpl() { // Use the Unicode versions of Win32 API calls - Map<String, Object> m = new HashMap<String, Object>(); + Map<String, Object> m = new HashMap<>(); m.put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); m.put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); options = Collections.unmodifiableMap(m); @@ -112,6 +112,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl { User32.class, options); // Create a callback to handle the WM_QUERYENDSESSION message WindowProc proc = new WindowProc() { + @Override public LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp) { if (msg == WM_QUERYENDSESSION) { diff --git a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java index 4a463eb3eb02c5a49b12f20fdc7a56e4e943e2e8..37728666d0e34e0e995f08a3d4cf80b2eb447003 100644 --- a/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java +++ b/briar-desktop/src/org/briarproject/plugins/file/RemovableDrivePlugin.java @@ -9,7 +9,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.concurrent.Executor; import java.util.logging.Logger; @@ -114,7 +113,7 @@ implements RemovableDriveMonitor.Callback { } catch (IOException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); } - return Collections.unmodifiableList(matches); + return matches; } @Override diff --git a/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java b/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java index d5c2d76fe48ad8db04dd865cf7b5243ad148ff3c..0931f6f4434ceafaa47cf066d7876c3b813ff406 100644 --- a/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java +++ b/briar-desktop/src/org/briarproject/plugins/file/UnixRemovableDriveFinder.java @@ -3,7 +3,6 @@ package org.briarproject.plugins.file; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Scanner; @@ -13,8 +12,9 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder { protected abstract String parseMountPoint(String line); protected abstract boolean isRemovableDriveMountPoint(String path); + @Override public List<File> findRemovableDrives() throws IOException { - List<File> drives = new ArrayList<File>(); + List<File> drives = new ArrayList<>(); Process p = new ProcessBuilder(getMountCommand()).start(); Scanner s = new Scanner(p.getInputStream(), "UTF-8"); try { @@ -35,6 +35,6 @@ abstract class UnixRemovableDriveFinder implements RemovableDriveFinder { } finally { s.close(); } - return Collections.unmodifiableList(drives); + return drives; } } diff --git a/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java b/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java index cfbb1f5a59dd80c60c3214c3c33f36719ea8ef52..c67783ca8d50c2521ea83273377048a3e559768d 100644 --- a/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java +++ b/briar-desktop/src/org/briarproject/plugins/file/WindowsRemovableDriveFinder.java @@ -1,23 +1,23 @@ package org.briarproject.plugins.file; +import com.sun.jna.platform.win32.Kernel32; + import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import com.sun.jna.platform.win32.Kernel32; - class WindowsRemovableDriveFinder implements RemovableDriveFinder { // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939.aspx private static final int DRIVE_REMOVABLE = 2; + @Override public Collection<File> findRemovableDrives() throws IOException { File[] roots = File.listRoots(); if (roots == null) throw new IOException(); - List<File> drives = new ArrayList<File>(); + List<File> drives = new ArrayList<>(); for (File root : roots) { try { int type = Kernel32.INSTANCE.GetDriveType(root.getPath()); @@ -26,6 +26,6 @@ class WindowsRemovableDriveFinder implements RemovableDriveFinder { throw new IOException(e); } } - return Collections.unmodifiableList(drives); + return drives; } }