You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/06/23 11:06:03 UTC

[tomcat] branch 8.5.x updated: Fix SpotBugs warning and threading issue

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new cd1ebb5  Fix SpotBugs warning and threading issue
cd1ebb5 is described below

commit cd1ebb5156ef062f713dd80511c91b0d474e8645
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 23 11:01:30 2021 +0100

    Fix SpotBugs warning and threading issue
    
    The threading issue is that roles/groups can have entries removed
    between the size test and the call to StringUtils.join()
    
    Empty groups and/or role lists are not an issue so remove the test which
    removes the need for the sync and removes the threading issue.
---
 java/org/apache/catalina/users/MemoryGroup.java | 12 ++---
 java/org/apache/catalina/users/MemoryUser.java  | 64 ++++++++++---------------
 2 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/java/org/apache/catalina/users/MemoryGroup.java b/java/org/apache/catalina/users/MemoryGroup.java
index 97d499b..eafeb80 100644
--- a/java/org/apache/catalina/users/MemoryGroup.java
+++ b/java/org/apache/catalina/users/MemoryGroup.java
@@ -172,14 +172,10 @@ public class MemoryGroup extends AbstractGroup {
             sb.append(description);
             sb.append("\"");
         }
-        synchronized (roles) {
-            if (roles.size() > 0) {
-                sb.append(" roles=\"");
-                StringUtils.join(roles, ',', new Function<Role>(){
-                    @Override public String apply(Role t) { return t.getRolename(); }}, sb);
-                sb.append("\"");
-            }
-        }
+        sb.append(" roles=\"");
+        StringUtils.join(roles, ',', new Function<Role>(){
+            @Override public String apply(Role t) { return t.getRolename(); }}, sb);
+        sb.append("\"");
         sb.append("/>");
         return sb.toString();
     }
diff --git a/java/org/apache/catalina/users/MemoryUser.java b/java/org/apache/catalina/users/MemoryUser.java
index 376f0ca..723497a 100644
--- a/java/org/apache/catalina/users/MemoryUser.java
+++ b/java/org/apache/catalina/users/MemoryUser.java
@@ -222,28 +222,20 @@ public class MemoryUser extends AbstractUser {
             sb.append(Escape.xml(fullName));
             sb.append("\"");
         }
-        synchronized (groups) {
-            if (groups.size() > 0) {
-                sb.append(" groups=\"");
-                StringUtils.join(groups, ',', new Function<Group>() {
-                    @Override public String apply(Group t) {
-                        return Escape.xml(t.getGroupname());
-                    }
-                }, sb);
-                sb.append("\"");
+        sb.append(" groups=\"");
+        StringUtils.join(groups, ',', new Function<Group>() {
+            @Override public String apply(Group t) {
+                return Escape.xml(t.getGroupname());
             }
-        }
-        synchronized (roles) {
-            if (roles.size() > 0) {
-                sb.append(" roles=\"");
-                StringUtils.join(roles, ',', new Function<Role>() {
-                    @Override public String apply(Role t) {
-                        return Escape.xml(t.getRolename());
-                    }
-                }, sb);
-                sb.append("\"");
+        }, sb);
+        sb.append("\"");
+        sb.append(" roles=\"");
+        StringUtils.join(roles, ',', new Function<Role>() {
+            @Override public String apply(Role t) {
+                return Escape.xml(t.getRolename());
             }
-        }
+        }, sb);
+        sb.append("\"");
         sb.append("/>");
         return sb.toString();
     }
@@ -263,28 +255,20 @@ public class MemoryUser extends AbstractUser {
             sb.append(Escape.xml(fullName));
             sb.append("\"");
         }
-        synchronized (groups) {
-            if (groups.size() > 0) {
-                sb.append(", groups=\"");
-                StringUtils.join(groups, ',', new Function<Group>() {
-                    @Override public String apply(Group t) {
-                        return Escape.xml(t.getGroupname());
-                    }
-                }, sb);
-                sb.append("\"");
+        sb.append(", groups=\"");
+        StringUtils.join(groups, ',', new Function<Group>() {
+            @Override public String apply(Group t) {
+                return Escape.xml(t.getGroupname());
             }
-        }
-        synchronized (roles) {
-            if (roles.size() > 0) {
-                sb.append(", roles=\"");
-                StringUtils.join(roles, ',', new Function<Role>() {
-                    @Override public String apply(Role t) {
-                        return Escape.xml(t.getRolename());
-                    }
-                }, sb);
-                sb.append("\"");
+        }, sb);
+        sb.append("\"");
+        sb.append(", roles=\"");
+        StringUtils.join(roles, ',', new Function<Role>() {
+            @Override public String apply(Role t) {
+                return Escape.xml(t.getRolename());
             }
-        }
+        }, sb);
+        sb.append("\"");
         return sb.toString();
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org