This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit e4771310934871bfc5eb27638d4cb766281c8c82 Author: Mark Thomas <[email protected]> AuthorDate: Tue Mar 15 17:18:09 2022 +0000 Fix sync issues identified by SpotBugs --- .../catalina/nonblocking/TestNonBlockingAPI.java | 3 ++- .../tribes/test/transport/SocketNioReceive.java | 24 ++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java index 782dce7..c0eeca5 100644 --- a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java +++ b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java @@ -1143,7 +1143,8 @@ public class TestNonBlockingAPI extends TomcatBaseTest { try { byte buffer[] = new byte[1 * 4]; while (is.isReady() && !is.isFinished()) { - is.read(buffer); + @SuppressWarnings("unused") + int ignore = is.read(buffer); } String body = new String(buffer, StandardCharsets.UTF_8); Assert.assertTrue(body.equals("body")); diff --git a/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java b/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java index 763d7b2..9936c63 100644 --- a/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java +++ b/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java @@ -27,13 +27,15 @@ import org.apache.catalina.tribes.membership.MemberImpl; import org.apache.catalina.tribes.transport.nio.NioReceiver; public class SocketNioReceive { - static int count = 0; - static int accept = 0; - static long start = 0; - static double mb = 0; - static int len = 0; - static DecimalFormat df = new DecimalFormat("##.00"); - static double seconds = 0; + private static int count = 0; + private static final Object countLock = new Object(); + private static int accept = 0; + private static final Object acceptLock = new Object(); + private static long start = 0; + private static double mb = 0; + private static int len = 0; + private static DecimalFormat df = new DecimalFormat("##.00"); + private static double seconds = 0; protected static final Object mutex = new Object(); public static void main(String[] args) throws Exception { @@ -74,7 +76,9 @@ public class SocketNioReceive { start = System.currentTimeMillis(); } mb += ( (double) len) / 1024 / 1024; - synchronized (this) {count++;} + synchronized (countLock) { + count++; + } if ( ( (count) % 10000) == 0) { long time = System.currentTimeMillis(); seconds = ( (double) (time - start)) / 1000; @@ -84,7 +88,9 @@ public class SocketNioReceive { @Override public boolean accept(ChannelMessage msg) { - synchronized (this) {accept++;} + synchronized (acceptLock) { + accept++; + } return true; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
