Skip to content

Commit

Permalink
NIFI-14178 Applied PMD EmptyCatchBlock and corrected violations (#9665)
Browse files Browse the repository at this point in the history
Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
dan-s1 authored Jan 24, 2025
1 parent 584323b commit 583c4ec
Show file tree
Hide file tree
Showing 116 changed files with 298 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void cleanUpAfterEach() {
for (Path operationId : directoryStream) {
FileUtils.deleteDirectory(operationId.toFile());
}
} catch (Exception ignore) {
} catch (Exception ignored) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void stop() {
try {
scheduledExecutorService.shutdown();
scheduledExecutorService.awaitTermination(termination_wait, TimeUnit.MILLISECONDS);
} catch (InterruptedException ignore) {
} catch (InterruptedException ignored) {
// Shutting down anyway
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static <T> Optional<T> retry(Supplier<T> input, Predicate<T> predicate,
retries++;
try {
Thread.sleep(pauseDurationMillis);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static class BootstrapCommunicatorStub implements BootstrapCommunicator, Runnabl
public void run() {
try {
sleep(waitBeforeAcknowledgeMs);
} catch (InterruptedException ignore) {
} catch (InterruptedException ignored) {
}
handler.accept(callbackResult, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static void cleanUpAfterAll() {
for (Path tmpFile : directoryStream) {
Files.deleteIfExists(tmpFile);
}
} catch (Exception ignore) {
} catch (Exception ignored) {
}
}

Expand All @@ -113,7 +113,7 @@ public void testAddingNewItems() {
c2Items.forEach(resourceItem -> {
try {
when(mockResourceRepository.addResourceItem(eq(resourceItem), any())).thenReturn(Optional.of(resourceItem));
} catch (Exception e) {
} catch (Exception ignored) {
}
});

Expand All @@ -123,7 +123,7 @@ public void testAddingNewItems() {
assertEquals(FULLY_APPLIED, resultState);
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -141,7 +141,7 @@ public void testAddingNewItemWhenBinaryPresent() {
assertEquals(FULLY_APPLIED, resultState);
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -156,7 +156,7 @@ public void testAddingNewItemsSuccessWithValidResourcePath(String validResourceP
c2Items.forEach(resourceItem -> {
try {
when(mockResourceRepository.addResourceItem(eq(resourceItem), any())).thenReturn(Optional.of(resourceItem));
} catch (Exception e) {
} catch (Exception ignored) {
}
});

Expand All @@ -166,7 +166,7 @@ public void testAddingNewItemsSuccessWithValidResourcePath(String validResourceP
assertEquals(FULLY_APPLIED, resultState);
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -188,7 +188,7 @@ public void testAddingNewItemFailureWhenTypeIsAssetAndPathIsInvalid(String inval
verify(mockResourceRepository, never()).addResourceItem(any());
verify(mockResourceRepository, never()).addResourceItem(any(), any());
verify(mockResourceRepository, never()).saveResourcesGlobalHash(C2_GLOBAL_HASH);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -206,7 +206,7 @@ public void testAddingNewItemFailureDueToIssueWithUrlEnrichment() {
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
verify(mockResourceRepository, never()).saveResourcesGlobalHash(C2_GLOBAL_HASH);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -224,7 +224,7 @@ public void testAddingNewItemFailureDueToIssueInDownloadFunction() {
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
verify(mockResourceRepository, never()).saveResourcesGlobalHash(C2_GLOBAL_HASH);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -245,7 +245,7 @@ public void testAddingNewItemFailureDueToIssueInPersistFunction() {
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
verify(mockResourceRepository, never()).saveResourcesGlobalHash(C2_GLOBAL_HASH);
} catch (Exception e) {
} catch (Exception ignored) {
}
}
}
Expand All @@ -257,7 +257,7 @@ public void testAddingNewItemFailureDueToIssueWhenUpdatingRepository() {
when(mockResourceRepository.findAllResourceItems()).thenReturn(List.of());
try {
when(mockResourceRepository.addResourceItem(resourceItem)).thenThrow(Exception.class);
} catch (Exception e) {
} catch (Exception ignored) {
}

OperationState resultState =
Expand All @@ -267,7 +267,7 @@ public void testAddingNewItemFailureDueToIssueWhenUpdatingRepository() {
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
verify(mockResourceRepository, never()).saveResourcesGlobalHash(C2_GLOBAL_HASH);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -284,7 +284,7 @@ public void testDeletingAllItems() {
agentItems.forEach(agentItem -> {
try {
when(mockResourceRepository.deleteResourceItem(agentItem)).thenReturn(Optional.of(agentItem));
} catch (Exception e) {
} catch (Exception ignored) {
}
});

Expand All @@ -294,7 +294,7 @@ public void testDeletingAllItems() {
assertEquals(FULLY_APPLIED, resultState);
try {
verify(mockResourceRepository, never()).addResourceItem(any());
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -308,7 +308,7 @@ public void testDeleteFailureDueToIssueWithUpdatingRepository() {
agentItems.forEach(agentItem -> {
try {
when(mockResourceRepository.deleteResourceItem(agentItem)).thenThrow(Exception.class);
} catch (Exception e) {
} catch (Exception ignored) {
}
});

Expand All @@ -319,7 +319,7 @@ public void testDeleteFailureDueToIssueWithUpdatingRepository() {
try {
verify(mockResourceRepository, never()).addResourceItem(any());
verify(mockResourceRepository, never()).saveResourcesGlobalHash(C2_GLOBAL_HASH);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand All @@ -330,7 +330,7 @@ public void testAddFileSuccessfulButUpdateGlobalHashFails() {
try {
when(mockResourceRepository.addResourceItem(eq(c2Item), any())).thenReturn(Optional.of(c2Item));
when(mockResourceRepository.saveResourcesGlobalHash(C2_GLOBAL_HASH)).thenThrow(Exception.class);
} catch (Exception e) {
} catch (Exception ignored) {
}

OperationState resultState =
Expand All @@ -339,7 +339,7 @@ public void testAddFileSuccessfulButUpdateGlobalHashFails() {
assertEquals(PARTIALLY_APPLIED, resultState);
try {
verify(mockResourceRepository, never()).deleteResourceItem(any());
} catch (Exception e) {
} catch (Exception ignored) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void stop() {

try {
serverSocket.close();
} catch (IOException ioe) {
} catch (IOException ignored) {
// nothing to really do here. we could log this, but it would just become
// confusing in the logs, as we're shutting down and there's no real benefit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public Integer getPort() {
Integer port = null;
try {
port = Integer.parseInt(getProperty(WEB_HTTP_PORT));
} catch (NumberFormatException nfe) {
} catch (NumberFormatException ignored) {
}
return port;
}
Expand All @@ -667,7 +667,7 @@ public Integer getSslPort() {
Integer sslPort = null;
try {
sslPort = Integer.parseInt(getProperty(WEB_HTTPS_PORT));
} catch (NumberFormatException nfe) {
} catch (NumberFormatException ignored) {
}
return sslPort;
}
Expand Down Expand Up @@ -1858,10 +1858,7 @@ private static void readFromPropertiesFile(String propertiesFilePath, Properties
if (null != inStream) {
try {
inStream.close();
} catch (final Exception ex) {
/**
* do nothing *
*/
} catch (final Exception ignored) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public EndpointConnection getEndpointConnection(final TransferDirection directio
peerSelector.penalize(peer, penalizationMillis);
try {
peer.close();
} catch (final IOException ioe) {
} catch (final IOException ignored) {
}

continue;
Expand Down Expand Up @@ -296,7 +296,7 @@ public EndpointConnection getEndpointConnection(final TransferDirection directio
if (commsSession != null) {
try {
commsSession.close();
} catch (final IOException ioe) {
} catch (final IOException ignored) {
}
}

Expand Down Expand Up @@ -342,7 +342,7 @@ private void cleanup(final SocketClientProtocol protocol, final Peer peer) {
} catch (final TransmissionDisabledException e) {
// User disabled transmission.... do nothing.
logger.debug("{} Transmission Disabled by User", this);
} catch (IOException e1) {
} catch (IOException ignored) {
}
}

Expand All @@ -352,7 +352,7 @@ private void cleanup(final SocketClientProtocol protocol, final Peer peer) {
} catch (final TransmissionDisabledException e) {
// User disabled transmission.... do nothing.
logger.debug("{} Transmission Disabled by User", this);
} catch (IOException e1) {
} catch (IOException ignored) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void close() {
// 2 seconds, it is because the Runnable thread is blocking on a write; in this case,
// we will just ignore it and return
executorService.awaitTermination(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ public void run() {
final Response response = new Response(e);
responseQueue.put(response);
}
} catch (InterruptedException e) {
} catch (InterruptedException ignored) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public static void closeQuietly(final Closeable closeable) {
if (null != closeable) {
try {
closeable.close();
} catch (final IOException io) {
/*IGNORE*/
} catch (final IOException ignored) {
}
}
}
Expand All @@ -70,8 +69,7 @@ public static void releaseQuietly(final FileLock lock) {
if (null != lock) {
try {
lock.release();
} catch (final IOException io) {
/*IGNORE*/
} catch (final IOException ignored) {
}
}
}
Expand Down Expand Up @@ -508,8 +506,7 @@ public static void renameFile(final File source, final File destination, final i
public static void sleepQuietly(final long millis) {
try {
Thread.sleep(millis);
} catch (final InterruptedException ex) {
/* do nothing */
} catch (final InterruptedException ignored) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public ByteArrayOutputStream getByteArrayOutputStream() {
if (count.getAndIncrement() == 1) {
try {
Thread.sleep(1000L);
} catch (final InterruptedException ie) {
} catch (final InterruptedException ignored) {
}
}

Expand Down Expand Up @@ -505,7 +505,7 @@ protected void poison(final Throwable t) {
if (count.getAndIncrement() == 0) { // it is only important that we sleep the first time. If we sleep every time, it just slows the test down.
try {
Thread.sleep(3000L);
} catch (InterruptedException ignore) {
} catch (InterruptedException ignored) {
}
}

Expand All @@ -524,15 +524,15 @@ protected void poison(final Throwable t) {
final Thread t1 = new Thread(() -> {
try {
journal.update(Collections.singleton(firstRecord), key -> null);
} catch (final IOException ignore) {
} catch (final IOException ignored) {
}
});


final Thread t2 = new Thread(() -> {
try {
journal.update(Collections.singleton(secondRecord), key -> firstRecord);
} catch (final IOException ignore) {
} catch (final IOException ignored) {
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
while (reader.nextBlock() != null) {
recordCount += reader.getBlockCount();
}
} catch (NoSuchElementException e) {
} catch (NoSuchElementException ignored) {
// happens at end of file
}
avroMetadata.put(ITEM_COUNT_ATTR, String.valueOf(recordCount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private void checkBareRecordsSplitSize(final List<MockFlowFile> flowFiles, final
count++;
record = reader.read(record, decoder);
}
} catch (EOFException eof) {
} catch (EOFException ignored) {
// expected
}
assertEquals(expectedRecordsPerSplit, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
int available = 0;
try {
available = in.available();
} catch (IOException e) {
} catch (IOException ignored) {
// in case of the last part, the stream is already closed
}
getLogger().info("Success uploading part flowfile={} part={} available={} etag={} uploadId={}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void validateClob(String someClob) throws SQLException, ClassNotFoundExc

try {
st.executeUpdate(dropTable);
} catch (final Exception e) {
} catch (final Exception ignored) {
// table may not exist, this is not serious problem.
}

Expand Down
Loading

0 comments on commit 583c4ec

Please sign in to comment.