Author: markt
Date: Wed Feb 26 19:49:46 2014
New Revision: 1572217
URL: http://svn.apache.org/r1572217
Log:
Findbugs fixes
Make connection count thread safe
Modified:
commons/proper/dbcp/trunk/findbugs-exclude-filter.xml
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java
Modified: commons/proper/dbcp/trunk/findbugs-exclude-filter.xml
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/findbugs-exclude-filter.xml?rev=1572217&r1=1572216&r2=1572217&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/findbugs-exclude-filter.xml (original)
+++ commons/proper/dbcp/trunk/findbugs-exclude-filter.xml Wed Feb 26 19:49:46
2014
@@ -28,6 +28,24 @@
<Class name="~.*\.Tester.*"/>
<Bug pattern="NP_NONNULL_RETURN_VIOLATION" />
</Match>
+ <!-- Tests aren't run with a security manager configured -->
+ <Match>
+ <Class name="org.apache.commons.dbcp2.TestBasicDataSource"/>
+ <Method name="setUp"/>
+ <Bug pattern="DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"/>
+ </Match>
+ <!-- Sleep is intentional and short -->
+ <Match>
+ <Class name="org.apache.commons.dbcp2.TestBasicDataSource"/>
+ <Method name="testCreateDataSourceCleanupEvictor"/>
+ <Bug pattern="SWL_SLEEP_WITH_LOCK_HELD"/>
+ </Match>
+ <!-- Write to static is intentional -->
+ <Match>
+ <Class
name="org.apache.commons.dbcp2.TestBasicDataSource.TesterConnRequestCountDriver"/>
+ <Method name="connect"/>
+ <Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD "/>
+ </Match>
<!-- Not worth coding around for test code -->
<Match>
<Class name="org.apache.commons.dbcp2.TesterResultSet"/>
Modified:
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java?rev=1572217&r1=1572216&r2=1572217&view=diff
==============================================================================
---
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
(original)
+++
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
Wed Feb 26 19:49:46 2014
@@ -22,6 +22,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.DataSource;
@@ -244,12 +245,10 @@ public class TestBasicDataSource extends
}
public void testInvalidValidationQuery() {
- try {
- ds.setValidationQuery("invalid");
- ds.getConnection();
+ ds.setValidationQuery("invalid");
+ try (Connection c = ds.getConnection()) {
fail("expected SQLException");
- }
- catch (SQLException e) {
+ } catch (SQLException e) {
if (e.toString().indexOf("invalid") < 0) {
fail("expected detailed error message");
}
@@ -259,8 +258,7 @@ public class TestBasicDataSource extends
public void testValidationQueryTimoutFail() {
ds.setTestOnBorrow(true);
ds.setValidationQueryTimeout(3); // Too fast for TesterStatement
- try {
- ds.getConnection();
+ try (Connection c = ds.getConnection()) {
fail("expected SQLException");
} catch (SQLException ex) {
if (ex.toString().indexOf("timeout") < 0) {
@@ -306,7 +304,7 @@ public class TestBasicDataSource extends
public void testInvalidConnectionInitSql() {
try {
ds.setConnectionInitSqls(Arrays.asList(new String[]{"SELECT
1","invalid"}));
- ds.getConnection();
+ try (Connection c = ds.getConnection()) {}
fail("expected SQLException");
}
catch (SQLException e) {
@@ -486,8 +484,7 @@ public class TestBasicDataSource extends
ds.setValidationQuery("SELECT DUMMY FROM DUAL");
int threadCount = Thread.activeCount();
for (int i = 0; i < 10; i++) {
- try {
- ds.getConnection();
+ try (Connection c = ds.getConnection()){
} catch (SQLException ex) {
// ignore
}
@@ -560,11 +557,11 @@ public class TestBasicDataSource extends
*/
class TesterConnRequestCountDriver extends TesterDriver {
private static final String CONNECT_STRING =
"jdbc:apache:commons:testerConnRequestCountDriver";
- private static int connectionRequestCount = 0;
+ private static AtomicInteger connectionRequestCount = new AtomicInteger(0);
@Override
public Connection connect(String url, Properties info) throws SQLException
{
- connectionRequestCount++;
+ connectionRequestCount.incrementAndGet();
return super.connect(url, info);
}
@@ -574,10 +571,10 @@ class TesterConnRequestCountDriver exten
}
public static int getConnectionRequestCount() {
- return connectionRequestCount;
+ return connectionRequestCount.get();
}
public static void initConnRequestCount() {
- connectionRequestCount = 0;
+ connectionRequestCount.set(0);
}
}
Modified:
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java?rev=1572217&r1=1572216&r2=1572217&view=diff
==============================================================================
---
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java
(original)
+++
commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java
Wed Feb 26 19:49:46 2014
@@ -50,7 +50,9 @@ public class TesterPreparedStatement ext
super(conn);
try {
_catalog = conn.getCatalog();
- } catch (SQLException e) { }
+ } catch (SQLException e) {
+ // Ignored
+ }
}
public TesterPreparedStatement(Connection conn, String sql) {
@@ -58,7 +60,9 @@ public class TesterPreparedStatement ext
_sql = sql;
try {
_catalog = conn.getCatalog();
- } catch (SQLException e) { }
+ } catch (SQLException e) {
+ // Ignored
+ }
}
public TesterPreparedStatement(Connection conn, String sql, int
resultSetType, int resultSetConcurrency) {
@@ -66,7 +70,9 @@ public class TesterPreparedStatement ext
_sql = sql;
try {
_catalog = conn.getCatalog();
- } catch (SQLException e) { }
+ } catch (SQLException e) {
+ // Ignored
+ }
}
/** for junit test only */