Skip to content

Commit 59da95d

Browse files
committed
Proposal: Replace .size() == 0 with .isEmpty() for Lists and Maps
1 parent 567933d commit 59da95d

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

acl/src/main/java/org/springframework/security/acls/domain/AclImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public boolean isGranted(List<Permission> permission, List<Sid> sids, boolean ad
202202
public boolean isSidLoaded(List<Sid> sids) {
203203
// If loadedSides is null, this indicates all SIDs were loaded
204204
// Also return true if the caller didn't specify a SID to find
205-
if ((this.loadedSids == null) || (sids == null) || (sids.size() == 0)) {
205+
if ((this.loadedSids == null) || (sids == null) || sids.isEmpty()) {
206206
return true;
207207
}
208208

acl/src/main/java/org/springframework/security/acls/domain/DefaultPermissionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public Permission buildFromName(String name) {
140140

141141
@Override
142142
public List<Permission> buildFromNames(List<String> names) {
143-
if ((names == null) || (names.size() == 0)) {
143+
if ((names == null) || names.isEmpty()) {
144144
return Collections.emptyList();
145145
}
146146
List<Permission> permissions = new ArrayList<>(names.size());

config/src/main/java/org/springframework/security/config/http/UserDetailsServiceFactoryBean.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ else if (bean instanceof UserDetailsService) {
101101
*/
102102
private UserDetailsService getUserDetailsService() {
103103
Map<String, ?> beans = getBeansOfType(CachingUserDetailsService.class);
104-
if (beans.size() == 0) {
104+
if (beans.isEmpty()) {
105105
beans = getBeansOfType(UserDetailsService.class);
106106
}
107-
if (beans.size() == 0) {
107+
if (beans.isEmpty()) {
108108
throw new ApplicationContextException("No UserDetailsService registered.");
109109
}
110110
if (beans.size() > 1) {
@@ -124,7 +124,7 @@ public void setApplicationContext(ApplicationContext beanFactory) throws BeansEx
124124
// Check ancestor bean factories if they exist and the current one has none of the
125125
// required type
126126
BeanFactory parent = this.beanFactory.getParentBeanFactory();
127-
while (parent != null && beans.size() == 0) {
127+
while (parent != null && beans.isEmpty()) {
128128
if (parent instanceof ListableBeanFactory) {
129129
beans = ((ListableBeanFactory) parent).getBeansOfType(type);
130130
}

core/src/main/java/org/springframework/security/access/intercept/RunAsManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public Authentication buildRunAs(Authentication authentication, Object object,
8080
newAuthorities.add(extraAuthority);
8181
}
8282
}
83-
if (newAuthorities.size() == 0) {
83+
if (newAuthorities.isEmpty()) {
8484
return null;
8585
}
8686
// Add existing authorities

core/src/main/java/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected void initDao() throws ApplicationContextException {
182182
@Override
183183
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
184184
List<UserDetails> users = loadUsersByUsername(username);
185-
if (users.size() == 0) {
185+
if (users.isEmpty()) {
186186
this.logger.debug("Query returned no results for user '" + username + "'");
187187
throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.notFound",
188188
new Object[] { username }, "Username {0} not found"));
@@ -197,7 +197,7 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
197197
}
198198
List<GrantedAuthority> dbAuths = new ArrayList<>(dbAuthsSet);
199199
addCustomAuthorities(user.getUsername(), dbAuths);
200-
if (dbAuths.size() == 0) {
200+
if (dbAuths.isEmpty()) {
201201
this.logger.debug("User '" + username + "' has no authorities and will be treated as 'not found'");
202202
throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.noAuthority",
203203
new Object[] { username }, "User {0} has no GrantedAuthority"));

ldap/src/test/java/org/apache/directory/server/core/avltree/ArrayMarshaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public ArrayMarshaller(Comparator<E> comparator) {
7373
* @param tree the tree to be marshalled
7474
*/
7575
public byte[] serialize(ArrayTree<E> tree) {
76-
if ((tree == null) || (tree.size() == 0)) {
76+
if ((tree == null) || tree.isEmpty()) {
7777
return EMPTY_TREE;
7878
}
7979

taglibs/src/main/java/org/springframework/security/taglibs/authz/AbstractAuthorizeTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private WebInvocationPrivilegeEvaluator getPrivilegeEvaluator() throws IOExcepti
207207
ApplicationContext ctx = SecurityWebApplicationContextUtils
208208
.findRequiredWebApplicationContext(getServletContext());
209209
Map<String, WebInvocationPrivilegeEvaluator> wipes = ctx.getBeansOfType(WebInvocationPrivilegeEvaluator.class);
210-
if (wipes.size() == 0) {
210+
if (wipes.isEmpty()) {
211211
throw new IOException(
212212
"No visible WebInvocationPrivilegeEvaluator instance could be found in the application "
213213
+ "context. There must be at least one in order to support the use of URL access checks in 'authorize' tags.");

taglibs/src/main/java/org/springframework/security/taglibs/authz/AccessControlListTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private <T> T getBeanOfType(Class<T> type) throws JspException {
163163
.getParent()) {
164164
map.putAll(context.getBeansOfType(type));
165165
}
166-
if (map.size() == 0) {
166+
if (map.isEmpty()) {
167167
return null;
168168
}
169169
if (map.size() == 1) {

web/src/main/java/org/springframework/security/web/FilterChainProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private void doFilterInternal(ServletRequest request, ServletResponse response,
211211
FirewalledRequest firewallRequest = this.firewall.getFirewalledRequest((HttpServletRequest) request);
212212
HttpServletResponse firewallResponse = this.firewall.getFirewalledResponse((HttpServletResponse) response);
213213
List<Filter> filters = getFilters(firewallRequest);
214-
if (filters == null || filters.size() == 0) {
214+
if (filters == null || filters.isEmpty()) {
215215
if (logger.isTraceEnabled()) {
216216
logger.trace(LogMessage.of(() -> "No security for " + requestLine(firewallRequest)));
217217
}

0 commit comments

Comments
 (0)