From 8fb2b039c73de086cdf6f04b0b9aa15a5a81158c Mon Sep 17 00:00:00 2001 From: dev-mlb <19797865+dev-mlb@users.noreply.github.com> Date: Thu, 30 May 2024 05:13:30 -0400 Subject: [PATCH] errorprone :: InterruptedExceptionSwallowed (#790) --- .../output/filter/AbstractRollableFilter.java | 3 +++ src/test/java/emissary/core/FTestMovingAgent.java | 4 +++- .../java/emissary/core/ResourceWatcherTest.java | 3 ++- src/test/java/emissary/core/TimedResourceTest.java | 2 +- src/test/java/emissary/kff/KffFileTest.java | 3 ++- .../output/roller/JournaledCoalescerTest.java | 14 +++++++------- .../roller/journal/JournaledChannelPoolTest.java | 4 ++-- src/test/java/emissary/roll/RollManagerTest.java | 2 +- .../java/emissary/test/core/junit5/UnitTest.java | 3 +++ .../emissary/util/io/LoggingPrintStreamTest.java | 2 +- .../emissary/util/shell/ProcessReaderTest.java | 5 +++-- 11 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/emissary/output/filter/AbstractRollableFilter.java b/src/main/java/emissary/output/filter/AbstractRollableFilter.java index f7e87b147d..7eb09b81ab 100644 --- a/src/main/java/emissary/output/filter/AbstractRollableFilter.java +++ b/src/main/java/emissary/output/filter/AbstractRollableFilter.java @@ -124,6 +124,9 @@ protected void setupRoller() { logger.info("Added Roller for {} running every {} {}(s) or on size {} (bytes).", getFilterName(), this.rollInterval, this.rollIntervalUnits, this.maxRollFileSize); } catch (Exception ex) { + if (ex instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } logger.error("Unable to instantiate Roller for handling {} file output", getFilterName(), ex); System.exit(1); } diff --git a/src/test/java/emissary/core/FTestMovingAgent.java b/src/test/java/emissary/core/FTestMovingAgent.java index e127322802..570a4d0241 100644 --- a/src/test/java/emissary/core/FTestMovingAgent.java +++ b/src/test/java/emissary/core/FTestMovingAgent.java @@ -129,7 +129,9 @@ private void runTest(@Nullable final String agentClass) { try { Thread.sleep(250); } catch (Exception ex) { - // empty catch block + if (ex instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } } waitCounter++; } diff --git a/src/test/java/emissary/core/ResourceWatcherTest.java b/src/test/java/emissary/core/ResourceWatcherTest.java index 6521a03016..15a910260d 100644 --- a/src/test/java/emissary/core/ResourceWatcherTest.java +++ b/src/test/java/emissary/core/ResourceWatcherTest.java @@ -8,6 +8,7 @@ import com.codahale.metrics.Timer; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Random; @@ -26,7 +27,7 @@ class ResourceWatcherTest extends UnitTest { public IServiceProviderPlace place = null; @Test - void testResourceWatcherWithMultipleThreads() throws Exception { + void testResourceWatcherWithMultipleThreads() throws IOException, InterruptedException { this.resourceWatcher = new ResourceWatcher(); this.place = new DevNullPlace(); int threadCount = 10; diff --git a/src/test/java/emissary/core/TimedResourceTest.java b/src/test/java/emissary/core/TimedResourceTest.java index fcf6ab37bd..602cbc0314 100644 --- a/src/test/java/emissary/core/TimedResourceTest.java +++ b/src/test/java/emissary/core/TimedResourceTest.java @@ -40,7 +40,7 @@ void testCheckState() { } @TestAttempts - void test() throws Exception { + void test() throws InterruptedException { TestMobileAgent tma = new TestMobileAgent(); // timeout almost immediately try (TimedResource tr = new TimedResource(tma, tp, 1, new Timer())) { diff --git a/src/test/java/emissary/kff/KffFileTest.java b/src/test/java/emissary/kff/KffFileTest.java index 1a13a3455d..3fcf5d003e 100644 --- a/src/test/java/emissary/kff/KffFileTest.java +++ b/src/test/java/emissary/kff/KffFileTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Random; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -90,7 +91,7 @@ void testKffFileCheck() { * Tests concurrent {@link KffFile#check(String, ChecksumResults)} invocations to ensure that method's thread-safety */ @Test - void testConcurrentKffFileCheckCalls() throws Exception { + void testConcurrentKffFileCheckCalls() throws ExecutionException, IOException, InterruptedException { int EXPECTED_FAILURE_COUNT = 200; // the inputs we'll submit, along wth their expected KffFile.check return values diff --git a/src/test/java/emissary/output/roller/JournaledCoalescerTest.java b/src/test/java/emissary/output/roller/JournaledCoalescerTest.java index e802611869..69d37716f3 100644 --- a/src/test/java/emissary/output/roller/JournaledCoalescerTest.java +++ b/src/test/java/emissary/output/roller/JournaledCoalescerTest.java @@ -56,7 +56,7 @@ class JournaledCoalescerTest extends UnitTest { private final List BUD2_LINES = Arrays.asList("Line3", "Line4"); @BeforeEach - public void setUp(@TempDir final Path tempFilesPath) throws Exception { + public void setUp(@TempDir final Path tempFilesPath) throws IOException, InterruptedException { fileNameGenerator = new SimpleFileNameGenerator(); targetBudPath = tempFilesPath; journaledCoalescer = new JournaledCoalescer(targetBudPath, fileNameGenerator); @@ -119,7 +119,7 @@ void testNonWritable() throws Exception { } @Test - void testRollOrphanedFiles() throws Exception { + void testRollOrphanedFiles() throws IOException, InterruptedException { // setup try (JournaledChannelPool pool = new JournaledChannelPool(targetBudPath, BUD1_NAME, 2); KeyedOutput one = pool.getFree(); @@ -205,7 +205,7 @@ void testAddFilesWithRoll() throws Exception { * run, which should be deleted and normal operations carried out from there. */ @Test - void testCrashWhileRolling() throws Exception { + void testCrashWhileRolling() throws IOException, InterruptedException { // setup Path finalBudOutput; try (KeyedOutput one = journaledCoalescer.getOutput()) { @@ -232,7 +232,7 @@ void testCrashWhileRolling() throws Exception { * Test to see the rolled and part files are cleaned up without rolling again. */ @Test - void testCrashAfterRolled() throws Exception { + void testCrashAfterRolled() throws IOException, InterruptedException { try (JournaledChannelPool pool = new JournaledChannelPool(targetBudPath, BUD1_NAME, 2); KeyedOutput one = pool.getFree(); KeyedOutput two = pool.getFree()) { @@ -261,7 +261,7 @@ void testCrashAfterRolled() throws Exception { * are deleted, but the rolled file is not renamed. */ @Test - void testCrashAfterRolledNoPartFiles() throws Exception { + void testCrashAfterRolledNoPartFiles() throws IOException, InterruptedException { // create the rolled file without any part/journal files Path oldRolled = Files.createFile(targetBudPath.resolve(BUD1_NAME + JournaledCoalescer.ROLLED_EXT)); Files.write(oldRolled, BUD1_LINES, StandardCharsets.UTF_8, StandardOpenOption.WRITE); @@ -274,7 +274,7 @@ void testCrashAfterRolledNoPartFiles() throws Exception { } @Test - void testCrashAfterRolledEmpty() throws Exception { + void testCrashAfterRolledEmpty() throws IOException, InterruptedException { try (JournaledChannelPool pool = new JournaledChannelPool(targetBudPath, BUD1_NAME, 2); KeyedOutput one = pool.getFree(); KeyedOutput two = pool.getFree()) { @@ -295,7 +295,7 @@ void testCrashAfterRolledEmpty() throws Exception { } @Test - void testCrashAfterRolledEmptyNoPartFiles() throws Exception { + void testCrashAfterRolledEmptyNoPartFiles() throws IOException, InterruptedException { // create the rolled file without any part/journal files Path oldRolled = Files.createFile(targetBudPath.resolve(BUD1_NAME + JournaledCoalescer.ROLLED_EXT)); diff --git a/src/test/java/emissary/output/roller/journal/JournaledChannelPoolTest.java b/src/test/java/emissary/output/roller/journal/JournaledChannelPoolTest.java index 979b4bc6d3..98bfb4e053 100644 --- a/src/test/java/emissary/output/roller/journal/JournaledChannelPoolTest.java +++ b/src/test/java/emissary/output/roller/journal/JournaledChannelPoolTest.java @@ -46,7 +46,7 @@ public void tearDown() throws Exception { * Test of freeChannel method, of class JournaledChannelPool. */ @Test - void testGetAndFree() throws Exception { + void testGetAndFree() throws IOException, InterruptedException { final SeekableByteChannel out = this.instance.getFree(); final int created = this.instance.getCreatedCount(); assertTrue(created > 0, "Should have recorded creation of at least 1 object"); @@ -60,7 +60,7 @@ void testGetAndFree() throws Exception { * Test of getJournalEntries method, of class JournaledChannelPool. */ @Test - void testGetJournalEntries() throws Exception { + void testGetJournalEntries() throws IOException, InterruptedException { final String onetext = "one line of text"; final String twotext = "two lines of text\nthe second line"; try (KeyedOutput k1 = this.instance.getFree(); KeyedOutput k2 = this.instance.getFree()) { diff --git a/src/test/java/emissary/roll/RollManagerTest.java b/src/test/java/emissary/roll/RollManagerTest.java index afff1d7131..796d564fbc 100644 --- a/src/test/java/emissary/roll/RollManagerTest.java +++ b/src/test/java/emissary/roll/RollManagerTest.java @@ -56,7 +56,7 @@ void testAutoConfig() throws IOException { } @Test - void testFailedRoller() throws Exception { + void testFailedRoller() throws IOException, InterruptedException { RollManager rm = new RollManager(ConfigUtil.getConfigInfo(this.getClass())); CountDownLatch latch = new CountDownLatch(1); Roller r = new Roller(TimeUnit.MILLISECONDS, 250, new Rollable() { diff --git a/src/test/java/emissary/test/core/junit5/UnitTest.java b/src/test/java/emissary/test/core/junit5/UnitTest.java index aa23a41f20..fdc5d5c0a5 100644 --- a/src/test/java/emissary/test/core/junit5/UnitTest.java +++ b/src/test/java/emissary/test/core/junit5/UnitTest.java @@ -177,6 +177,9 @@ protected void pause(long millis) { Thread.sleep(millis); } catch (Exception ex) { // empty exception block + if (ex instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } logger.debug("Thread interrupted", ex); } } diff --git a/src/test/java/emissary/util/io/LoggingPrintStreamTest.java b/src/test/java/emissary/util/io/LoggingPrintStreamTest.java index ecc961587e..6d15760287 100644 --- a/src/test/java/emissary/util/io/LoggingPrintStreamTest.java +++ b/src/test/java/emissary/util/io/LoggingPrintStreamTest.java @@ -237,7 +237,7 @@ void testSingleThread() { } @Test - void testMultiThread() throws Exception { + void testMultiThread() throws InterruptedException { final org.slf4j.event.Level slf4jLevel = org.slf4j.event.Level.INFO; LogbackTester logbackTester = new LogbackTester(LoggingPrintStreamTest.class.getName()); diff --git a/src/test/java/emissary/util/shell/ProcessReaderTest.java b/src/test/java/emissary/util/shell/ProcessReaderTest.java index 8e461b3195..6a07562967 100644 --- a/src/test/java/emissary/util/shell/ProcessReaderTest.java +++ b/src/test/java/emissary/util/shell/ProcessReaderTest.java @@ -14,6 +14,7 @@ import org.slf4j.MDC; import java.io.ByteArrayOutputStream; +import java.io.IOException; import javax.annotation.Nullable; import static emissary.log.MDCConstants.SERVICE_LOCATION; @@ -78,7 +79,7 @@ public void tearDown() throws Exception { * {@link ProcessReader#applyLogContextMap()} */ @Test - void testFormattedLogMessageWithMDCTransfer() throws Exception { + void testFormattedLogMessageWithMDCTransfer() throws IOException, InterruptedException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { appender.setOutputStream(outputStream); @@ -95,7 +96,7 @@ void testFormattedLogMessageWithMDCTransfer() throws Exception { } @Test - void testFormattedLogMessageWithoutMDCTransfer() throws Exception { + void testFormattedLogMessageWithoutMDCTransfer() throws IOException, InterruptedException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { appender.setOutputStream(outputStream);