Skip to content

Commit

Permalink
Fix inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Oct 17, 2023
1 parent d51dd7a commit fc2e9bb
Show file tree
Hide file tree
Showing 27 changed files with 158 additions and 158 deletions.
28 changes: 28 additions & 0 deletions graalvm-config-dir/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,10 @@
"name":"org.bouncycastle.jcajce.provider.asymmetric.DSTU4145$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.Dilithium$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.EC$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand All @@ -1371,6 +1375,10 @@
"name":"org.bouncycastle.jcajce.provider.asymmetric.ECGOST$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.EXTERNAL$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.EdEC$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand All @@ -1379,6 +1387,10 @@
"name":"org.bouncycastle.jcajce.provider.asymmetric.ElGamal$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.Falcon$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.GM$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand All @@ -1391,10 +1403,22 @@
"name":"org.bouncycastle.jcajce.provider.asymmetric.IES$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.LMS$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.NTRU$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.RSA$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.SPHINCSPlus$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.asymmetric.X509$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand All @@ -1419,6 +1443,10 @@
"name":"org.bouncycastle.jcajce.provider.digest.Blake2s$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.digest.Blake3$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.bouncycastle.jcajce.provider.digest.DSTU7564$Mappings",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand Down
10 changes: 5 additions & 5 deletions lib/src/main/java/org/asamk/signal/manager/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static boolean isSignalClientAvailable() {

Configuration getConfiguration();

void updateConfiguration(Configuration configuration) throws IOException, NotPrimaryDeviceException;
void updateConfiguration(Configuration configuration) throws NotPrimaryDeviceException;

/**
* Update the user's profile.
Expand Down Expand Up @@ -160,11 +160,11 @@ SendMessageResults sendTypingMessage(

SendMessageResults sendReadReceipt(
RecipientIdentifier.Single sender, List<Long> messageIds
) throws IOException;
);

SendMessageResults sendViewedReceipt(
RecipientIdentifier.Single sender, List<Long> messageIds
) throws IOException;
);

SendMessageResults sendMessage(
Message message, Set<RecipientIdentifier> recipients
Expand Down Expand Up @@ -199,7 +199,7 @@ SendMessageResults sendPaymentNotificationMessage(

void setContactName(
RecipientIdentifier.Single recipient, String givenName, final String familyName
) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
) throws NotPrimaryDeviceException, UnregisteredRecipientException;

void setContactsBlocked(
Collection<RecipientIdentifier.Single> recipient, boolean blocked
Expand Down Expand Up @@ -299,7 +299,7 @@ boolean trustIdentityVerified(
InputStream retrieveAttachment(final String id) throws IOException;

@Override
void close() throws IOException;
void close();

interface ReceiveMessageHandler {

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/org/asamk/signal/manager/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public record Settings(TrustNewIdentity trustNewIdentity, boolean disableMessageSendLog) {

public static Settings DEFAULT = new Settings(TrustNewIdentity.ON_FIRST_USE, false);
public static final Settings DEFAULT = new Settings(TrustNewIdentity.ON_FIRST_USE, false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public void execute(Context context) throws Throwable {
envelopeType = messageContent.getType();
} else {
originalContent = envelope.getContent();
envelopeType = envelopeTypeToCiphertextMessageType(envelope.getType());
envelopeType = envelope.getType() == null
? CiphertextMessage.WHISPER_TYPE
: envelopeTypeToCiphertextMessageType(envelope.getType());
}

DecryptionErrorMessage decryptionErrorMessage = DecryptionErrorMessage.forOriginalMessage(originalContent,
Expand Down
44 changes: 25 additions & 19 deletions lib/src/main/java/org/asamk/signal/manager/api/MessageEnvelope.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -234,7 +235,7 @@ static Quote from(
return new Quote(quote.getId(),
addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(quote.getAuthor()))
.toApiRecipientAddress(),
Optional.ofNullable(quote.getText()),
Optional.of(quote.getText()),
quote.getMentions() == null
? List.of()
: quote.getMentions()
Expand Down Expand Up @@ -291,9 +292,9 @@ public record Attachment(
boolean isBorderless
) {

static Attachment from(SignalServiceAttachment attachment, AttachmentFileProvider fileProvider) {
if (attachment.isPointer()) {
final var a = attachment.asPointer();
static Attachment from(SignalServiceAttachment signalAttachment, AttachmentFileProvider fileProvider) {
if (signalAttachment.isPointer()) {
final var a = signalAttachment.asPointer();
final var attachmentFile = fileProvider.getFile(a);
return new Attachment(Optional.of(attachmentFile.getName()),
Optional.of(attachmentFile),
Expand All @@ -310,21 +311,26 @@ static Attachment from(SignalServiceAttachment attachment, AttachmentFileProvide
a.isGif(),
a.isBorderless());
} else {
final var a = attachment.asStream();
return new Attachment(Optional.empty(),
Optional.empty(),
a.getFileName(),
a.getContentType(),
a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
Optional.of(a.getLength()),
a.getPreview(),
Optional.empty(),
a.getCaption(),
a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
a.getVoiceNote(),
a.isGif(),
a.isBorderless());
Attachment attachment = null;
try (final var a = signalAttachment.asStream()) {
attachment = new Attachment(Optional.empty(),
Optional.empty(),
a.getFileName(),
a.getContentType(),
a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
Optional.of(a.getLength()),
a.getPreview(),
Optional.empty(),
a.getCaption(),
a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
a.getVoiceNote(),
a.isGif(),
a.isBorderless());
return attachment;
} catch (IOException e) {
return attachment;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,8 @@ private byte[] readAvatarBytes(final String avatarFile) throws IOException {
if (avatarFile == null) {
return null;
}
try (final var avatar = Utils.createStreamDetails(avatarFile).first().getStream()) {
return IOUtils.readFully(avatar);
try (final var avatar = Utils.createStreamDetails(avatarFile).first()) {
return IOUtils.readFully(avatar.getStream());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.push.ServiceId;

import java.io.IOException;
import java.util.Arrays;
import java.util.function.BiFunction;

Expand Down Expand Up @@ -112,12 +111,8 @@ private boolean trustIdentity(
}

account.getIdentityKeyStore().setIdentityTrustLevel(serviceId, identity.getIdentityKey(), trustLevel);
try {
context.getSyncHelper()
.sendVerifiedMessage(address.toSignalServiceAddress(), identity.getIdentityKey(), trustLevel);
} catch (IOException e) {
logger.warn("Failed to send verification sync message: {}", e.getMessage());
}
context.getSyncHelper()
.sendVerifiedMessage(address.toSignalServiceAddress(), identity.getIdentityKey(), trustLevel);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ public void setProfile(

if (avatar != null) {
if (avatar.isPresent()) {
final var streamDetails = Utils.createStreamDetails(avatar.get()).first();
context.getAvatarStore()
.storeProfileAvatar(account.getSelfRecipientAddress(),
outputStream -> IOUtils.copyStream(streamDetails.getStream(), outputStream));
try (final var streamDetails = Utils.createStreamDetails(avatar.get()).first()) {
context.getAvatarStore()
.storeProfileAvatar(account.getSelfRecipientAddress(),
outputStream -> IOUtils.copyStream(streamDetails.getStream(), outputStream));
}
} else {
context.getAvatarStore().deleteProfileAvatar(account.getSelfRecipientAddress());
}
Expand Down
34 changes: 19 additions & 15 deletions lib/src/main/java/org/asamk/signal/manager/helper/SyncHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.signal.libsignal.protocol.IdentityKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
Expand Down Expand Up @@ -73,8 +74,8 @@ public void requestSyncPniIdentity() {
requestSyncData(SyncMessage.Request.Type.PNI_IDENTITY);
}

public void sendSyncFetchProfileMessage() {
context.getSendHelper()
public SendMessageResult sendSyncFetchProfileMessage() {
return context.getSendHelper()
.sendSyncMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE));
}

Expand Down Expand Up @@ -193,7 +194,7 @@ public void sendContacts() throws IOException {
}
}

public void sendBlockedList() {
public SendMessageResult sendBlockedList() {
var addresses = new ArrayList<SignalServiceAddress>();
for (var record : account.getContactStore().getContacts()) {
if (record.second().isBlocked()) {
Expand All @@ -206,30 +207,33 @@ public void sendBlockedList() {
groupIds.add(record.getGroupId().serialize());
}
}
context.getSendHelper()
return context.getSendHelper()
.sendSyncMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(addresses, groupIds)));
}

public void sendVerifiedMessage(
public SendMessageResult sendVerifiedMessage(
SignalServiceAddress destination, IdentityKey identityKey, TrustLevel trustLevel
) throws IOException {
) {
var verifiedMessage = new VerifiedMessage(destination,
identityKey,
trustLevel.toVerifiedState(),
System.currentTimeMillis());
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
}

public void sendKeysMessage() {
public SendMessageResult sendKeysMessage() {
var keysMessage = new KeysMessage(Optional.ofNullable(account.getStorageKey()));
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forKeys(keysMessage));
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forKeys(keysMessage));
}

public void sendStickerOperationsMessage(List<StickerPack> installStickers, List<StickerPack> removeStickers) {
public SendMessageResult sendStickerOperationsMessage(
List<StickerPack> installStickers, List<StickerPack> removeStickers
) {
var installStickerMessages = installStickers.stream().map(s -> getStickerPackOperationMessage(s, true));
var removeStickerMessages = removeStickers.stream().map(s -> getStickerPackOperationMessage(s, false));
var stickerMessages = Stream.concat(installStickerMessages, removeStickerMessages).toList();
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(stickerMessages));
return context.getSendHelper()
.sendSyncMessage(SignalServiceSyncMessage.forStickerPackOperations(stickerMessages));
}

private static StickerPackOperationMessage getStickerPackOperationMessage(
Expand All @@ -240,13 +244,13 @@ private static StickerPackOperationMessage getStickerPackOperationMessage(
installed ? StickerPackOperationMessage.Type.INSTALL : StickerPackOperationMessage.Type.REMOVE);
}

public void sendConfigurationMessage() {
public SendMessageResult sendConfigurationMessage() {
final var config = account.getConfigurationStore();
var configurationMessage = new ConfigurationMessage(Optional.ofNullable(config.getReadReceipts()),
Optional.ofNullable(config.getUnidentifiedDeliveryIndicators()),
Optional.ofNullable(config.getTypingIndicators()),
Optional.ofNullable(config.getLinkPreviews()));
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forConfiguration(configurationMessage));
return context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forConfiguration(configurationMessage));
}

public void handleSyncDeviceGroups(final InputStream input) {
Expand Down Expand Up @@ -344,10 +348,10 @@ public void handleSyncDeviceContacts(final InputStream input) throws IOException
}
}

private void requestSyncData(final SyncMessage.Request.Type type) {
private SendMessageResult requestSyncData(final SyncMessage.Request.Type type) {
var r = new SyncMessage.Request.Builder().type(type).build();
var message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));
context.getSendHelper().sendSyncMessage(message);
return context.getSendHelper().sendSyncMessage(message);
}

private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(RecipientAddress address) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ public RegistrationManager getNewRegistrationManager(String number) throws IOExc
public void close() {
synchronized (managers) {
for (var m : new ArrayList<>(managers)) {
try {
m.close();
} catch (IOException e) {
logger.warn("Cleanup failed", e);
}
m.close();
}
managers.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final Connection getConnection() throws SQLException {
}

@Override
public void close() throws SQLException {
public void close() {
dataSource.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,7 @@ public void deleteAccountData() throws IOException {
public void close() {
synchronized (fileChannel) {
if (accountDatabase != null) {
try {
accountDatabase.close();
} catch (SQLException e) {
logger.warn("Failed to close account database: {}", e.getMessage(), e);
}
accountDatabase.close();
}
if (messageSendLogStore != null) {
messageSendLogStore.close();
Expand Down
Loading

0 comments on commit fc2e9bb

Please sign in to comment.