Skip to content

Commit

Permalink
Fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Feb 22, 2024
1 parent eca7f87 commit 8bd592c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/main/java/mpo/dayon/assistant/gui/Assistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ public void actionPerformed(ActionEvent ev) {
Log.error("Could not determine public IP", ex);
JOptionPane.showMessageDialog(frame, translate("ipAddress.msg2"), translate("ipAddress"),
JOptionPane.ERROR_MESSAGE);
} finally {
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
}
finally {
frame.setCursor(cursor);
}
}
Expand Down Expand Up @@ -609,6 +613,9 @@ public void actionPerformed(ActionEvent ev) {
Log.error("Could not obtain token", ex);
JOptionPane.showMessageDialog(frame, translate("token.create.error.msg"), translate("token"),
JOptionPane.ERROR_MESSAGE);
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} finally {
frame.setCursor(cursor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void receivingLoop(boolean compatibilityMode) throws NoSuchAlgorithmExce
} catch (CertificateEncodingException ex) {
Log.error(ex.getMessage());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
} finally {
closeConnections();
UPnP.closePortTCP(configuration.getPort());
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/mpo/dayon/assisted/gui/Assisted.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ private void applyConnectionSettings(ConnectionSettingsDialog connectionSettings
String connectionParams = null;
try {
connectionParams = resolveToken(tokenServerUrl, token);
} catch (IOException | InterruptedException ie){
} catch (IOException | InterruptedException ex){
Log.warn("Could not resolve token " + token);
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
}
Log.debug("Connection params " + connectionParams);
newConfiguration = extractConfiguration(connectionParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void receivingLoop() {
} catch (IOException ex) {
handleIOException(ex);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
} finally {
closeConnections();
fireOnDisconnecting();
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/mpo/dayon/common/network/NetworkEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public abstract class NetworkEngine {

protected static final String UNSUPPORTED_TYPE = "Unsupported message type [%s]!";

private final static String CLIPBOARD_DEBUG = "setClipboardContents %s";

protected NetworkSender sender; // out

protected NetworkSender fileSender; // file out
Expand Down Expand Up @@ -77,18 +79,18 @@ public void sendClipboardFiles(List<File> files, long size, String basePath) {
}

protected void setClipboardContents(String string, ClipboardOwner clipboardOwner) {
Log.debug("setClipboardContents %s", () -> string);
Log.debug(CLIPBOARD_DEBUG, () -> string);
StringSelection stringSelection = new StringSelection(string);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, clipboardOwner);
}

protected void setClipboardContents(BufferedImage image, ClipboardOwner clipboardOwner) {
Log.debug("setClipboardContents %s", () -> format("%dx%d", image.getWidth(), image.getHeight()));
Log.debug(CLIPBOARD_DEBUG, () -> format("%dx%d", image.getWidth(), image.getHeight()));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new TransferableImage(image), clipboardOwner);
}

private void setClipboardContents(List<File> files, ClipboardOwner clipboardOwner) {
Log.debug("setClipboardContents %s", () -> String.valueOf(files));
Log.debug(CLIPBOARD_DEBUG, () -> String.valueOf(files));
TransferableFiles transferableFiles = new TransferableFiles(files);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferableFiles, clipboardOwner);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/mpo/dayon/common/version/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public String getLatestRelease() {
}
} catch (IOException | InterruptedException e) {
Log.error("Exception", e);
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
}
}
return latestVersion;
Expand Down

0 comments on commit 8bd592c

Please sign in to comment.