Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Critical Sonar Issues #1833

Merged
merged 5 commits into from Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -59,9 +59,12 @@
@Slf4j
public class App {

private static final String ROCKET_LAUNCH_LOG_PATTERN = "Space rocket <%s> launched successfully";

/**
* Program entry point.
*/

public static void main(String[] args) throws Exception {
// construct a new executor that will run async tasks
var executor = new ThreadAsyncExecutor();
Expand All @@ -87,9 +90,9 @@ public static void main(String[] args) throws Exception {
asyncResult5.await();

// log the results of the tasks, callbacks log immediately when complete
log("Space rocket <" + result1 + "> launch complete");
log("Space rocket <" + result2 + "> launch complete");
log("Space rocket <" + result3 + "> launch complete");
log(String.format(ROCKET_LAUNCH_LOG_PATTERN, result1));
log(String.format(ROCKET_LAUNCH_LOG_PATTERN, result2));
log(String.format(ROCKET_LAUNCH_LOG_PATTERN, result3));
}

/**
Expand All @@ -102,7 +105,7 @@ public static void main(String[] args) throws Exception {
private static <T> Callable<T> lazyval(T value, long delayMillis) {
return () -> {
Thread.sleep(delayMillis);
log("Space rocket <" + value + "> launched successfully");
log(String.format(ROCKET_LAUNCH_LOG_PATTERN, value));
return value;
};
}
Expand Down
9 changes: 5 additions & 4 deletions caching/src/main/java/com/iluwatar/caching/DbManager.java
Expand Up @@ -50,6 +50,7 @@ public final class DbManager {
private static boolean useMongoDB;

private static Map<String, UserAccount> virtualDB;
private static final String ERROR_MESSAGE_LOG = "Error connecting to MongoDB";

private DbManager() {
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public static UserAccount readFromDb(String userId) {
try {
connect();
} catch (ParseException e) {
LOGGER.error("Error connecting to MongoDB", e);
LOGGER.error(ERROR_MESSAGE_LOG, e);
}
}
var iterable = db
Expand All @@ -112,7 +113,7 @@ public static void writeToDb(UserAccount userAccount) {
try {
connect();
} catch (ParseException e) {
LOGGER.error("Error connecting to MongoDB", e);
LOGGER.error(ERROR_MESSAGE_LOG, e);
}
}
db.getCollection(CachingConstants.USER_ACCOUNT).insertOne(
Expand All @@ -134,7 +135,7 @@ public static void updateDb(UserAccount userAccount) {
try {
connect();
} catch (ParseException e) {
LOGGER.error("Error connecting to MongoDB", e);
LOGGER.error(ERROR_MESSAGE_LOG, e);
}
}
db.getCollection(CachingConstants.USER_ACCOUNT).updateOne(
Expand All @@ -155,7 +156,7 @@ public static void upsertDb(UserAccount userAccount) {
try {
connect();
} catch (ParseException e) {
LOGGER.error("Error connecting to MongoDB", e);
LOGGER.error(ERROR_MESSAGE_LOG, e);
}
}
db.getCollection(CachingConstants.USER_ACCOUNT).updateOne(
Expand Down