Skip to content

Commit 5d3fdf1

Browse files
committed
SonarCloud fix: java:S5411 Avoid using boxed Boolean types directly in boolean expressions
1 parent b1a7b78 commit 5d3fdf1

28 files changed

+100
-85
lines changed

java/code/src/com/redhat/rhn/domain/contentmgmt/validation/ContentPropertiesValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static void validateFilterProperties(String name) {
139139
* @param label label to validate
140140
* @return true if label is valid
141141
*/
142-
public static Boolean isLabelValid(String label) {
142+
public static boolean isLabelValid(String label) {
143143
return Pattern.compile(CreateChannelCommand.CHANNEL_LABEL_REGEX).matcher(label).find() &&
144144
Pattern.compile(CreateChannelCommand.CHANNEL_NAME_REGEX).matcher(label).find();
145145
}

java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private Date getPickerDate(HttpServletRequest request, String paramName) {
9393
return null;
9494
}
9595

96-
private Boolean getOptionScanDateSearch(HttpServletRequest request) {
96+
private boolean getOptionScanDateSearch(HttpServletRequest request) {
9797
Object dateSrch = request.getAttribute(SCAN_DATE_SEARCH);
9898
if (dateSrch instanceof Boolean bool) {
9999
return bool;

java/code/src/com/redhat/rhn/frontend/action/errata/ErrataSearchAction.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.List;
4646
import java.util.ListIterator;
4747
import java.util.Map;
48+
import java.util.Optional;
4849
import java.util.Set;
4950
import java.util.TimeZone;
5051

@@ -98,7 +99,7 @@ protected ActionForward doExecute(HttpServletRequest request, ActionMapping mapp
9899
"erratasearch.jsp.start_date",
99100
"erratasearch.jsp.end_date");
100101
DatePickerResults dates = null;
101-
Boolean dateSearch = getOptionIssueDateSearch(request);
102+
boolean dateSearch = getOptionIssueDateSearch(request);
102103

103104
/*
104105
* If search/viewmode aren't null, we need to search and set
@@ -399,29 +400,19 @@ private List<ErrataOverview> filterByAdvisoryType(List<ErrataOverview> unfiltere
399400
}
400401
List<ErrataOverview> filteredByType = new ArrayList<>();
401402
for (ErrataOverview eo : unfiltered) {
402-
Boolean type = null;
403403
if (eo.isBugFix()) {
404-
type = (Boolean)formIn.get(ERRATA_BUG);
405-
if (type != null) {
406-
if (type) {
407-
filteredByType.add(eo);
408-
}
404+
if (Optional.ofNullable((Boolean)formIn.get(ERRATA_BUG)).orElse(false)) {
405+
filteredByType.add(eo);
409406
}
410407
}
411408
if (eo.isSecurityAdvisory()) {
412-
type = (Boolean)formIn.get(ERRATA_SEC);
413-
if (type != null) {
414-
if (type) {
415-
filteredByType.add(eo);
416-
}
409+
if (Optional.ofNullable((Boolean)formIn.get(ERRATA_SEC)).orElse(false)) {
410+
filteredByType.add(eo);
417411
}
418412
}
419413
if (eo.isProductEnhancement()) {
420-
type = (Boolean)formIn.get(ERRATA_ENH);
421-
if (type != null) {
422-
if (type) {
423-
filteredByType.add(eo);
424-
}
414+
if (Optional.ofNullable((Boolean)formIn.get(ERRATA_ENH)).orElse(false)) {
415+
filteredByType.add(eo);
425416
}
426417
}
427418
}
@@ -524,7 +515,7 @@ private String escapeSpecialChars(String queryIn) {
524515
return queryIn.replace(":", "\\:");
525516
}
526517

527-
private Boolean getOptionIssueDateSearch(HttpServletRequest request) {
518+
private boolean getOptionIssueDateSearch(HttpServletRequest request) {
528519
Object dateSrch = request.getAttribute(OPT_ISSUE_DATE);
529520
if (dateSrch == null) {
530521
return false;

java/code/src/com/redhat/rhn/frontend/action/kickstart/KickstartLocaleEditAction.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.redhat.rhn.manager.kickstart.BaseKickstartCommand;
2020
import com.redhat.rhn.manager.kickstart.KickstartLocaleCommand;
2121

22+
import org.apache.commons.lang3.BooleanUtils;
2223
import org.apache.struts.action.DynaActionForm;
2324

2425
import java.util.List;
@@ -77,17 +78,13 @@ protected ValidatorError processFormValues(HttpServletRequest request,
7778
"validation.timezone.invalid");
7879
}
7980

80-
Boolean useUtc = (Boolean) form.get(USE_UTC);
81+
boolean useUtc = BooleanUtils.isTrue((Boolean)form.get(USE_UTC));
8182

82-
if (useUtc == null) {
83-
useUtc = Boolean.FALSE;
84-
}
85-
86-
if (localeCmd.getKickstartData().isUsingUtc() &&
83+
if (BooleanUtils.isTrue(localeCmd.getKickstartData().isUsingUtc()) &&
8784
!useUtc) {
8885
localeCmd.doNotUseUtc();
8986
}
90-
else if (!localeCmd.getKickstartData().isUsingUtc() &&
87+
else if (BooleanUtils.isNotTrue(localeCmd.getKickstartData().isUsingUtc()) &&
9188
useUtc) {
9289
localeCmd.useUtc();
9390
}

java/code/src/com/redhat/rhn/frontend/action/multiorg/OrgConfigAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected ActionForward process(ActionMapping mapping, HttpServletRequest reques
111111
return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
112112
}
113113

114-
private Boolean getOptionScapRetentionPeriodSet(HttpServletRequest request) {
114+
private boolean getOptionScapRetentionPeriodSet(HttpServletRequest request) {
115115
String strRetentionSet = request.getParameter(SCAP_RETENTION_SET);
116116
return "on".equals(strRetentionSet);
117117
}

java/code/src/com/redhat/rhn/frontend/action/user/UserEditActionHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.redhat.rhn.frontend.struts.RhnValidationHelper;
2525
import com.redhat.rhn.manager.SatManager;
2626

27+
import org.apache.commons.lang3.BooleanUtils;
2728
import org.apache.struts.action.ActionErrors;
2829
import org.apache.struts.action.ActionMessage;
2930
import org.apache.struts.action.ActionMessages;
@@ -57,15 +58,15 @@ public ActionErrors updateDetails(User loggedInUser, User targetUser,
5758
new ActionMessage("error.password_mismatch"));
5859
}
5960

60-
Boolean readOnly = (form.get("readonly") != null);
61+
boolean readOnly = (form.get("readonly") != null);
6162
if (!targetUser.isReadOnly()) {
6263
if (readOnly && targetUser.hasRole(RoleFactory.ORG_ADMIN) &&
6364
targetUser.getOrg().numActiveOrgAdmins() < 2) {
6465
errors.add(ActionMessages.GLOBAL_MESSAGE,
6566
new ActionMessage("error.readonly_org_admin",
6667
targetUser.getOrg().getName()));
6768
}
68-
if (readOnly && targetUser.hasRole(RoleFactory.SAT_ADMIN) &&
69+
if (BooleanUtils.isTrue(readOnly) && targetUser.hasRole(RoleFactory.SAT_ADMIN) &&
6970
SatManager.getActiveSatAdmins().size() < 2) {
7071
errors.add(ActionMessages.GLOBAL_MESSAGE,
7172
new ActionMessage("error.readonly_sat_admin",

java/code/src/com/redhat/rhn/frontend/xmlrpc/activationkey/ActivationKeyHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.suse.manager.webui.utils.token.Token;
5959
import com.suse.manager.webui.utils.token.TokenBuildingException;
6060

61+
import org.apache.commons.lang3.BooleanUtils;
6162
import org.apache.commons.lang3.StringUtils;
6263
import org.apache.logging.log4j.LogManager;
6364
import org.apache.logging.log4j.Logger;
@@ -462,7 +463,7 @@ public int setDetails(User loggedInUser, String key, Map<String, Object> details
462463
// Check if we need to override the usage_limit and set to unlimited:
463464
if (details.containsKey("unlimited_usage_limit")) {
464465
Boolean unlimited = (Boolean)details.get("unlimited_usage_limit");
465-
if (unlimited) {
466+
if (BooleanUtils.isTrue(unlimited)) {
466467
aKey.setUsageLimit(null);
467468
}
468469
}
@@ -1080,13 +1081,13 @@ public int addConfigChannels(User loggedInUser, List<String> keys,
10801081
List<ConfigChannel> channels = configHelper.
10811082
lookupGlobals(loggedInUser, configChannelLabels);
10821083
ConfigChannelListProcessor proc = new ConfigChannelListProcessor();
1083-
if (addToTop) {
1084+
if (BooleanUtils.isTrue(addToTop)) {
10841085
Collections.reverse(channels);
10851086
}
10861087

10871088
for (ActivationKey key : activationKeys) {
10881089
for (ConfigChannel chan : channels) {
1089-
if (addToTop) {
1090+
if (BooleanUtils.isTrue(addToTop)) {
10901091
proc.add(key.getConfigChannelsFor(loggedInUser), chan, 0);
10911092
}
10921093
else {

java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/profile/ProfileHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public int addScript(User loggedInUser, String ksLabel, String name, String cont
675675
script.setData(contents.getBytes());
676676
script.setInterpreter(interpreter.equals("") ? null : interpreter);
677677
script.setScriptType(type);
678-
script.setChroot(chroot ? "Y" : "N");
678+
script.setChroot(BooleanUtils.isTrue(chroot) ? "Y" : "N");
679679
script.setRaw(!template);
680680
script.setErrorOnFail(erroronfail);
681681
script.setKsdata(ksData);

java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/profile/system/SystemDetailsHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import com.suse.manager.api.ReadOnly;
4040

41+
import org.apache.commons.lang3.BooleanUtils;
4142
import org.apache.commons.lang3.StringUtils;
4243

4344
import java.util.HashMap;
@@ -293,7 +294,7 @@ public int setLocale(User loggedInUser, String ksLabel, String locale,
293294
}
294295

295296
command.setTimezone(locale);
296-
if (useUtc) {
297+
if (BooleanUtils.isTrue(useUtc)) {
297298
command.useUtc();
298299
}
299300
else {

java/code/src/com/redhat/rhn/frontend/xmlrpc/org/OrgHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
import com.suse.manager.api.ReadOnly;
5454

55+
import org.apache.commons.lang3.BooleanUtils;
5556
import org.apache.commons.lang3.StringUtils;
5657
import org.apache.logging.log4j.LogManager;
5758
import org.apache.logging.log4j.Logger;
@@ -177,7 +178,7 @@ public OrgDto create(User loggedInUser, String orgName, String adminLogin,
177178
cmd.setPrefix(prefix);
178179

179180
String pamAuthService = Config.get().getString(ConfigDefaults.WEB_PAM_AUTH_SERVICE);
180-
if (usePamAuth) {
181+
if (BooleanUtils.isTrue(usePamAuth)) {
181182
if (pamAuthService != null && !pamAuthService.trim().isEmpty()) {
182183
cmd.setUsePam(usePamAuth);
183184
}
@@ -220,7 +221,7 @@ private void validateCreateOrgData(String orgName, String password, String first
220221
throw new ValidationException(e.getMessage());
221222
}
222223

223-
if (!usePamAuth && StringUtils.isEmpty(password)) {
224+
if (BooleanUtils.isNotTrue(usePamAuth) && StringUtils.isEmpty(password)) {
224225
throw new FaultException(-501, "passwordRequiredOrUsePam",
225226
"Password is required if not using PAM authentication");
226227
}
@@ -659,7 +660,7 @@ public int setPolicyForScapResultDeletion(User loggedInUser, Integer orgId,
659660
ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
660661
OrgConfig orgConfig = verifyOrgExists(orgId).getOrgConfig();
661662
if (newSettings.containsKey("enabled")) {
662-
if ((Boolean) newSettings.get("enabled")) {
663+
if (BooleanUtils.isTrue((Boolean) newSettings.get("enabled"))) {
663664
orgConfig.setScapRetentionPeriodDays(90L);
664665
}
665666
else {
@@ -828,7 +829,7 @@ public Integer setContentStaging(User loggedInUser, Integer orgId,
828829
Boolean enable) {
829830
ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
830831
Org org = verifyOrgExists(orgId);
831-
if (enable) {
832+
if (BooleanUtils.isTrue(enable)) {
832833
org.getOrgConfig().setStagingContentEnabled(enable);
833834
}
834835
else {

java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/ConfigRevisionSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.suse.manager.api.SerializedApiResponse;
2525

2626
import org.apache.commons.codec.binary.Base64;
27+
import org.apache.commons.lang3.BooleanUtils;
2728

2829
import java.nio.charset.StandardCharsets;
2930
import java.text.DecimalFormat;
@@ -129,7 +130,7 @@ public SerializedApiResponse serialize(ConfigRevision src) {
129130
protected void addFileContent(ConfigRevision rev, SerializationBuilder builder) {
130131
if (!rev.getConfigContent().isBinary()) {
131132
String content = rev.getConfigContent().getContentsString();
132-
if (!StringUtil.containsInvalidXmlChars2(content)) {
133+
if (BooleanUtils.isFalse(StringUtil.containsInvalidXmlChars2(content))) {
133134
builder.add(CONTENTS, content);
134135
builder.add(CONTENTS_ENC64, Boolean.FALSE);
135136
}

java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/ScriptResultSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.suse.manager.api.SerializedApiResponse;
2323

2424
import org.apache.commons.codec.binary.Base64;
25+
import org.apache.commons.lang3.BooleanUtils;
2526

2627
import java.nio.charset.StandardCharsets;
2728

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

5960
String outputContents = src.getOutputContents();
60-
if (StringUtil.containsInvalidXmlChars2(outputContents)) {
61+
if (BooleanUtils.isTrue(StringUtil.containsInvalidXmlChars2(outputContents))) {
6162
builder.add("output_enc64", Boolean.TRUE);
6263
builder.add("output", new String(Base64.encodeBase64(outputContents
6364
.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));

java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
import com.suse.manager.xmlrpc.NoSuchHistoryEventException;
202202
import com.suse.manager.xmlrpc.dto.SystemEventDetailsDto;
203203

204+
import org.apache.commons.lang3.BooleanUtils;
204205
import org.apache.commons.lang3.StringUtils;
205206
import org.apache.logging.log4j.LogManager;
206207
import org.apache.logging.log4j.Logger;
@@ -887,7 +888,7 @@ private Map<String, Object> createChannelMap(EssentialChannelDto channel,
887888
ret.put("id", channel.getId());
888889
ret.put("name", channel.getName());
889890
ret.put("label", channel.getLabel());
890-
ret.put("current_base", currentBase ? Integer.valueOf(1) : Integer.valueOf(0));
891+
ret.put("current_base", BooleanUtils.isTrue(currentBase) ? Integer.valueOf(1) : Integer.valueOf(0));
891892
return ret;
892893
}
893894

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

1948-
if (member) {
1949+
if (BooleanUtils.isTrue(member)) {
19491950
//add to server group
19501951
serverGroupManager.addServers(group, servers, loggedInUser);
19511952
}
@@ -3909,7 +3910,7 @@ public List<Long> scheduleApplyErrata(User loggedInUser, List<Integer> sids, Lis
39093910
.map(Integer::longValue)
39103911
.collect(toList());
39113912

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

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

4220-
if (!allowModules) {
4221+
if (BooleanUtils.isNotTrue(allowModules)) {
42214222
boolean hasModules = false;
42224223
for (Integer sid : sids) {
42234224
Server server = SystemManager.lookupByIdAndUser(sid.longValue(), loggedInUser);
@@ -5713,7 +5714,7 @@ else if (selectedEnt.equals("unentitle")) {
57135714
if (details.containsKey("auto_errata_update")) {
57145715
Boolean autoUpdate = (Boolean)details.get("auto_errata_update");
57155716

5716-
if (autoUpdate) {
5717+
if (BooleanUtils.isTrue(autoUpdate)) {
57175718
server.setAutoUpdate("Y");
57185719
}
57195720
else {
@@ -5812,7 +5813,7 @@ public Integer setLockStatus(User loggedInUser, Integer sid, Boolean lockStatus)
58125813
server);
58135814
}
58145815
else {
5815-
if (lockStatus) {
5816+
if (BooleanUtils.isTrue(lockStatus)) {
58165817
// lock the server, if it isn't already locked.
58175818
if (server.getLock() == null) {
58185819
SystemManager.lockServer(loggedInUser, server,
@@ -7411,7 +7412,7 @@ public int setPrimaryInterface(User loggedInUser, Integer sid,
74117412
String interfaceName) {
74127413
Server server = lookupServer(loggedInUser, sid);
74137414

7414-
if (!server.existsActiveInterfaceWithName(interfaceName)) {
7415+
if (BooleanUtils.isNotTrue(server.existsActiveInterfaceWithName(interfaceName))) {
74157416
throw new NoSuchNetworkInterfaceException("No such network interface: " +
74167417
interfaceName);
74177418
}

java/code/src/com/redhat/rhn/frontend/xmlrpc/system/XmlRpcSystemHelper.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.util.List;
3333
import java.util.stream.Collectors;
34-
import java.util.stream.Stream;
3534

3635
/**
3736
* XmlRpcSystemHelper
@@ -149,14 +148,13 @@ public ShortSystemInfo format(Server server) {
149148
*/
150149
public int bootstrap(User user, BootstrapParameters params, boolean saltSSH)
151150
throws BootstrapException {
152-
BootstrapResult result = Stream.of(saltSSH).map(ssh -> {
153-
if (ssh) {
154-
return sshMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getSSHMinionDefault());
155-
}
156-
else {
157-
return regularMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getRegularMinionDefault());
158-
}
159-
}).findAny().orElseThrow(() -> new BootstrapException("No result for " + params.getHost()));
151+
BootstrapResult result;
152+
if (saltSSH) {
153+
result = sshMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getSSHMinionDefault());
154+
}
155+
else {
156+
result = regularMinionBootstrapper.bootstrap(params, user, ContactMethodUtil.getRegularMinionDefault());
157+
}
160158

161159
// Determine the result, throw BootstrapException in case of failure
162160
if (!result.isSuccess()) {

0 commit comments

Comments
 (0)