From b0d13d51b19c63bb66fe47d2cc93fade568750a7 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Mon, 21 Apr 2014 23:04:33 -0700 Subject: [PATCH] 1.0.24 - Circumventing deadlock during "Re-rip All" #22 Reproducing bug showed cross-thread UI manipulation. Added thread-safety to two commonly-called events: 1) beginning of rip -> pack() on main JFrame 2) updating of rip status -> Appending text to log text box --- pom.xml | 2 +- .../java/com/rarchives/ripme/ui/MainWindow.java | 15 +++++++++++---- .../java/com/rarchives/ripme/ui/UpdateUtils.java | 2 +- .../tst/ripper/rippers/InstagramRipperTest.java | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 0e278ef6..70c3d145 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.23 + 1.0.24 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 22c91916..01b363f3 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -419,6 +419,9 @@ public class MainWindow implements Runnable, RipStatusHandler { historyList.clearSelection(); historyList.setSelectedIndex(i); Thread t = ripAlbum( (String) historyListModel.get(i) ); + if (t == null) { + continue; + } try { synchronized (t) { t.wait(); @@ -562,7 +565,9 @@ public class MainWindow implements Runnable, RipStatusHandler { StyleConstants.setForeground(sas, color); StyledDocument sd = logText.getStyledDocument(); try { - sd.insertString(sd.getLength(), text + "\n", sas); + synchronized (this) { + sd.insertString(sd.getLength(), text + "\n", sas); + } } catch (BadLocationException e) { } logText.setCaretPosition(sd.getLength()); @@ -579,7 +584,7 @@ public class MainWindow implements Runnable, RipStatusHandler { } private Thread ripAlbum(String urlString) { - shutdownCleanup(); + //shutdownCleanup(); if (!logPanel.isVisible()) { optionLog.doClick(); } @@ -603,7 +608,9 @@ public class MainWindow implements Runnable, RipStatusHandler { statusProgress.setValue(100); openButton.setVisible(false); statusLabel.setVisible(true); - mainFrame.pack(); + synchronized (this) { + mainFrame.pack(); + } boolean failed = false; try { ripper = AbstractRipper.getRipper(url); @@ -664,7 +671,7 @@ public class MainWindow implements Runnable, RipStatusHandler { } } - private void handleEvent(StatusEvent evt) { + private synchronized void handleEvent(StatusEvent evt) { if (ripper.isStopped()) { return; } diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 8d935ae4..3773a653 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -19,7 +19,7 @@ import org.jsoup.nodes.Document; public class UpdateUtils { private static final Logger logger = Logger.getLogger(UpdateUtils.class); - private static final String DEFAULT_VERSION = "1.0.23"; + private static final String DEFAULT_VERSION = "1.0.24"; private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String mainFileName = "ripme.jar"; diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java index c45383e2..77ef6e59 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/InstagramRipperTest.java @@ -16,6 +16,7 @@ public class InstagramRipperTest extends RippersTest { testURLs.put(new URL("http://instagram.com/Test_User"), "Test_User"); testURLs.put(new URL("http://instagram.com/_test_user_"), "_test_user_"); testURLs.put(new URL("http://instagram.com/-test-user-"), "-test-user-"); + testURLs.put(new URL("http://statigr.am/username"), "username"); for (URL url : testURLs.keySet()) { InstagramRipper ripper = new InstagramRipper(url); assertEquals(testURLs.get(url), ripper.getGID(ripper.getURL()));