Skip to content

Commit

Permalink
refactor: use Objects.requireNonNull instead of assert to fail faster…
Browse files Browse the repository at this point in the history
… on NullPointerException in production mode
  • Loading branch information
caro3801 committed Nov 6, 2023
1 parent c135856 commit d6007a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* AMQP memory server for embedded mode and tests.
Expand Down Expand Up @@ -36,8 +37,7 @@ public boolean shutdown() {
private Map<String, Object> createSystemConfig() {
Map<String, Object> attributes = new HashMap<>();
URL initialConfig = QpidAmqpServer.class.getClassLoader().getResource(INITIAL_CONFIGURATION);
assert initialConfig != null;
logger.info("initial config : {}", initialConfig.toExternalForm());
logger.info("initial config : {}", Objects.requireNonNull(initialConfig," initialConfig cannot be null").toExternalForm());
attributes.put("type", "Memory");
attributes.put("initialConfigurationLocation", initialConfig.toExternalForm());
attributes.put("startupLoggedToSystemOut", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -44,9 +45,9 @@ public NlpConsumer(Pipeline pipeline, Indexer indexer, BlockingQueue<Message> me
public Integer call() {
boolean exitAsked = false;
int nbMessages = 0;
Objects.requireNonNull(messageQueue,"messageQueue cannot be null");
while (! exitAsked) {
try {
assert messageQueue != null;
Message message = messageQueue.poll(30, TimeUnit.SECONDS);
if (message != null) {
switch (message.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -71,8 +72,8 @@ public void run() {
} catch (JooqBatchSearchRepository.BatchNotFoundException notFound) {
logger.warn("batch was not executed : {}", notFound.toString());
} catch (BatchSearchRunner.CancelException cancelEx) {
Objects.requireNonNull(currentBatchId,"BatchSearch Id cannot be null");
logger.info("cancelling batch search {}", currentBatchId);
assert currentBatchId != null;
batchSearchQueue.offer(currentBatchId);
repository.reset(currentBatchId);
} catch (SearchException sex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static java.lang.Boolean.parseBoolean;
Expand Down Expand Up @@ -114,8 +111,9 @@ public Payload getExtractedText(
if(offset == null && limit == null ){
extractedText = getAllExtractedText(id, targetLanguage);
}else{
assert offset != null && limit != null;
extractedText = indexer.getExtractedText(project, id, routing, offset, limit, targetLanguage);
extractedText = indexer.getExtractedText(project, id, routing,
Objects.requireNonNull(offset, "offset parameter cannot be null"),
Objects.requireNonNull(limit, "limit parameter cannot be null"), targetLanguage);
}
return new Payload(extractedText).withCode(200);
}
Expand Down

0 comments on commit d6007a8

Please sign in to comment.