Skip to content

SonarCloud fix: java:S5411 Avoid using boxed "Boolean" types directly in boolean expressions #10242

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void validateFilterProperties(String name) {
* @param label label to validate
* @return true if label is valid
*/
public static Boolean isLabelValid(String label) {
public static boolean isLabelValid(String label) {
return Pattern.compile(CreateChannelCommand.CHANNEL_LABEL_REGEX).matcher(label).find() &&
Pattern.compile(CreateChannelCommand.CHANNEL_NAME_REGEX).matcher(label).find();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private Date getPickerDate(HttpServletRequest request, String paramName) {
return null;
}

private Boolean getOptionScanDateSearch(HttpServletRequest request) {
private boolean getOptionScanDateSearch(HttpServletRequest request) {
Object dateSrch = request.getAttribute(SCAN_DATE_SEARCH);
if (dateSrch instanceof Boolean bool) {
return bool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;

Expand Down Expand Up @@ -98,7 +99,7 @@ protected ActionForward doExecute(HttpServletRequest request, ActionMapping mapp
"erratasearch.jsp.start_date",
"erratasearch.jsp.end_date");
DatePickerResults dates = null;
Boolean dateSearch = getOptionIssueDateSearch(request);
boolean dateSearch = getOptionIssueDateSearch(request);

/*
* If search/viewmode aren't null, we need to search and set
Expand Down Expand Up @@ -399,29 +400,19 @@ private List<ErrataOverview> filterByAdvisoryType(List<ErrataOverview> unfiltere
}
List<ErrataOverview> filteredByType = new ArrayList<>();
for (ErrataOverview eo : unfiltered) {
Boolean type = null;
if (eo.isBugFix()) {
type = (Boolean)formIn.get(ERRATA_BUG);
if (type != null) {
if (type) {
filteredByType.add(eo);
}
if (Optional.ofNullable((Boolean)formIn.get(ERRATA_BUG)).orElse(false)) {
filteredByType.add(eo);
}
}
if (eo.isSecurityAdvisory()) {
type = (Boolean)formIn.get(ERRATA_SEC);
if (type != null) {
if (type) {
filteredByType.add(eo);
}
if (Optional.ofNullable((Boolean)formIn.get(ERRATA_SEC)).orElse(false)) {
filteredByType.add(eo);
}
}
if (eo.isProductEnhancement()) {
type = (Boolean)formIn.get(ERRATA_ENH);
if (type != null) {
if (type) {
filteredByType.add(eo);
}
if (Optional.ofNullable((Boolean)formIn.get(ERRATA_ENH)).orElse(false)) {
filteredByType.add(eo);
}
}
}
Expand Down Expand Up @@ -524,7 +515,7 @@ private String escapeSpecialChars(String queryIn) {
return queryIn.replace(":", "\\:");
}

private Boolean getOptionIssueDateSearch(HttpServletRequest request) {
private boolean getOptionIssueDateSearch(HttpServletRequest request) {
Object dateSrch = request.getAttribute(OPT_ISSUE_DATE);
if (dateSrch == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.redhat.rhn.manager.kickstart.BaseKickstartCommand;
import com.redhat.rhn.manager.kickstart.KickstartLocaleCommand;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.struts.action.DynaActionForm;

import java.util.List;
Expand Down Expand Up @@ -77,17 +78,13 @@ protected ValidatorError processFormValues(HttpServletRequest request,
"validation.timezone.invalid");
}

Boolean useUtc = (Boolean) form.get(USE_UTC);
boolean useUtc = BooleanUtils.isTrue((Boolean)form.get(USE_UTC));

if (useUtc == null) {
useUtc = Boolean.FALSE;
}

if (localeCmd.getKickstartData().isUsingUtc() &&
if (BooleanUtils.isTrue(localeCmd.getKickstartData().isUsingUtc()) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isUsingUtc() can be converted to return a boolean:

    /**
     * Will the system hardware clock use UTC
     *
     * @return Boolean Are we using UTC?
     */
    public Boolean isUsingUtc() {
        KickstartCommand tzCommand = this.getCommand("timezone");

        if (tzCommand == null || tzCommand.getArguments() == null) {
            return Boolean.FALSE;
        }

        List<String> tokens = StringUtil.stringToList(tzCommand.getArguments());

        for (String token : tokens) {
            if (token.equals("--utc")) {
                return Boolean.TRUE;
            }
        }

        return Boolean.FALSE;
    }

!useUtc) {
localeCmd.doNotUseUtc();
}
else if (!localeCmd.getKickstartData().isUsingUtc() &&
else if (BooleanUtils.isNotTrue(localeCmd.getKickstartData().isUsingUtc()) &&
useUtc) {
localeCmd.useUtc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected ActionForward process(ActionMapping mapping, HttpServletRequest reques
return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}

private Boolean getOptionScapRetentionPeriodSet(HttpServletRequest request) {
private boolean getOptionScapRetentionPeriodSet(HttpServletRequest request) {
String strRetentionSet = request.getParameter(SCAP_RETENTION_SET);
return "on".equals(strRetentionSet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.redhat.rhn.frontend.struts.RhnValidationHelper;
import com.redhat.rhn.manager.SatManager;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
Expand Down Expand Up @@ -57,15 +58,15 @@ public ActionErrors updateDetails(User loggedInUser, User targetUser,
new ActionMessage("error.password_mismatch"));
}

Boolean readOnly = (form.get("readonly") != null);
boolean readOnly = (form.get("readonly") != null);
if (!targetUser.isReadOnly()) {
if (readOnly && targetUser.hasRole(RoleFactory.ORG_ADMIN) &&
targetUser.getOrg().numActiveOrgAdmins() < 2) {
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("error.readonly_org_admin",
targetUser.getOrg().getName()));
}
if (readOnly && targetUser.hasRole(RoleFactory.SAT_ADMIN) &&
if (BooleanUtils.isTrue(readOnly) && targetUser.hasRole(RoleFactory.SAT_ADMIN) &&
SatManager.getActiveSatAdmins().size() < 2) {
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("error.readonly_sat_admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.suse.manager.webui.utils.token.Token;
import com.suse.manager.webui.utils.token.TokenBuildingException;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -462,7 +463,7 @@ public int setDetails(User loggedInUser, String key, Map<String, Object> details
// Check if we need to override the usage_limit and set to unlimited:
if (details.containsKey("unlimited_usage_limit")) {
Boolean unlimited = (Boolean)details.get("unlimited_usage_limit");
if (unlimited) {
if (BooleanUtils.isTrue(unlimited)) {
aKey.setUsageLimit(null);
}
}
Expand Down Expand Up @@ -1080,13 +1081,13 @@ public int addConfigChannels(User loggedInUser, List<String> keys,
List<ConfigChannel> channels = configHelper.
lookupGlobals(loggedInUser, configChannelLabels);
ConfigChannelListProcessor proc = new ConfigChannelListProcessor();
if (addToTop) {
if (BooleanUtils.isTrue(addToTop)) {
Collections.reverse(channels);
}

for (ActivationKey key : activationKeys) {
for (ConfigChannel chan : channels) {
if (addToTop) {
if (BooleanUtils.isTrue(addToTop)) {
proc.add(key.getConfigChannelsFor(loggedInUser), chan, 0);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public int addScript(User loggedInUser, String ksLabel, String name, String cont
script.setData(contents.getBytes());
script.setInterpreter(interpreter.equals("") ? null : interpreter);
script.setScriptType(type);
script.setChroot(chroot ? "Y" : "N");
script.setChroot(BooleanUtils.isTrue(chroot) ? "Y" : "N");
script.setRaw(!template);
script.setErrorOnFail(erroronfail);
script.setKsdata(ksData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import com.suse.manager.api.ReadOnly;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
Expand Down Expand Up @@ -293,7 +294,7 @@ public int setLocale(User loggedInUser, String ksLabel, String locale,
}

command.setTimezone(locale);
if (useUtc) {
if (BooleanUtils.isTrue(useUtc)) {
command.useUtc();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

import com.suse.manager.api.ReadOnly;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -177,7 +178,7 @@ public OrgDto create(User loggedInUser, String orgName, String adminLogin,
cmd.setPrefix(prefix);

String pamAuthService = Config.get().getString(ConfigDefaults.WEB_PAM_AUTH_SERVICE);
if (usePamAuth) {
if (BooleanUtils.isTrue(usePamAuth)) {
if (pamAuthService != null && !pamAuthService.trim().isEmpty()) {
cmd.setUsePam(usePamAuth);
}
Expand Down Expand Up @@ -220,7 +221,7 @@ private void validateCreateOrgData(String orgName, String password, String first
throw new ValidationException(e.getMessage());
}

if (!usePamAuth && StringUtils.isEmpty(password)) {
if (BooleanUtils.isNotTrue(usePamAuth) && StringUtils.isEmpty(password)) {
throw new FaultException(-501, "passwordRequiredOrUsePam",
"Password is required if not using PAM authentication");
}
Expand Down Expand Up @@ -659,7 +660,7 @@ public int setPolicyForScapResultDeletion(User loggedInUser, Integer orgId,
ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
OrgConfig orgConfig = verifyOrgExists(orgId).getOrgConfig();
if (newSettings.containsKey("enabled")) {
if ((Boolean) newSettings.get("enabled")) {
if (BooleanUtils.isTrue((Boolean) newSettings.get("enabled"))) {
orgConfig.setScapRetentionPeriodDays(90L);
}
else {
Expand Down Expand Up @@ -828,7 +829,7 @@ public Integer setContentStaging(User loggedInUser, Integer orgId,
Boolean enable) {
ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
Org org = verifyOrgExists(orgId);
if (enable) {
if (BooleanUtils.isTrue(enable)) {
org.getOrgConfig().setStagingContentEnabled(enable);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.suse.manager.api.SerializedApiResponse;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.BooleanUtils;

import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -129,7 +130,7 @@ public SerializedApiResponse serialize(ConfigRevision src) {
protected void addFileContent(ConfigRevision rev, SerializationBuilder builder) {
if (!rev.getConfigContent().isBinary()) {
String content = rev.getConfigContent().getContentsString();
if (!StringUtil.containsInvalidXmlChars2(content)) {
if (BooleanUtils.isFalse(StringUtil.containsInvalidXmlChars2(content))) {
builder.add(CONTENTS, content);
builder.add(CONTENTS_ENC64, Boolean.FALSE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.suse.manager.api.SerializedApiResponse;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.BooleanUtils;

import java.nio.charset.StandardCharsets;

Expand Down Expand Up @@ -57,7 +58,7 @@ public SerializedApiResponse serialize(ScriptResult src) {
.add("returnCode", src.getReturnCode());

String outputContents = src.getOutputContents();
if (StringUtil.containsInvalidXmlChars2(outputContents)) {
if (BooleanUtils.isTrue(StringUtil.containsInvalidXmlChars2(outputContents))) {
builder.add("output_enc64", Boolean.TRUE);
builder.add("output", new String(Base64.encodeBase64(outputContents
.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
import com.suse.manager.xmlrpc.NoSuchHistoryEventException;
import com.suse.manager.xmlrpc.dto.SystemEventDetailsDto;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -887,7 +888,7 @@ private Map<String, Object> createChannelMap(EssentialChannelDto channel,
ret.put("id", channel.getId());
ret.put("name", channel.getName());
ret.put("label", channel.getLabel());
ret.put("current_base", currentBase ? Integer.valueOf(1) : Integer.valueOf(0));
ret.put("current_base", BooleanUtils.isTrue(currentBase) ? Integer.valueOf(1) : Integer.valueOf(0));
return ret;
}

Expand Down Expand Up @@ -1945,7 +1946,7 @@ public int setGroupMembership(User loggedInUser, Integer sid, Integer sgid,
List<Server> servers = new ArrayList<>(1);
servers.add(server);

if (member) {
if (BooleanUtils.isTrue(member)) {
//add to server group
serverGroupManager.addServers(group, servers, loggedInUser);
}
Expand Down Expand Up @@ -3909,7 +3910,7 @@ public List<Long> scheduleApplyErrata(User loggedInUser, List<Integer> sids, Lis
.map(Integer::longValue)
.collect(toList());

if (!allowModules) {
if (BooleanUtils.isNotTrue(allowModules)) {
for (Long sid : serverIds) {
Server server = SystemManager.lookupByIdAndUser(sid, loggedInUser);
for (Channel channel : server.getChannels()) {
Expand Down Expand Up @@ -4217,7 +4218,7 @@ private Long[] schedulePackagesAction(User loggedInUser, List<Integer> sids,

List<Long> actionIds = new ArrayList<>();

if (!allowModules) {
if (BooleanUtils.isNotTrue(allowModules)) {
boolean hasModules = false;
for (Integer sid : sids) {
Server server = SystemManager.lookupByIdAndUser(sid.longValue(), loggedInUser);
Expand Down Expand Up @@ -5713,7 +5714,7 @@ else if (selectedEnt.equals("unentitle")) {
if (details.containsKey("auto_errata_update")) {
Boolean autoUpdate = (Boolean)details.get("auto_errata_update");

if (autoUpdate) {
if (BooleanUtils.isTrue(autoUpdate)) {
server.setAutoUpdate("Y");
}
else {
Expand Down Expand Up @@ -5812,7 +5813,7 @@ public Integer setLockStatus(User loggedInUser, Integer sid, Boolean lockStatus)
server);
}
else {
if (lockStatus) {
if (BooleanUtils.isTrue(lockStatus)) {
// lock the server, if it isn't already locked.
if (server.getLock() == null) {
SystemManager.lockServer(loggedInUser, server,
Expand Down Expand Up @@ -7411,7 +7412,7 @@ public int setPrimaryInterface(User loggedInUser, Integer sid,
String interfaceName) {
Server server = lookupServer(loggedInUser, sid);

if (!server.existsActiveInterfaceWithName(interfaceName)) {
if (BooleanUtils.isNotTrue(server.existsActiveInterfaceWithName(interfaceName))) {
throw new NoSuchNetworkInterfaceException("No such network interface: " +
interfaceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* XmlRpcSystemHelper
Expand Down Expand Up @@ -149,14 +148,13 @@ public ShortSystemInfo format(Server server) {
*/
public int bootstrap(User user, BootstrapParameters params, boolean saltSSH)
throws BootstrapException {
BootstrapResult result = Stream.of(saltSSH).map(ssh -> {
if (ssh) {
return sshMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getSSHMinionDefault());
}
else {
return regularMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getRegularMinionDefault());
}
}).findAny().orElseThrow(() -> new BootstrapException("No result for " + params.getHost()));
BootstrapResult result;
if (saltSSH) {
result = sshMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getSSHMinionDefault());
}
else {
result = regularMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getRegularMinionDefault());
}

// Determine the result, throw BootstrapException in case of failure
if (!result.isSuccess()) {
Expand Down
Loading
Loading