Author: markt Date: Sun Jul 30 18:48:40 2017 New Revision: 1803451 URL: http://svn.apache.org/viewvc?rev=1803451&view=rev Log: Fix some scary but low confidence Findbug warnings (and other warnings in those files)
Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java tomcat/trunk/res/findbugs/filter-false-positives.xml Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java?rev=1803451&r1=1803450&r2=1803451&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java Sun Jul 30 18:48:40 2017 @@ -34,11 +34,11 @@ public class AbandonPercentageTest exten this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100); this.datasource.getPoolProperties().setRemoveAbandoned(true); this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); - Connection con = datasource.getConnection(); - Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); - Thread.sleep(2000); - Assert.assertEquals("Number of connections active/busy should be 0",0,datasource.getPool().getActive()); - con.close(); + try (Connection con = datasource.getConnection()) { + Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); + Thread.sleep(2000); + Assert.assertEquals("Number of connections active/busy should be 0",0,datasource.getPool().getActive()); + } } @Test @@ -51,11 +51,11 @@ public class AbandonPercentageTest exten this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100); this.datasource.getPoolProperties().setRemoveAbandoned(true); this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); - Connection con = datasource.getConnection(); - Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); - Thread.sleep(2000); - Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); - con.close(); + try (Connection con = datasource.getConnection()) { + Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); + Thread.sleep(2000); + Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); + } } @Test @@ -69,14 +69,16 @@ public class AbandonPercentageTest exten this.datasource.getPoolProperties().setRemoveAbandoned(true); this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1); this.datasource.getPoolProperties().setJdbcInterceptors(ResetAbandonedTimer.class.getName()); - Connection con = datasource.getConnection(); - Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); - for (int i=0; i<20; i++) { - Thread.sleep(200); - con.isClosed(); + try (Connection con = datasource.getConnection()) { + Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); + for (int i=0; i<20; i++) { + Thread.sleep(200); + // This call is here to ensure the pool thinks the connection + // is being used. + con.isClosed(); + } + Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); } - Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive()); - con.close(); } @Test Modified: tomcat/trunk/res/findbugs/filter-false-positives.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/res/findbugs/filter-false-positives.xml?rev=1803451&r1=1803450&r2=1803451&view=diff ============================================================================== --- tomcat/trunk/res/findbugs/filter-false-positives.xml (original) +++ tomcat/trunk/res/findbugs/filter-false-positives.xml Sun Jul 30 18:48:40 2017 @@ -1079,16 +1079,33 @@ <Bug pattern="DLS_DEAD_LOCAL_STORE"/> </Match> <Match> + <!-- Use of statics is unavoidable in all cases --> + <!-- Better to use it consistently rather than only where necessary --> + <Class name="org.apache.tomcat.jdbc.pool.interceptor.TestInterceptor" /> + <Bug code="ST" /> + </Match> + <Match> + <!-- The call with the ignored return value is used to ensure the pool --> + <!-- thinks the connection is being used. --> + <Class name="org.apache.tomcat.jdbc.test.AbandonPercentageTest" /> + <Method name="testResetConnection" /> + <Bug pattern="RV_RETURN_VALUE_IGNORED" /> + </Match> + <Match> <!-- Use of static is unavoidable --> <Class name="org.apache.tomcat.jdbc.test.TestStatementCache" /> <Method name="tearDown" /> <Bug code="ST" /> </Match> <Match> - <!-- Use of statics is unavoidable in all cases --> - <!-- Better to use it consistently rather than only where necessary --> - <Class name="org.apache.tomcat.jdbc.pool.interceptor.TestInterceptor" /> - <Bug code="ST" /> + <Class name="org.apache.tomcat.jdbc.test.TwoDataSources" /> + <Method name="testTwoDataSources" /> + <Or> + <!-- The object creation should fail --> + <Bug pattern="RV_RETURN_VALUE_IGNORED" /> + <!-- The connection should be close by the pool --> + <Bug pattern="ODR_OPEN_DATABASE_RESOURCE" /> + </Or> </Match> <Match> <Class name="org.apache.tomcat.util.http.TestCookieParsing$EchoCookieHeader"/> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org