Skip to content

Improve readibility of empty collection checks #15898

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

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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 @@ -202,7 +202,7 @@ public boolean isGranted(List<Permission> permission, List<Sid> sids, boolean ad
public boolean isSidLoaded(List<Sid> sids) {
// If loadedSides is null, this indicates all SIDs were loaded
// Also return true if the caller didn't specify a SID to find
if ((this.loadedSids == null) || (sids == null) || (sids.size() == 0)) {
if ((this.loadedSids == null) || (sids == null) || sids.isEmpty()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -140,7 +140,7 @@ public Permission buildFromName(String name) {

@Override
public List<Permission> buildFromNames(List<String> names) {
if ((names == null) || (names.size() == 0)) {
if ((names == null) || names.isEmpty()) {
return Collections.emptyList();
}
List<Permission> permissions = new ArrayList<>(names.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,10 +101,10 @@ else if (bean instanceof UserDetailsService) {
*/
private UserDetailsService getUserDetailsService() {
Map<String, ?> beans = getBeansOfType(CachingUserDetailsService.class);
if (beans.size() == 0) {
if (beans.isEmpty()) {
beans = getBeansOfType(UserDetailsService.class);
}
if (beans.size() == 0) {
if (beans.isEmpty()) {
throw new ApplicationContextException("No UserDetailsService registered.");
}
if (beans.size() > 1) {
Expand All @@ -124,7 +124,7 @@ public void setApplicationContext(ApplicationContext beanFactory) throws BeansEx
// Check ancestor bean factories if they exist and the current one has none of the
// required type
BeanFactory parent = this.beanFactory.getParentBeanFactory();
while (parent != null && beans.size() == 0) {
while (parent != null && beans.isEmpty()) {
if (parent instanceof ListableBeanFactory) {
beans = ((ListableBeanFactory) parent).getBeansOfType(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Authentication buildRunAs(Authentication authentication, Object object,
newAuthorities.add(extraAuthority);
}
}
if (newAuthorities.size() == 0) {
if (newAuthorities.isEmpty()) {
return null;
}
// Add existing authorities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected void initDao() throws ApplicationContextException {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
List<UserDetails> users = loadUsersByUsername(username);
if (users.size() == 0) {
if (users.isEmpty()) {
this.logger.debug("Query returned no results for user '" + username + "'");
throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.notFound",
new Object[] { username }, "Username {0} not found"));
Expand All @@ -197,7 +197,7 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
}
List<GrantedAuthority> dbAuths = new ArrayList<>(dbAuthsSet);
addCustomAuthorities(user.getUsername(), dbAuths);
if (dbAuths.size() == 0) {
if (dbAuths.isEmpty()) {
this.logger.debug("User '" + username + "' has no authorities and will be treated as 'not found'");
throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.noAuthority",
new Object[] { username }, "User {0} has no GrantedAuthority"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -73,7 +73,7 @@ public ArrayMarshaller(Comparator<E> comparator) {
* @param tree the tree to be marshalled
*/
public byte[] serialize(ArrayTree<E> tree) {
if ((tree == null) || (tree.size() == 0)) {
if ((tree == null) || tree.isEmpty()) {
return EMPTY_TREE;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2022 the original author or authors.
* Copyright 2004-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -207,7 +207,7 @@ private WebInvocationPrivilegeEvaluator getPrivilegeEvaluator() throws IOExcepti
ApplicationContext ctx = SecurityWebApplicationContextUtils
.findRequiredWebApplicationContext(getServletContext());
Map<String, WebInvocationPrivilegeEvaluator> wipes = ctx.getBeansOfType(WebInvocationPrivilegeEvaluator.class);
if (wipes.size() == 0) {
if (wipes.isEmpty()) {
throw new IOException(
"No visible WebInvocationPrivilegeEvaluator instance could be found in the application "
+ "context. There must be at least one in order to support the use of URL access checks in 'authorize' tags.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private <T> T getBeanOfType(Class<T> type) throws JspException {
.getParent()) {
map.putAll(context.getBeansOfType(type));
}
if (map.size() == 0) {
if (map.isEmpty()) {
return null;
}
if (map.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private void doFilterInternal(ServletRequest request, ServletResponse response,
FirewalledRequest firewallRequest = this.firewall.getFirewalledRequest((HttpServletRequest) request);
HttpServletResponse firewallResponse = this.firewall.getFirewalledResponse((HttpServletResponse) response);
List<Filter> filters = getFilters(firewallRequest);
if (filters == null || filters.size() == 0) {
if (filters == null || filters.isEmpty()) {
if (logger.isTraceEnabled()) {
logger.trace(LogMessage.of(() -> "No security for " + requestLine(firewallRequest)));
}
Expand Down