Upgrading Spotbugs to 4.4.1

This commit is contained in:
Petri Tuomola
2021-09-12 07:16:22 +08:00
committed by Petri Tuomola
parent 60a4d71dd0
commit 81e5c4d814
14 changed files with 64 additions and 15 deletions
@@ -19,6 +19,7 @@
package org.apache.fineract.commands.service;
import com.google.gson.JsonElement;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.time.ZonedDateTime;
import java.util.Random;
import org.apache.fineract.commands.domain.CommandSource;
@@ -52,6 +53,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
private final CommandProcessingService processAndLogCommandService;
private final SchedulerJobRunnerReadService schedulerJobRunnerReadService;
private static final Logger LOG = LoggerFactory.getLogger(PortfolioCommandSourceWritePlatformServiceImpl.class);
private static final Random random = new Random();
@Autowired
public PortfolioCommandSourceWritePlatformServiceImpl(final PlatformSecurityContext context,
@@ -66,6 +68,8 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
@Override
@SuppressWarnings("AvoidHidingCauseException")
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public CommandProcessingResult logCommandSource(final CommandWrapper wrapper) {
boolean isApprovedByChecker = false;
@@ -112,7 +116,6 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
* Else sleep for a random time (between 1 to 10 seconds) and continue
**/
try {
Random random = new Random();
int randomNum = random.nextInt(maxIntervalBetweenRetries + 1);
Thread.sleep(1000 + (randomNum * 1000));
numberOfRetries = numberOfRetries + 1;
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.infrastructure.documentmanagement.contentrepository;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -187,6 +188,9 @@ public final class ContentRepositoryUtils {
/**
* Generate a random String.
*/
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public static String generateRandomString() {
final String characters = "abcdefghijklmnopqrstuvwxyz123456789";
// length is a random number between 5 to 16
@@ -55,6 +55,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
@@ -168,6 +169,9 @@ public class Sender {
* @throws IOException
* if message could not be sent.
*/
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public Result send(Message message, String to, int retries) throws IOException {
int attempt = 0;
Result result;
@@ -316,6 +320,8 @@ public class Sender {
* @throws IOException
* if message could not be sent.
*/
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public MulticastResult send(Message message, List<String> regIds, int retries) throws IOException {
int attempt = 0;
MulticastResult multicastResult;
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.infrastructure.jobs.service;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Random;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
@@ -36,6 +37,7 @@ import org.springframework.stereotype.Component;
public class SchedulerTriggerListener implements TriggerListener {
private static final Logger LOG = LoggerFactory.getLogger(SchedulerTriggerListener.class);
private static final Random random = new Random();
private final SchedularWritePlatformService schedularService;
private final TenantDetailsService tenantDetailsService;
@@ -58,6 +60,8 @@ public class SchedulerTriggerListener implements TriggerListener {
}
@Override
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public boolean vetoJobExecution(final Trigger trigger, final JobExecutionContext context) {
final String tenantIdentifier = trigger.getJobDataMap().getString(SchedulerServiceConstants.TENANT_IDENTIFIER);
final FineractPlatformTenant tenant = this.tenantDetailsService.loadTenantById(tenantIdentifier);
@@ -81,7 +85,6 @@ public class SchedulerTriggerListener implements TriggerListener {
LOG.warn("vetoJobExecution() not able to acquire the lock to update job running status at retry {} (of {}) for JobKey: {}",
numberOfRetries, maxNumberOfRetries, jobKey, exception);
try {
Random random = new Random();
int randomNum = random.nextInt(maxIntervalBetweenRetries + 1);
Thread.sleep(1000 + (randomNum * 1000));
numberOfRetries = numberOfRetries + 1;
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.loanaccount.service;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -55,6 +56,7 @@ import org.springframework.util.CollectionUtils;
public class LoanSchedularServiceImpl implements LoanSchedularService {
private static final Logger LOG = LoggerFactory.getLogger(LoanSchedularServiceImpl.class);
private static final Random random = new Random();
private final ConfigurationDomainService configurationDomainService;
private final LoanReadPlatformService loanReadPlatformService;
@@ -123,6 +125,8 @@ public class LoanSchedularServiceImpl implements LoanSchedularService {
@Override
@CronTarget(jobName = JobName.RECALCULATE_INTEREST_FOR_LOAN)
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public void recalculateInterest() throws JobExecutionException {
Integer maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock();
Integer maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries();
@@ -150,7 +154,6 @@ public class LoanSchedularServiceImpl implements LoanSchedularService {
// Else sleep for a random time (between 1 to 10
// seconds) and continue
try {
Random random = new Random();
int randomNum = random.nextInt(maxIntervalBetweenRetries + 1);
Thread.sleep(1000 + (randomNum * 1000));
numberOfRetries = numberOfRetries + 1;
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.loanaccount.service;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -37,6 +38,7 @@ import org.springframework.stereotype.Component;
public class RecalculateInterestPoster implements Callable<Void> {
private static final Logger LOG = LoggerFactory.getLogger(RecalculateInterestPoster.class);
private static final Random random = new Random();
private Collection<Long> loanIds;
private LoanWritePlatformService loanWritePlatformService;
@@ -50,6 +52,8 @@ public class RecalculateInterestPoster implements Callable<Void> {
}
@Override
@SuppressFBWarnings(value = {
"DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once")
public Void call() throws JobExecutionException {
Integer maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock();
Integer maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries();