From 4a7ebbbc7cdec4051f2fc242e3a7d20070defeb9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 06:08:18 -0400 Subject: [PATCH 001/169] Bump github/codeql-action from 3.25.8 to 3.25.10 (#396) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.8 to 3.25.10. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/2e230e8fe0ad3a14a340ad0815ddb96d599d2aff...23acc5c183826b7a8a97bce3cecc52db901f8251) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7e014f8759..12acd6d4fa 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # 3.25.8 + uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # 3.25.8 + uses: github/codeql-action/autobuild@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # 3.25.8 + uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index ae7a6eacd8..61d000ddd4 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # 3.25.8 + uses: github/codeql-action/upload-sarif@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 with: sarif_file: results.sarif From 569ae858494348553fd03b4e7347d864321f166e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 06:08:32 -0400 Subject: [PATCH 002/169] Bump codecov/codecov-action from 4.4.1 to 4.5.0 (#398) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.4.1 to 4.5.0. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/125fc84a9a348dbcf27191600683ec096ec9021c...e28ff129e5465c2c0dcc6f003fc735cb6ae0c673) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 5cd1566cb1..c6a3d9a277 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -47,6 +47,6 @@ jobs: run: mvn --show-version --batch-mode --no-transfer-progress test jacoco:report - name: Upload coverage to Codecov - uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1 + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 with: files: ./target/site/jacoco/jacoco.xml From affb6b5010dfff48aaa47f085716e75093727855 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 06:08:45 -0400 Subject: [PATCH 003/169] Bump actions/checkout from 4.1.6 to 4.1.7 (#397) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.6 to 4.1.7. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/a5ac7e51b41094c92402da3b24376905380afc29...692973e3d937129bcbf40652eb9f2f61becf3332) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/coverage.yml | 2 +- .github/workflows/maven.yml | 2 +- .github/workflows/scorecards-analysis.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 12acd6d4fa..e70708d23b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index c6a3d9a277..8367dfe1b2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -29,7 +29,7 @@ jobs: java: [ 8 ] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c6de493ed0..65a377ca23 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -34,7 +34,7 @@ jobs: # experimental: true steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 61d000ddd4..7efca3176b 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -40,7 +40,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: persist-credentials: false From dd32100b5796f18abea994dfeb2c8acf69eb962e Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 18 Jun 2024 09:16:17 -0400 Subject: [PATCH 004/169] Javadoc --- .../apache/commons/dbcp2/datasources/PerUserPoolDataSource.java | 2 +- .../apache/commons/dbcp2/datasources/SharedPoolDataSource.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 85d7491ad0..1b60c498df 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -687,7 +687,7 @@ Map put(Map map, final K key, final V value) { * Supports Serialization interface. * * @param in - * a {@link java.io.ObjectInputStream} value + * a {@link ObjectInputStream} value * @throws IOException * if an error occurs * @throws ClassNotFoundException diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index d14ff58362..31e7aeda08 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -145,7 +145,7 @@ public Reference getReference() throws NamingException { * Supports Serialization interface. * * @param in - * a {@link java.io.ObjectInputStream} value + * a {@link ObjectInputStream} value * @throws IOException * if an error occurs * @throws ClassNotFoundException From 13bb605afd3b31750f0ed8dd1a1aa1a0e1776e6f Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 23 Jun 2024 15:50:59 -0400 Subject: [PATCH 005/169] Javadoc --- .../dbcp2/datasources/PerUserPoolDataSource.java | 11 ++++------- .../dbcp2/datasources/SharedPoolDataSource.java | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 1b60c498df..46dcf3ae94 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -684,14 +684,11 @@ Map put(Map map, final K key, final V value) { } /** - * Supports Serialization interface. + * Deserializes an instance from an ObjectInputStream. * - * @param in - * a {@link ObjectInputStream} value - * @throws IOException - * if an error occurs - * @throws ClassNotFoundException - * if an error occurs + * @param in The source ObjectInputStream. + * @throws IOException Any of the usual Input/Output related exceptions. + * @throws ClassNotFoundException A class of a serialized object cannot be found. */ @SuppressWarnings("resource") private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index 31e7aeda08..fd596d51da 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -142,14 +142,11 @@ public Reference getReference() throws NamingException { } /** - * Supports Serialization interface. + * Deserializes an instance from an ObjectInputStream. * - * @param in - * a {@link ObjectInputStream} value - * @throws IOException - * if an error occurs - * @throws ClassNotFoundException - * if an error occurs + * @param in The source ObjectInputStream. + * @throws IOException Any of the usual Input/Output related exceptions. + * @throws ClassNotFoundException A class of a serialized object cannot be found. */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); From 6352dcab43cdba05f7c68ae2f3c9217e68609079 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 29 Jun 2024 08:02:20 -0400 Subject: [PATCH 006/169] Drop CodeQL - It now requires an API key and a login to view reports - Instead, use 'mvn clean install site -P jacoco' to view JaCoCo HTML reports --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 954b884ae6..7367fb7b22 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ Apache Commons DBCP [![Coverage Status](https://codecov.io/gh/apache/commons-dbcp/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/commons-dbcp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/?gav=true) [![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.12.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.12.0) -[![CodeQL](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp) Apache Commons DBCP software implements Database Connection Pooling From 6a2137142c8f73cb57eeb69c8417d348be7c2236 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 29 Jun 2024 08:11:00 -0400 Subject: [PATCH 007/169] Drop CodeQL - It now requires an API key and a login to view reports - Instead, use 'mvn clean install site -P jacoco' to view JaCoCo HTML reports --- .github/workflows/codeql-analysis.yml | 85 --------------------------- 1 file changed, 85 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index e70708d23b..0000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,85 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '33 9 * * 4' - -permissions: - contents: read - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support - - steps: - - name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - with: - persist-credentials: false - - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 From cf78f942d39b0c1b1f4556b5dd54dc7efb5c99af Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 29 Jun 2024 10:49:21 -0400 Subject: [PATCH 008/169] Revert "Drop CodeQL" This reverts commit 6a2137142c8f73cb57eeb69c8417d348be7c2236. --- .github/workflows/codeql-analysis.yml | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000000..e70708d23b --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,85 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '33 9 * * 4' + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + persist-credentials: false + - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 From 0d104b8f4508800354eb39f0381615d48653eef9 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 29 Jun 2024 10:49:21 -0400 Subject: [PATCH 009/169] Revert "Drop CodeQL" This reverts commit 6352dcab43cdba05f7c68ae2f3c9217e68609079. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7367fb7b22..954b884ae6 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Apache Commons DBCP [![Coverage Status](https://codecov.io/gh/apache/commons-dbcp/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/commons-dbcp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/?gav=true) [![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.12.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.12.0) +[![CodeQL](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp) Apache Commons DBCP software implements Database Connection Pooling From 3d287e36bf45b32cf09bb39037ba87117669c265 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 29 Jun 2024 14:24:23 -0400 Subject: [PATCH 010/169] Drop codecov.io - It now requires an API key and a login to view reports - Instead, use 'mvn clean install site -P jacoco' to view JaCoCo HTML reports --- .github/workflows/coverage.yml | 52 ---------------------------------- README.md | 1 - 2 files changed, 53 deletions(-) delete mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 8367dfe1b2..0000000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,52 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -name: Coverage - -on: [push, pull_request] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - java: [ 8 ] - - steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - with: - persist-credentials: false - - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - - name: Build with Maven - run: mvn --show-version --batch-mode --no-transfer-progress test jacoco:report - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 - with: - files: ./target/site/jacoco/jacoco.xml diff --git a/README.md b/README.md index 954b884ae6..f467f4ec4c 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ Apache Commons DBCP =================== [![Java CI](https://github.com/apache/commons-dbcp/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/maven.yml) -[![Coverage Status](https://codecov.io/gh/apache/commons-dbcp/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/commons-dbcp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/?gav=true) [![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.12.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.12.0) [![CodeQL](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml) From fd739ef1fb89c21ea3a8d6f796c43297ef9649cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2024 06:46:50 -0400 Subject: [PATCH 011/169] Bump github/codeql-action from 3.25.10 to 3.25.11 (#401) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.10 to 3.25.11. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/23acc5c183826b7a8a97bce3cecc52db901f8251...b611370bb5703a7efb587f9d136a52ea24c5c38c) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e70708d23b..492ed75027 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 + uses: github/codeql-action/init@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 + uses: github/codeql-action/autobuild@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 + uses: github/codeql-action/analyze@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 7efca3176b..b8c14b15b3 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@23acc5c183826b7a8a97bce3cecc52db901f8251 # 3.25.10 + uses: github/codeql-action/upload-sarif@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 with: sarif_file: results.sarif From 2aba7d1c5f4bcffeac75d7c9e71b7b01a55e664e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2024 07:52:42 -0400 Subject: [PATCH 012/169] Bump commons-logging:commons-logging from 1.3.2 to 1.3.3 (#399) Bumps commons-logging:commons-logging from 1.3.2 to 1.3.3. --- updated-dependencies: - dependency-name: commons-logging:commons-logging dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f5b8ae155e..4ad507fe57 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ commons-logging commons-logging - 1.3.2 + 1.3.3 From 6ada0c61d30cf88ebac5035b095a120f31692e99 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 5 Jul 2024 07:53:23 -0400 Subject: [PATCH 013/169] Bump commons-logging:commons-logging from 1.3.2 to 1.3.3 #399 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bbbafc3ade..8f3bef3451 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -74,7 +74,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 71 #360, #371, #395. - Bump commons-logging:commons-logging from 1.3.0 to 1.3.2 #368. + Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. From 69683ea5355c750eceeea7d610103cee862fb404 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 9 Jul 2024 10:15:48 -0400 Subject: [PATCH 014/169] Remove redundant keywords --- src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java index 3114f42b07..6c30b5555e 100644 --- a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java +++ b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java @@ -95,7 +95,7 @@ public void cancel() throws SQLException { protected void checkOpen() throws SQLException { if (isClosed()) { - throw new SQLException(this.getClass().getName() + " with address: \"" + this.toString() + "\" is closed."); + throw new SQLException(this.getClass().getName() + " with address: \"" + toString() + "\" is closed."); } } From 52c66aade7aef5fa257d0fe139af215976d3607f Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 9 Jul 2024 10:16:03 -0400 Subject: [PATCH 015/169] Use final --- .../apache/commons/dbcp2/datasources/SharedPoolDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index fd596d51da..54e8b8a036 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -156,7 +156,7 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot private KeyedObjectPool readObjectImpl() throws IOException, ClassNotFoundException { try { return ((SharedPoolDataSource) new SharedPoolDataSourceFactory().getObjectInstance(getReference(), null, null, null)).pool; - } catch (NamingException e) { + } catch (final NamingException e) { throw new IOException("NamingException: " + e); } } From 3367ceddc79690721fcf645a5f8cdb9a4bd23ec5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jul 2024 07:16:57 -0400 Subject: [PATCH 016/169] Bump actions/upload-artifact from 4.3.3 to 4.3.4 (#402) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.3 to 4.3.4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/65462800fd760344b1a7b4382951275a0abb4808...0b2256b8c012f0828dc542b3febcab082c67f72b) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/scorecards-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index b8c14b15b3..9c3dcf97c1 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -57,7 +57,7 @@ jobs: publish_results: true - name: "Upload artifact" - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # 4.3.3 + uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # 4.3.4 with: name: SARIF file path: results.sarif From d3bd07b57b590a5143d8e1968556177f780f9ac6 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 14 Jul 2024 12:49:31 -0400 Subject: [PATCH 017/169] Normalize instance variable names in tests --- .../commons/dbcp2/TestConnectionPool.java | 32 ++-- .../dbcp2/TestParallelCreationWithNoIdle.java | 4 +- .../commons/dbcp2/TesterConnection.java | 52 +++---- .../dbcp2/TesterPreparedStatement.java | 76 +++++----- .../apache/commons/dbcp2/TesterResultSet.java | 2 +- .../apache/commons/dbcp2/TesterStatement.java | 140 +++++++++--------- 6 files changed, 153 insertions(+), 153 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java index 597d2cab59..acee1c87b8 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java +++ b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java @@ -164,37 +164,37 @@ public void stop() { } final class TestThread implements Runnable { - final java.util.Random _random = new java.util.Random(); - boolean _complete; - boolean _failed; - int _iter = 100; - int _delay = 50; + final java.util.Random random = new java.util.Random(); + boolean complete; + boolean failed; + int iter = 100; + int delay = 50; public TestThread() { } public TestThread(final int iter) { - _iter = iter; + this.iter = iter; } public TestThread(final int iter, final int delay) { - _iter = iter; - _delay = delay; + this.iter = iter; + this.delay = delay; } public boolean complete() { - return _complete; + return complete; } public boolean failed() { - return _failed; + return failed; } @Override public void run() { - for (int i = 0; i < _iter; i++) { + for (int i = 0; i < iter; i++) { try { - Thread.sleep(_random.nextInt(_delay)); + Thread.sleep(random.nextInt(delay)); } catch (final Exception e) { // ignored } @@ -202,18 +202,18 @@ public void run() { PreparedStatement stmt = conn.prepareStatement("select 'literal', SYSDATE from dual"); ResultSet rset = stmt.executeQuery()) { try { - Thread.sleep(_random.nextInt(_delay)); + Thread.sleep(random.nextInt(delay)); } catch (final Exception ignore) { // ignored } } catch (final Exception e) { e.printStackTrace(); - _failed = true; - _complete = true; + failed = true; + complete = true; break; } } - _complete = true; + complete = true; } } diff --git a/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java b/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java index 395d4a1331..3b2ea0e1a6 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java +++ b/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java @@ -36,7 +36,7 @@ public class TestParallelCreationWithNoIdle { final class TestThread extends Thread { - final java.util.Random _random = new java.util.Random(); + final java.util.Random random = new java.util.Random(); final int iter; final int delay; final int delayAfter; @@ -72,7 +72,7 @@ private void sleepMax(final int timeMax) { return; } try { - Thread.sleep(_random.nextInt(timeMax)); + Thread.sleep(random.nextInt(timeMax)); } catch (final Exception e) { // ignored } diff --git a/src/test/java/org/apache/commons/dbcp2/TesterConnection.java b/src/test/java/org/apache/commons/dbcp2/TesterConnection.java index 00b6075199..3e6e4bb4e6 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterConnection.java @@ -40,15 +40,15 @@ */ public class TesterConnection extends AbandonedTrace implements Connection { - protected boolean _open = true; - protected boolean _aborted; - protected boolean _autoCommit = true; - protected int _transactionIsolation = 1; - protected final DatabaseMetaData _metaData = new TesterDatabaseMetaData(); - protected String _catalog; + protected boolean open = true; + protected boolean aborted; + protected boolean autoCommit = true; + protected int transactionIsolation = 1; + protected final DatabaseMetaData metaData = new TesterDatabaseMetaData(); + protected String catalog; protected String schema; - protected Map> _typeMap; - protected boolean _readOnly; + protected Map> typeMap; + protected boolean readOnly; protected SQLWarning warnings; protected final String userName; protected Exception failure; @@ -62,8 +62,8 @@ public class TesterConnection extends AbandonedTrace implements Connection { @Override public void abort(final Executor executor) throws SQLException { checkFailure(); - _aborted = true; - _open = false; + aborted = true; + open = false; } protected void checkFailure() throws SQLException { @@ -76,7 +76,7 @@ protected void checkFailure() throws SQLException { } protected void checkOpen() throws SQLException { - if (!_open) { + if (!open) { throw new SQLException("Connection is closed."); } checkFailure(); @@ -91,7 +91,7 @@ public void clearWarnings() throws SQLException { @Override public void close() throws SQLException { checkFailure(); - _open = false; + open = false; } @Override @@ -155,13 +155,13 @@ public Struct createStruct(final String typeName, final Object[] attributes) thr @Override public boolean getAutoCommit() throws SQLException { checkOpen(); - return _autoCommit; + return autoCommit; } @Override public String getCatalog() throws SQLException { checkOpen(); - return _catalog; + return catalog; } @Override @@ -182,7 +182,7 @@ public int getHoldability() throws SQLException { @Override public DatabaseMetaData getMetaData() throws SQLException { checkOpen(); - return _metaData; + return metaData; } @Override @@ -199,13 +199,13 @@ public String getSchema() throws SQLException { @Override public int getTransactionIsolation() throws SQLException { checkOpen(); - return _transactionIsolation; + return transactionIsolation; } @Override public Map> getTypeMap() throws SQLException { checkOpen(); - return _typeMap; + return typeMap; } public String getUserName() { @@ -220,19 +220,19 @@ public SQLWarning getWarnings() throws SQLException { public boolean isAborted() throws SQLException { checkFailure(); - return _aborted; + return aborted; } @Override public boolean isClosed() throws SQLException { checkFailure(); - return !_open; + return !open; } @Override public boolean isReadOnly() throws SQLException { checkOpen(); - return _readOnly; + return readOnly; } public boolean isSqlExceptionOnClose() { @@ -241,7 +241,7 @@ public boolean isSqlExceptionOnClose() { @Override public boolean isValid(final int timeout) throws SQLException { - return _open; + return open; } @Override @@ -352,13 +352,13 @@ public void rollback(final java.sql.Savepoint savepoint) throws SQLException { @Override public void setAutoCommit(final boolean autoCommit) throws SQLException { checkOpen(); - _autoCommit = autoCommit; + this.autoCommit = autoCommit; } @Override public void setCatalog(final String catalog) throws SQLException { checkOpen(); - _catalog = catalog; + this.catalog = catalog; } @Override @@ -389,7 +389,7 @@ public void setNetworkTimeout(final Executor executor, final int milliseconds) @Override public void setReadOnly(final boolean readOnly) throws SQLException { checkOpen(); - _readOnly = readOnly; + this.readOnly = readOnly; } @Override @@ -415,13 +415,13 @@ public void setSqlExceptionOnClose(final boolean sqlExceptionOnClose) { @Override public void setTransactionIsolation(final int level) throws SQLException { checkOpen(); - _transactionIsolation = level; + this.transactionIsolation = level; } @Override public void setTypeMap(final Map> map) throws SQLException { checkOpen(); - _typeMap = map; + this.typeMap = map; } public void setWarnings(final SQLWarning warning) { diff --git a/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java index 3d11bbb7fa..b171c8577c 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java @@ -40,17 +40,17 @@ */ public class TesterPreparedStatement extends TesterStatement implements PreparedStatement { - private final ResultSetMetaData _resultSetMetaData = null; - private String _sql; - private String _catalog; - private int _autoGeneratedKeys = 1; - private int[] _columnIndexes; - private String[] _columnNames; + private final ResultSetMetaData resultSetMetaData = null; + private String sql; + private String catalog; + private int autoGeneratedKeys = 1; + private int[] columnIndexes; + private String[] columnNames; public TesterPreparedStatement(final Connection conn) { super(conn); try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -58,9 +58,9 @@ public TesterPreparedStatement(final Connection conn) { public TesterPreparedStatement(final Connection conn, final String sql) { super(conn); - _sql = sql; + this.sql = sql; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -68,10 +68,10 @@ public TesterPreparedStatement(final Connection conn, final String sql) { public TesterPreparedStatement(final Connection conn, final String sql, final int autoGeneratedKeys) { super(conn); - _sql = sql; - _autoGeneratedKeys = autoGeneratedKeys; + this.sql = sql; + this.autoGeneratedKeys = autoGeneratedKeys; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -79,9 +79,9 @@ public TesterPreparedStatement(final Connection conn, final String sql, final in public TesterPreparedStatement(final Connection conn, final String sql, final int resultSetType, final int resultSetConcurrency) { super(conn, resultSetType, resultSetConcurrency); - _sql = sql; + this.sql = sql; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -90,9 +90,9 @@ public TesterPreparedStatement(final Connection conn, final String sql, final in public TesterPreparedStatement(final Connection conn, final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { super(conn, resultSetType, resultSetConcurrency, resultSetHoldability); - _sql = sql; + this.sql = sql; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -100,10 +100,10 @@ public TesterPreparedStatement(final Connection conn, final String sql, final in public TesterPreparedStatement(final Connection conn, final String sql, final int[] columnIndexes) { super(conn); - _sql = sql; - _columnIndexes = columnIndexes; + this.sql = sql; + this.columnIndexes = columnIndexes; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -111,10 +111,10 @@ public TesterPreparedStatement(final Connection conn, final String sql, final in public TesterPreparedStatement(final Connection conn, final String sql, final String[] columnNames) { super(conn); - _sql = sql; - _columnNames = columnNames; + this.sql = sql; + this.columnNames = columnNames; try { - _catalog = conn.getCatalog(); + this.catalog = conn.getCatalog(); } catch (final SQLException e) { // Ignored } @@ -156,13 +156,13 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE @Override public long executeLargeUpdate() throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override public long executeLargeUpdate(final String sql) throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override @@ -186,14 +186,14 @@ public long executeLargeUpdate(final String sql, final String[] columnNames) thr @Override public ResultSet executeQuery() throws SQLException { checkOpen(); - if ("null".equals(_sql)) { + if ("null".equals(sql)) { return null; } - if (_queryTimeout > 0 && _queryTimeout < 5) { + if (queryTimeout > 0 && queryTimeout < 5) { // Simulate timeout if queryTimout is set to less than 5 seconds throw new SQLException("query timeout"); } - return new TesterResultSet(this, _resultSetType, _resultSetConcurrency); + return new TesterResultSet(this, resultSetType, resultSetConcurrency); } @Override @@ -202,19 +202,19 @@ public ResultSet executeQuery(final String sql) throws SQLException { if ("null".equals(sql)) { return null; } - return new TesterResultSet(this, _resultSetType, _resultSetConcurrency); + return new TesterResultSet(this, resultSetType, resultSetConcurrency); } @Override public int executeUpdate() throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override public int executeUpdate(final String sql) throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override @@ -236,30 +236,30 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ } public int getAutoGeneratedKeys() { - return _autoGeneratedKeys; + return autoGeneratedKeys; } public String getCatalog() { - return _catalog; + return catalog; } public int[] getColumnIndexes() { - return _columnIndexes; + return columnIndexes; } public String[] getColumnNames() { - return _columnNames; + return columnNames; } @Override public ResultSet getGeneratedKeys() throws SQLException { - return new TesterResultSet(this, _resultSetType, _resultSetConcurrency); + return new TesterResultSet(this, resultSetType, resultSetConcurrency); } @Override public ResultSetMetaData getMetaData() throws SQLException { checkOpen(); - return _resultSetMetaData; + return resultSetMetaData; } @Override @@ -274,7 +274,7 @@ public java.sql.ParameterMetaData getParameterMetaData() throws SQLException { /** For junit test only */ public String getSql() { - return _sql; + return sql; } @Override @@ -531,6 +531,6 @@ public void setURL(final int parameterIndex, final java.net.URL x) throws SQLExc @Override public String toString() { - return _sql; + return sql; } } diff --git a/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java b/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java index dad25d5923..0150e26366 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java @@ -111,7 +111,7 @@ public void close() throws SQLException { // Not all result sets are generated from statements eg DatabaseMetaData if (_statement != null) { - ((TesterStatement) _statement)._resultSet = null; + ((TesterStatement) _statement).resultSet = null; } _open = false; diff --git a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java index 3357543ca8..0b6479c8fb 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java @@ -28,39 +28,39 @@ */ public class TesterStatement extends AbandonedTrace implements Statement { - protected final Connection _connection; - protected boolean _open = true; - protected final long _rowsUpdated = 1; - protected final boolean _executeResponse = true; - protected int _maxFieldSize = 1024; - protected long _maxRows = 1024; - protected boolean _escapeProcessing; - protected int _queryTimeout = 1000; - protected String _cursorName; - protected int _fetchDirection = 1; - protected int _fetchSize = 1; - protected int _resultSetConcurrency = 1; - protected int _resultSetType = 1; - private int _resultSetHoldability = 1; - protected ResultSet _resultSet; - protected boolean _sqlExceptionOnClose; - - public TesterStatement(final Connection conn) { - _connection = conn; - } - - public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency) { - _connection = conn; - _resultSetType = resultSetType; - _resultSetConcurrency = resultSetConcurrency; - } - - public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency, + protected final Connection connection; + protected boolean open = true; + protected final long rowsUpdated = 1; + protected final boolean executeResponse = true; + protected int maxFieldSize = 1024; + protected long maxRows = 1024; + protected boolean escapeProcessing; + protected int queryTimeout = 1000; + protected String cursorName; + protected int fetchDirection = 1; + protected int fetchSize = 1; + protected int resultSetConcurrency = 1; + protected int resultSetType = 1; + private int resultSetHoldability = 1; + protected ResultSet resultSet; + protected boolean sqlExceptionOnClose; + + public TesterStatement(final Connection connection) { + this.connection = connection; + } + + public TesterStatement(final Connection connection, final int resultSetType, final int resultSetConcurrency) { + this.connection = connection; + this.resultSetType = resultSetType; + this.resultSetConcurrency = resultSetConcurrency; + } + + public TesterStatement(final Connection connection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { - _connection = conn; - _resultSetType = resultSetType; - _resultSetConcurrency = resultSetConcurrency; - _resultSetHoldability = resultSetHoldability; + this.connection = connection; + this.resultSetType = resultSetType; + this.resultSetConcurrency = resultSetConcurrency; + this.resultSetHoldability = resultSetHoldability; } @Override @@ -74,7 +74,7 @@ public void cancel() throws SQLException { } protected void checkOpen() throws SQLException { - if (!_open) { + if (!open) { throw new SQLException("Connection is closed."); } } @@ -91,19 +91,19 @@ public void clearWarnings() throws SQLException { @Override public void close() throws SQLException { - if (_sqlExceptionOnClose) { + if (sqlExceptionOnClose) { throw new SQLException("TestSQLExceptionOnClose"); } // calling close twice has no effect - if (!_open) { + if (!open) { return; } - _open = false; - if (_resultSet != null) { - _resultSet.close(); - _resultSet = null; + open = false; + if (resultSet != null) { + resultSet.close(); + resultSet = null; } } @@ -118,7 +118,7 @@ public boolean execute(final String sql) throws SQLException { if ("invalid".equals(sql)) { throw new SQLException("invalid query"); } - return _executeResponse; + return executeResponse; } @Override @@ -154,7 +154,7 @@ public long[] executeLargeBatch() throws SQLException { @Override public long executeLargeUpdate(final String sql) throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override @@ -185,12 +185,12 @@ public ResultSet executeQuery(final String sql) throws SQLException { throw new SQLException("broken connection"); } if ("select username".equals(sql)) { - final String userName = ((TesterConnection) _connection).getUserName(); + final String userName = ((TesterConnection) connection).getUserName(); final Object[][] data = { { userName } }; return new TesterResultSet(this, data); } // Simulate timeout if queryTimout is set to less than 5 seconds - if (_queryTimeout > 0 && _queryTimeout < 5) { + if (queryTimeout > 0 && queryTimeout < 5) { throw new SQLException("query timeout"); } return new TesterResultSet(this); @@ -199,7 +199,7 @@ public ResultSet executeQuery(final String sql) throws SQLException { @Override public int executeUpdate(final String sql) throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override @@ -220,19 +220,19 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ @Override public Connection getConnection() throws SQLException { checkOpen(); - return _connection; + return connection; } @Override public int getFetchDirection() throws SQLException { checkOpen(); - return _fetchDirection; + return fetchDirection; } @Override public int getFetchSize() throws SQLException { checkOpen(); - return _fetchSize; + return fetchSize; } @Override @@ -243,25 +243,25 @@ public ResultSet getGeneratedKeys() throws SQLException { @Override public long getLargeMaxRows() throws SQLException { checkOpen(); - return _maxRows; + return maxRows; } @Override public long getLargeUpdateCount() throws SQLException { checkOpen(); - return _rowsUpdated; + return rowsUpdated; } @Override public int getMaxFieldSize() throws SQLException { checkOpen(); - return _maxFieldSize; + return maxFieldSize; } @Override public int getMaxRows() throws SQLException { checkOpen(); - return (int) _maxRows; + return (int) maxRows; } @Override @@ -278,40 +278,40 @@ public boolean getMoreResults(final int current) throws SQLException { @Override public int getQueryTimeout() throws SQLException { checkOpen(); - return _queryTimeout; + return queryTimeout; } @Override public ResultSet getResultSet() throws SQLException { checkOpen(); - if (_resultSet == null) { - _resultSet = new TesterResultSet(this); + if (resultSet == null) { + resultSet = new TesterResultSet(this); } - return _resultSet; + return resultSet; } @Override public int getResultSetConcurrency() throws SQLException { checkOpen(); - return _resultSetConcurrency; + return resultSetConcurrency; } @Override public int getResultSetHoldability() throws SQLException { checkOpen(); - return _resultSetHoldability; + return resultSetHoldability; } @Override public int getResultSetType() throws SQLException { checkOpen(); - return _resultSetType; + return resultSetType; } @Override public int getUpdateCount() throws SQLException { checkOpen(); - return (int) _rowsUpdated; + return (int) rowsUpdated; } @Override @@ -322,7 +322,7 @@ public SQLWarning getWarnings() throws SQLException { @Override public boolean isClosed() throws SQLException { - return !_open; + return !open; } @Override @@ -336,7 +336,7 @@ public boolean isPoolable() throws SQLException { } public boolean isSqlExceptionOnClose() { - return _sqlExceptionOnClose; + return sqlExceptionOnClose; } @Override @@ -347,43 +347,43 @@ public boolean isWrapperFor(final Class iface) throws SQLException { @Override public void setCursorName(final String name) throws SQLException { checkOpen(); - _cursorName = name; + this.cursorName = name; } @Override public void setEscapeProcessing(final boolean enable) throws SQLException { checkOpen(); - _escapeProcessing = enable; + this.escapeProcessing = enable; } @Override public void setFetchDirection(final int direction) throws SQLException { checkOpen(); - _fetchDirection = direction; + this.fetchDirection = direction; } @Override public void setFetchSize(final int rows) throws SQLException { checkOpen(); - _fetchSize = rows; + this.fetchSize = rows; } @Override public void setLargeMaxRows(final long max) throws SQLException { checkOpen(); - _maxRows = max; + this.maxRows = max; } @Override public void setMaxFieldSize(final int max) throws SQLException { checkOpen(); - _maxFieldSize = max; + this.maxFieldSize = max; } @Override public void setMaxRows(final int max) throws SQLException { checkOpen(); - _maxRows = max; + this.maxRows = max; } @Override @@ -394,11 +394,11 @@ public void setPoolable(final boolean poolable) throws SQLException { @Override public void setQueryTimeout(final int seconds) throws SQLException { checkOpen(); - _queryTimeout = seconds; + this.queryTimeout = seconds; } public void setSqlExceptionOnClose(final boolean _sqlExceptionOnClose) { - this._sqlExceptionOnClose = _sqlExceptionOnClose; + this.sqlExceptionOnClose = _sqlExceptionOnClose; } @Override From 759a88c61618a713b6147931ea458a55d1ecdefb Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 14 Jul 2024 12:50:23 -0400 Subject: [PATCH 018/169] Use import not FQCN --- src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java | 2 +- .../apache/commons/dbcp2/TestParallelCreationWithNoIdle.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java index acee1c87b8..6376cca881 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java +++ b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java @@ -164,7 +164,7 @@ public void stop() { } final class TestThread implements Runnable { - final java.util.Random random = new java.util.Random(); + final Random random = new Random(); boolean complete; boolean failed; int iter = 100; diff --git a/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java b/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java index 3b2ea0e1a6..48ea4aace6 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java +++ b/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Random; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,7 +37,7 @@ public class TestParallelCreationWithNoIdle { final class TestThread extends Thread { - final java.util.Random random = new java.util.Random(); + final Random random = new Random(); final int iter; final int delay; final int delayAfter; From db958c7b6b53fc4d90b3761c9ef16417b021987e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:41:00 -0400 Subject: [PATCH 019/169] Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 (#404) Bumps org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4ad507fe57..b95d642d7c 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ org.apache.commons commons-lang3 - 3.14.0 + 3.15.0 test From 583f269e913c3d84d2b8ec940c21c8b7b7e66ac3 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 17 Jul 2024 18:41:40 -0400 Subject: [PATCH 020/169] Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404 --- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8f3bef3451..532bd7b209 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,6 +75,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 71 #360, #371, #395. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. + Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404. From ee5d7a9e27f8c4212eb64d4cfe64fb95ec09a4e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jul 2024 00:25:10 -0400 Subject: [PATCH 021/169] Bump github/codeql-action from 3.25.11 to 3.25.12 (#405) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.11 to 3.25.12. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/b611370bb5703a7efb587f9d136a52ea24c5c38c...4fa2a7953630fd2f3fb380f21be14ede0169dd4f) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 492ed75027..fe8dabbcef 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 + uses: github/codeql-action/init@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 + uses: github/codeql-action/autobuild@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 + uses: github/codeql-action/analyze@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 9c3dcf97c1..381f78a949 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@b611370bb5703a7efb587f9d136a52ea24c5c38c # 3.25.11 + uses: github/codeql-action/upload-sarif@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 with: sarif_file: results.sarif From da714d524d3b93939844e18e19b3959a725869dc Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 21 Jul 2024 11:29:37 -0400 Subject: [PATCH 022/169] Javadoc Use HTML 'em' tag instead of 'i' tag --- .../org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java | 2 +- .../java/org/apache/commons/dbcp2/managed/package-info.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java index 481acaf355..6281592127 100644 --- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java +++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java @@ -700,7 +700,7 @@ public void setMinEvictableIdleTimeMillis(final int minEvictableIdleTimeMillis) *

* When a negative value is supplied, * {@code ceil({@link BasicDataSource#getNumIdle})/abs({@link #getNumTestsPerEvictionRun})} tests will be run. - * I.e., when the value is -n, roughly one nth of the idle objects will be tested per run. + * I.e., when the value is -n, roughly one nth of the idle objects will be tested per run. *

* * @param numTestsPerEvictionRun number of statements to examine per run diff --git a/src/main/java/org/apache/commons/dbcp2/managed/package-info.java b/src/main/java/org/apache/commons/dbcp2/managed/package-info.java index f0bc5210fe..7e613e7b9c 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/package-info.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/package-info.java @@ -19,7 +19,7 @@ *

* This package provides support for pooling of ManagedConnections. A managed * connection is responsible for managing a database connection in a - * transactional environment (typically called Container Managed). + * transactional environment (typically called Container Managed). * A managed connection operates like any other connection when no global * transaction (a.k.a. XA transaction or JTA Transaction) is in progress. * When a global transaction is active a single physical connection to the From f5a4211e26d0842cb03c2c9d9a8b5e2e5b556c8c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 22 Jul 2024 08:44:46 -0400 Subject: [PATCH 023/169] Add Java 22 to the GitHub CI build --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 65a377ca23..3c7f2ac814 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,7 +27,7 @@ jobs: continue-on-error: ${{ matrix.experimental }} strategy: matrix: - java: [ 8, 11, 17, 21 ] + java: [ 8, 11, 17, 21, 22 ] experimental: [false] # include: # - java: 22-ea From 33762a662624d14a6645b0a4c2543851eedf1ae0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 22 Jul 2024 08:45:02 -0400 Subject: [PATCH 024/169] Add Java 23-ea as an experimental build --- .github/workflows/maven.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3c7f2ac814..d383592eb1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,9 +29,9 @@ jobs: matrix: java: [ 8, 11, 17, 21, 22 ] experimental: [false] -# include: -# - java: 22-ea -# experimental: true + include: + - java: 23-ea + experimental: true steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 From 51f3e985b54f2afe5ecf850af2bbf4395c261699 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 22 Jul 2024 08:50:11 -0400 Subject: [PATCH 025/169] Add Java 24-ea as an experimental build --- .github/workflows/maven.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d383592eb1..b2cf2b9d7b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -32,6 +32,8 @@ jobs: include: - java: 23-ea experimental: true + - java: 24-ea + experimental: true steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 From 8277232afe4ea0635cb9ab2525a1a60dcc116205 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:39:47 -0400 Subject: [PATCH 026/169] Bump github/codeql-action from 3.25.12 to 3.25.14 (#406) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.12 to 3.25.14. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/4fa2a7953630fd2f3fb380f21be14ede0169dd4f...5cf07d8b700b67e235fbb65cbc84f69c0cf10464) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index fe8dabbcef..43e10c73d6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 + uses: github/codeql-action/init@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 + uses: github/codeql-action/autobuild@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 + uses: github/codeql-action/analyze@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 381f78a949..a69fb1b9d3 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@4fa2a7953630fd2f3fb380f21be14ede0169dd4f # 3.25.12 + uses: github/codeql-action/upload-sarif@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 with: sarif_file: results.sarif From 0b5ca3c50716ca136a532f92dc56bd1fb91f0305 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 26 Jul 2024 18:34:34 -0400 Subject: [PATCH 027/169] Remove useless comments --- src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java | 1 - .../org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java | 1 - src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java | 1 - 3 files changed, 3 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java b/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java index 1f7c0aa000..4762107e45 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java @@ -164,7 +164,6 @@ public Connection getConnection(final String userName, final String password) th throw new UnsupportedOperationException(); } - // --- DataSource methods ----------------------------------------- /** * Throws {@link UnsupportedOperationException}. diff --git a/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java index bdaac7803b..0f6232a490 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java @@ -53,7 +53,6 @@ private void assertAndReset(final DelegatingConnection con) { con.setLastUsed(Instant.EPOCH); } - // ---------- Abandoned Test ----------- /** * Verifies that PreparedStatement executeXxx methods update lastUsed on the parent connection diff --git a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java index 6376cca881..7f09aab92a 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java +++ b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java @@ -232,7 +232,6 @@ public void run() { /** Connections opened during the course of a test */ protected final Stack connectionStack = new Stack<>(); - // ----------- Utility Methods --------------------------------- protected void assertBackPointers(final Connection conn, final Statement statement) throws SQLException { assertFalse(conn.isClosed()); From 4124a54b96ff20cc9ebe61c91f93360d5bc04df3 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 29 Jul 2024 07:50:34 -0400 Subject: [PATCH 028/169] Use Javadoc @link --- .../dbcp2/datasources/InstanceKeyDataSource.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java index 9ec3451b27..636209522a 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java @@ -1109,18 +1109,15 @@ public void setLogWriter(final PrintWriter logWriter) { /** *

- * Sets the maximum permitted lifetime of a connection. A value of zero or less indicates an - * infinite lifetime. + * Sets the maximum permitted lifetime of a connection. A value of zero or less indicates an infinite lifetime. *

*

- * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the following methods is + * invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, {@link #setLoginTimeout(Duration)}, {@link #getLoginTimeoutDuration()}, + * {@link #getLogWriter()}. *

* - * @param maxConnLifetimeMillis - * The maximum permitted lifetime of a connection. A value of zero or less indicates an - * infinite lifetime. + * @param maxConnLifetimeMillis The maximum permitted lifetime of a connection. A value of zero or less indicates an infinite lifetime. * @since 2.9.0 */ public void setMaxConnLifetime(final Duration maxConnLifetimeMillis) { From e6ab6936df70f14eeea50f88360acb79a5aeb098 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 29 Jul 2024 07:51:29 -0400 Subject: [PATCH 029/169] Use Javadoc @link --- .../dbcp2/datasources/InstanceKeyDataSource.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java index 636209522a..4fd5ff293e 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java @@ -1126,18 +1126,15 @@ public void setMaxConnLifetime(final Duration maxConnLifetimeMillis) { /** *

- * Sets the maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an - * infinite lifetime. + * Sets the maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime. *

*

- * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the following methods is + * invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, {@link #setLoginTimeout(Duration)}, {@link #getLoginTimeoutDuration()}, + * {@link #getLogWriter()}. *

* - * @param maxConnLifetimeMillis - * The maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an - * infinite lifetime. + * @param maxConnLifetimeMillis The maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime. * @deprecated Use {@link #setMaxConnLifetime(Duration)}. */ @Deprecated From 414974b6efce132bfa74e54184733468f8fefca5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 29 Jul 2024 07:52:16 -0400 Subject: [PATCH 030/169] Use Javadoc @link --- .../commons/dbcp2/managed/BasicManagedDataSource.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java index 52570bea49..9f83f36e1a 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java @@ -234,17 +234,14 @@ public synchronized void setXADataSource(final String xaDataSource) { } /** - *

* Sets the XADataSource instance used by the XAConnectionFactory. - *

*

- * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the following methods is + * invoked: {@link #getConnection()}, {@link #setLogWriter(java.io.PrintWriter)}, {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, + * {@link #getLogWriter()}. *

* - * @param xaDataSourceInstance - * XADataSource instance + * @param xaDataSourceInstance XADataSource instance */ public synchronized void setXaDataSourceInstance(final XADataSource xaDataSourceInstance) { this.xaDataSourceInstance = xaDataSourceInstance; From f3e28588a98c916f355c4dd19d05824746e09e61 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 29 Jul 2024 07:54:16 -0400 Subject: [PATCH 031/169] Use Javadoc @link --- .../apache/commons/dbcp2/BasicDataSource.java | 88 +++++++++---------- .../dbcp2/managed/BasicManagedDataSource.java | 2 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index ed58c7aef2..45511a3fa5 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -1729,8 +1729,8 @@ public void setAbandonedUsageTracking(final boolean usageTracking) { * the underlying connection. (Default: false) *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param allow Access to the underlying connection is granted when true. @@ -1786,8 +1786,8 @@ public void setConnectionFactoryClassName(final String connectionFactoryClassNam * Sets the collection of SQL statements to be executed when a physical connection is first created. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param connectionInitSqls Collection of SQL statements to execute on connection creation @@ -1802,8 +1802,8 @@ public void setConnectionInitSqls(final Collection connectionInitSqls) { * Sets the list of SQL statements to be executed when a physical connection is first created. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param connectionInitSqls List of SQL statements to execute on connection creation @@ -1853,8 +1853,8 @@ public void setConnectionProperties(final String connectionProperties) { * Sets default auto-commit state of connections returned by this datasource. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param defaultAutoCommit default auto-commit value @@ -1867,8 +1867,8 @@ public void setDefaultAutoCommit(final Boolean defaultAutoCommit) { * Sets the default catalog. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param defaultCatalog the default catalog @@ -1904,8 +1904,8 @@ public void setDefaultQueryTimeout(final Integer defaultQueryTimeoutSeconds) { * Sets defaultReadonly property. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param defaultReadOnly default read-only value @@ -1918,8 +1918,8 @@ public void setDefaultReadOnly(final Boolean defaultReadOnly) { * Sets the default schema. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param defaultSchema the default catalog @@ -1933,8 +1933,8 @@ public void setDefaultSchema(final String defaultSchema) { * Sets the default transaction isolation state for returned connections. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param defaultTransactionIsolation the default transaction isolation state @@ -1975,8 +1975,8 @@ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCo * Sets the JDBC Driver instance to use for this pool. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param driver The JDBC Driver instance to use for this pool. @@ -1989,8 +1989,8 @@ public synchronized void setDriver(final Driver driver) { * Sets the class loader to be used to load the JDBC driver. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param driverClassLoader the class loader with which to load the JDBC driver @@ -2003,8 +2003,8 @@ public synchronized void setDriverClassLoader(final ClassLoader driverClassLoade * Sets the JDBC driver class name. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param driverClassName the class name of the JDBC driver @@ -2062,8 +2062,8 @@ public void setFastFailValidation(final boolean fastFailValidation) { * Sets the initial size of the connection pool. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param initialSize the number of connections created when the pool is initialized @@ -2155,8 +2155,8 @@ public void setLogWriter(final PrintWriter logWriter) throws SQLException { * infinite lifetime. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param maxConnDuration The maximum permitted lifetime of a connection. @@ -2171,8 +2171,8 @@ public void setMaxConn(final Duration maxConnDuration) { * infinite lifetime. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param maxConnLifetimeMillis The maximum permitted lifetime of a connection in milliseconds. @@ -2199,8 +2199,8 @@ public synchronized void setMaxIdle(final int maxIdle) { * Sets the value of the {@code maxOpenPreparedStatements} property. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param maxOpenStatements the new maximum number of prepared statements @@ -2297,8 +2297,8 @@ public synchronized void setNumTestsPerEvictionRun(final int numTestsPerEviction * Sets the {code password}. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param password new value for the password @@ -2311,8 +2311,8 @@ public void setPassword(final String password) { * Sets whether to pool statements or not. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param poolingStatements pooling on or off @@ -2483,8 +2483,8 @@ public synchronized void setTimeBetweenEvictionRunsMillis(final long timeBetween * Sets the {code connection string}. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param connectionString the new value for the JDBC connection connectionString @@ -2497,8 +2497,8 @@ public synchronized void setUrl(final String connectionString) { * Sets the {code userName}. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param userName the new value for the JDBC connection user name @@ -2511,8 +2511,8 @@ public void setUsername(final String userName) { * Sets the {code validationQuery}. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param validationQuery the new value for the validation query @@ -2526,8 +2526,8 @@ public void setValidationQuery(final String validationQuery) { * response from the database when executing a validation query. Use a value less than or equal to 0 for no timeout. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param validationQueryTimeoutDuration new validation query timeout value in seconds @@ -2542,8 +2542,8 @@ public void setValidationQueryTimeout(final Duration validationQueryTimeoutDurat * response from the database when executing a validation query. Use a value less than or equal to 0 for no timeout. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter. + * time one of the following methods is invoked: {@link #getConnection()}, {@link #setLogWriter(PrintWriter)}, + * {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, {@link #getLogWriter()}. *

* * @param validationQueryTimeoutSeconds new validation query timeout value in seconds diff --git a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java index 9f83f36e1a..719ee4d09c 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java @@ -238,7 +238,7 @@ public synchronized void setXADataSource(final String xaDataSource) { *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the following methods is * invoked: {@link #getConnection()}, {@link #setLogWriter(java.io.PrintWriter)}, {@link #setLoginTimeout(int)}, {@link #getLoginTimeout()}, - * {@link #getLogWriter()}. + * {@link #getLogWriter()}. *

* * @param xaDataSourceInstance XADataSource instance From 5d610dcde083f9abb2d3069a630871bb676f7255 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 29 Jul 2024 16:37:58 -0400 Subject: [PATCH 032/169] Use Javadoc @code and @link --- src/test/java/org/apache/commons/dbcp2/TesterDriver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TesterDriver.java b/src/test/java/org/apache/commons/dbcp2/TesterDriver.java index adf3b8c3d8..6f2c18623e 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterDriver.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterDriver.java @@ -27,8 +27,8 @@ import java.util.logging.Logger; /** - * Mock object implementing the java.sql.Driver interface. - * Returns TestConnection's from getConnection methods. + * Mock object implementing the {@link Driver} interface. + * Returns {@code TestConnection}'s from getConnection methods. * Valid user name, password combinations are: * * From a2f666715236d2a9f1d4d769ba2564e3d0c3defe Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 30 Jul 2024 08:52:05 -0400 Subject: [PATCH 033/169] Bump org.apache.commons:commons-parent from 71 to 72 --- pom.xml | 2 +- src/changes/changes.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b95d642d7c..88aa62385f 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-parent - 71 + 72 4.0.0 commons-dbcp2 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 532bd7b209..cb45e464ff 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -73,7 +73,7 @@ The type attribute can be add,update,fix,remove. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. - Bump org.apache.commons:commons-parent from 66 to 71 #360, #371, #395. + Bump org.apache.commons:commons-parent from 66 to 72 #360, #371, #395. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404. From 560ffccc48095c9706cdad3b2379afeb8a1b5fe3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 08:12:40 -0400 Subject: [PATCH 034/169] Bump org.hamcrest:hamcrest from 2.2 to 3.0 (#409) Bumps [org.hamcrest:hamcrest](https://github.com/hamcrest/JavaHamcrest) from 2.2 to 3.0. - [Release notes](https://github.com/hamcrest/JavaHamcrest/releases) - [Changelog](https://github.com/hamcrest/JavaHamcrest/blob/master/CHANGES.md) - [Commits](https://github.com/hamcrest/JavaHamcrest/compare/v2.2...v3.0) --- updated-dependencies: - dependency-name: org.hamcrest:hamcrest dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 88aa62385f..58f2a10162 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ org.hamcrest hamcrest - 2.2 + 3.0 test From 27a7818eb1d122af60538459e8daf7eee190a955 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 2 Aug 2024 08:13:19 -0400 Subject: [PATCH 035/169] Bump org.hamcrest:hamcrest from 2.2 to 3.0 #409 --- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cb45e464ff..672e71b8a7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -76,6 +76,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 72 #360, #371, #395. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404. + Bump org.hamcrest:hamcrest from 2.2 to 3.0 #409. From c9cfd334fdc7685493f15d1e6d46b0874eaee7f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 08:13:42 -0400 Subject: [PATCH 036/169] Bump ossf/scorecard-action from 2.3.3 to 2.4.0 (#408) Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.3.3 to 2.4.0. - [Release notes](https://github.com/ossf/scorecard-action/releases) - [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md) - [Commits](https://github.com/ossf/scorecard-action/compare/dc50aa9510b46c811795eb24b2f1ba02a914e534...62b2cac7ed8198b15735ed49ab1e5cf35480ba46) --- updated-dependencies: - dependency-name: ossf/scorecard-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/scorecards-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index a69fb1b9d3..557283e35f 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -45,7 +45,7 @@ jobs: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # 2.3.3 + uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # 2.4.0 with: results_file: results.sarif results_format: sarif From 80e023778edace2aa25e5e748ac351b0d5989968 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 2 Aug 2024 10:09:43 -0400 Subject: [PATCH 037/169] Put Hamcreset last on the classpath Local build OK without this but fails on GitHub --- pom.xml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 58f2a10162..999290c92f 100644 --- a/pom.xml +++ b/pom.xml @@ -72,13 +72,6 @@ test - - org.hamcrest - hamcrest - 3.0 - test - - org.mockito mockito-core @@ -170,6 +163,12 @@ 3.4.3.Final test + + org.hamcrest + hamcrest + 3.0 + test + From 3ae4669c9c70998e45027db37b8054cf9a5aa1ca Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 2 Aug 2024 10:52:30 -0400 Subject: [PATCH 038/169] Undo bump org.hamcrest:hamcrest from 2.2 to 3.0 OK locally but not on GitHub? --- pom.xml | 2 +- src/changes/changes.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 999290c92f..20b703d8ca 100644 --- a/pom.xml +++ b/pom.xml @@ -166,7 +166,7 @@ org.hamcrest hamcrest - 3.0 + 2.0 test diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 672e71b8a7..cb45e464ff 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -76,7 +76,6 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 72 #360, #371, #395. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404. - Bump org.hamcrest:hamcrest from 2.2 to 3.0 #409. From 7cd898c8e9a027e68c8802be1bd4f3d0c1cb3460 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 2 Aug 2024 10:56:52 -0400 Subject: [PATCH 039/169] Undo bump org.hamcrest:hamcrest from 2.2 to 3.0 OK locally but not on GitHub? --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 20b703d8ca..e82fdd936c 100644 --- a/pom.xml +++ b/pom.xml @@ -166,7 +166,7 @@ org.hamcrest hamcrest - 2.0 + 2.2 test From 54e94fde1c12c25ee59fa671d3e14d2f0f87db3c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:00:51 -0400 Subject: [PATCH 040/169] Bump github/codeql-action from 3.25.14 to 3.25.15 (#407) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.14 to 3.25.15. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/5cf07d8b700b67e235fbb65cbc84f69c0cf10464...afb54ba388a7dca6ecae48f608c4ff05ff4cc77a) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 43e10c73d6..bc8bcc758b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 + uses: github/codeql-action/init@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 + uses: github/codeql-action/autobuild@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 + uses: github/codeql-action/analyze@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 557283e35f..b7e502326d 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@5cf07d8b700b67e235fbb65cbc84f69c0cf10464 # 3.25.14 + uses: github/codeql-action/upload-sarif@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 with: sarif_file: results.sarif From 2a4e520c913f047174206e74b58a9310a0b45751 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Aug 2024 07:25:18 -0400 Subject: [PATCH 041/169] Try a different way to initial tests for GitHub failures --- .../commons/dbcp2/AbstractDriverTest.java | 45 +++++++++++++++++++ .../TestDriverManagerConnectionFactory.java | 16 +------ .../apache/commons/dbcp2/TesterDriver.java | 4 ++ 3 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 src/test/java/org/apache/commons/dbcp2/AbstractDriverTest.java diff --git a/src/test/java/org/apache/commons/dbcp2/AbstractDriverTest.java b/src/test/java/org/apache/commons/dbcp2/AbstractDriverTest.java new file mode 100644 index 0000000000..b1f28dac91 --- /dev/null +++ b/src/test/java/org/apache/commons/dbcp2/AbstractDriverTest.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.dbcp2; + +import java.sql.DriverManager; +import java.sql.SQLException; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; + +/** + * Abstracts testing a JDBC driver. + */ +public abstract class AbstractDriverTest { + + //private static final String KEY_JDBC_DRIVERS = "jdbc.drivers"; + + @AfterAll + public static void afterClass() throws SQLException { + //System.clearProperty(KEY_JDBC_DRIVERS); + DriverManager.deregisterDriver(TesterDriver.INSTANCE); + } + + @BeforeAll + public static void beforeClass() throws SQLException { + //System.setProperty(KEY_JDBC_DRIVERS, "org.apache.commons.dbcp2.TesterDriver"); + DriverManager.registerDriver(TesterDriver.INSTANCE); + } + +} diff --git a/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java b/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java index 673f4bb162..ce6b368c9d 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java +++ b/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java @@ -28,8 +28,6 @@ import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** @@ -37,7 +35,7 @@ * the initialization of DriverManager. * Based on the test case for DBCP-212 written by Marcos Sanz */ -public class TestDriverManagerConnectionFactory { +public class TestDriverManagerConnectionFactory extends AbstractDriverTest { private static final class ConnectionThread implements Runnable { private final DataSource ds; @@ -77,18 +75,6 @@ public String toString() { } } - private static final String KEY_JDBC_DRIVERS = "jdbc.drivers"; - - @AfterAll - public static void afterClass() { - System.clearProperty(KEY_JDBC_DRIVERS); - } - - @BeforeAll - public static void beforeClass() { - System.setProperty(KEY_JDBC_DRIVERS, "org.apache.commons.dbcp2.TesterDriver"); - } - @Test public void testDriverManagerCredentialsInUrl() throws SQLException { final DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver;user=foo;password=bar", null, (char[]) null); diff --git a/src/test/java/org/apache/commons/dbcp2/TesterDriver.java b/src/test/java/org/apache/commons/dbcp2/TesterDriver.java index 6f2c18623e..5f3c71fab6 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterDriver.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterDriver.java @@ -40,7 +40,11 @@ *
*/ public class TesterDriver implements Driver { + + static TesterDriver INSTANCE = new TesterDriver(); + private static final Properties validUserPasswords = new Properties(); + static { try { DriverManager.registerDriver(new TesterDriver()); From 082ded3c409bdac13dd8d8d20bb7d51dff5d6f6c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Aug 2024 07:29:06 -0400 Subject: [PATCH 042/169] Use assertThrows() Longer lines --- .../commons/dbcp2/TestPoolableConnection.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java index 3a9f2e2ac0..30611d8c0e 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; @@ -42,9 +43,7 @@ public class TestPoolableConnection { @BeforeEach public void setUp() throws Exception { final PoolableConnectionFactory factory = new PoolableConnectionFactory( - new DriverConnectionFactory( - new TesterDriver(),"jdbc:apache:commons:testdriver", null), - null); + new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", null), null); factory.setDefaultAutoCommit(Boolean.TRUE); factory.setDefaultReadOnly(Boolean.TRUE); @@ -149,14 +148,9 @@ public void testFastFailValidationCustomCodes() throws Exception { // Set up fatal exception nativeConnection.setFailure(new SQLException("Fatal connection error.", "XXX")); - - try { - conn.createStatement(); - fail("Should throw SQL exception."); - } catch (final SQLException ignored) { - // cleanup failure - nativeConnection.setFailure(null); - } + assertThrows(SQLException.class, conn::createStatement); + // cleanup failure + nativeConnection.setFailure(null); // verify that bad connection does not get returned to the pool conn.close(); // testOnReturn triggers validate, which should fail From 01d4211b29376c85ee0de4934f40a3834718f184 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Aug 2024 07:37:23 -0400 Subject: [PATCH 043/169] Bump org.hamcrest:hamcrest from 2.2 to 3.0 (#410) Bumps [org.hamcrest:hamcrest](https://github.com/hamcrest/JavaHamcrest) from 2.2 to 3.0. - [Release notes](https://github.com/hamcrest/JavaHamcrest/releases) - [Changelog](https://github.com/hamcrest/JavaHamcrest/blob/master/CHANGES.md) - [Commits](https://github.com/hamcrest/JavaHamcrest/compare/v2.2...v3.0) --- updated-dependencies: - dependency-name: org.hamcrest:hamcrest dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e82fdd936c..999290c92f 100644 --- a/pom.xml +++ b/pom.xml @@ -166,7 +166,7 @@ org.hamcrest hamcrest - 2.2 + 3.0 test From ffe8d43deed0a77e2d53e8866798b1fea10f62e2 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Aug 2024 07:38:02 -0400 Subject: [PATCH 044/169] Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410 --- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cb45e464ff..12ce5041f5 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -76,6 +76,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 72 #360, #371, #395. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404. + Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410.
From 49fa99ae08766e3e332963f408b7a361cc541765 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Aug 2024 07:38:23 -0400 Subject: [PATCH 045/169] Use assertThrows() --- .../cpdsadapter/TestDriverAdapterCPDS.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java index 6fc6042f1d..68573f42e4 100644 --- a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java +++ b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java @@ -290,30 +290,15 @@ public void testGettersAndSetters() { * JIRA: DBCP-245 */ @Test - public void testIncorrectPassword() throws Exception - { + public void testIncorrectPassword() throws Exception { pcds.getPooledConnection("u2", "p2").close(); - try { - // Use bad password - pcds.getPooledConnection("u1", "zlsafjk"); - fail("Able to retrieve connection with incorrect password"); - } catch (final SQLException e1) { - // should fail - - } + // Use bad password + assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "zlsafjk"), "Able to retrieve connection with incorrect password"); // Use good password - pcds.getPooledConnection("u1", "p1").close(); - try { - pcds.getPooledConnection("u1", "x"); - fail("Able to retrieve connection with incorrect password"); - } - catch (final SQLException e) { - if (!e.getMessage().startsWith("x is not the correct password")) { - throw e; - } - // else the exception was expected - } + SQLException e = assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "x"), "Able to retrieve connection with incorrect password"); + assertTrue(e.getMessage().startsWith("x is not the correct password")); + // else the exception was expected // Make sure we can still use our good password. pcds.getPooledConnection("u1", "p1").close(); From a03b858896eee3fb417a2b29db61c04e607c642d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Aug 2024 07:40:30 -0400 Subject: [PATCH 046/169] Use assertThrows() Longer lines --- .../TestPerUserPoolDataSource.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java index 529c6beb71..9cfc774dc8 100644 --- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java @@ -90,7 +90,9 @@ public void tearDown() throws Exception { ((PerUserPoolDataSource) ds).close(); } - // See DBCP-8 + /** + * See DBCP-8 + */ @Test public void testChangePassword() throws Exception { assertThrows(SQLException.class, () -> ds.getConnection(user, "bay")); @@ -99,28 +101,23 @@ public void testChangePassword() throws Exception { final Connection con3 = ds.getConnection(user, "bar"); con1.close(); con2.close(); - TesterDriver.addUser(user,"bay"); // change the user/password setting + TesterDriver.addUser(user, "bay"); // change the user/password setting try { final Connection con4 = ds.getConnection(user, "bay"); // new password // Idle instances with old password should have been cleared - assertEquals(0, ((PerUserPoolDataSource) ds).getNumIdle(user), - "Should be no idle connections in the pool"); + assertEquals(0, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be no idle connections in the pool"); con4.close(); // Should be one idle instance with new pwd - assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), - "Should be one idle connection in the pool"); - try (Connection c = ds.getConnection(user, "bar")) { // old password - fail("Should have generated SQLException"); - } catch (final SQLException expected) { - } + assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool"); + // old password + assertThrows(SQLException.class, () -> ds.getConnection(user, "bar"), "Should have generated SQLException"); final Connection con5 = ds.getConnection(user, "bay"); // take the idle one con3.close(); // Return a connection with the old password - ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it - assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), - "Should be one idle connection in the pool"); + ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it + assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool"); con5.close(); } finally { - TesterDriver.addUser(user,"bar"); + TesterDriver.addUser(user, "bar"); } } From 5a2f73466e64e410d314db89e858867af8422108 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 3 Aug 2024 07:41:05 -0400 Subject: [PATCH 047/169] Use try-with-resources --- .../dbcp2/datasources/TestPerUserPoolDataSource.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java index 9cfc774dc8..d74edc9fd8 100644 --- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java @@ -111,11 +111,11 @@ public void testChangePassword() throws Exception { assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool"); // old password assertThrows(SQLException.class, () -> ds.getConnection(user, "bar"), "Should have generated SQLException"); - final Connection con5 = ds.getConnection(user, "bay"); // take the idle one - con3.close(); // Return a connection with the old password - ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it - assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool"); - con5.close(); + try (Connection con5 = ds.getConnection(user, "bay")) { // take the idle one + con3.close(); // Return a connection with the old password + ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it + assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool"); + } } finally { TesterDriver.addUser(user, "bar"); } From 4a7a6576af829fc08a8cfd5d933866ab96f35466 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 6 Aug 2024 08:39:19 -0400 Subject: [PATCH 048/169] Javadoc --- src/main/java/org/apache/commons/dbcp2/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index 8652cae12e..d5c75f8b86 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -179,7 +179,7 @@ public static void closeQuietly(final Statement statement) { *
  • JZ0C0 (Sybase disconnect error)
  • *
  • JZ0C1 (Sybase disconnect error)
  • * - * @return SQL codes of fatal connection errors. + * @return A copy SQL codes of fatal connection errors. * @since 2.10.0 */ public static Set getDisconnectionSqlCodes() { From df422388651f61f91828737c5b1b901cccb6fd80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:54:49 -0400 Subject: [PATCH 049/169] Bump org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0 (#412) Bumps org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 999290c92f..3d9cb07bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ org.apache.commons commons-lang3 - 3.15.0 + 3.16.0 test From b8f3139c258f517adc97da32653273bee2a05087 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 7 Aug 2024 14:55:17 -0400 Subject: [PATCH 050/169] Bump org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0 #412 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 12ce5041f5..d5a5335f3b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,7 +75,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 72 #360, #371, #395. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. - Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.15.0 #404. + Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410.
    From 86acffa6ccb93a63acaac06c21757880c8a62e08 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 05:48:52 -0400 Subject: [PATCH 051/169] Bump actions/setup-java from 4.2.1 to 4.2.2 (#414) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.2.1 to 4.2.2. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/99b8673ff64fbf99d8d325f52d9a5bdedb8483e9...6a0805fcefea3d4657a47ac4c165951e33482018) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b2cf2b9d7b..822b7994d4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,7 +46,7 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 + uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 with: distribution: 'temurin' java-version: ${{ matrix.java }} From e44d82ca950176b676bb1ba27bc36506b82cc328 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 05:49:11 -0400 Subject: [PATCH 052/169] Bump github/codeql-action from 3.25.15 to 3.26.0 (#416) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.15 to 3.26.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/afb54ba388a7dca6ecae48f608c4ff05ff4cc77a...eb055d739abdc2e8de2e5f4ba1a8b246daa779aa) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index bc8bcc758b..281af97917 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 + uses: github/codeql-action/init@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 + uses: github/codeql-action/autobuild@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 + uses: github/codeql-action/analyze@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index b7e502326d..2be81a0223 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a # 3.25.15 + uses: github/codeql-action/upload-sarif@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 with: sarif_file: results.sarif From 1f044b0dfb7f593dc7ed7c60acdddf0e0a73a7be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 05:49:23 -0400 Subject: [PATCH 053/169] Bump actions/upload-artifact from 4.3.4 to 4.3.6 (#415) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.4 to 4.3.6. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/0b2256b8c012f0828dc542b3febcab082c67f72b...834a144ee995460fba8ed112a2fc961b36a5ec5a) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/scorecards-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 2be81a0223..bb13f9c0ad 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -57,7 +57,7 @@ jobs: publish_results: true - name: "Upload artifact" - uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # 4.3.4 + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # 4.3.6 with: name: SARIF file path: results.sarif From 69b5d9ddf7566e2f680834d868955ff574ef471a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 08:01:46 -0400 Subject: [PATCH 054/169] Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.15 (#413) Bumps org.slf4j:slf4j-simple from 2.0.13 to 2.0.15. --- updated-dependencies: - dependency-name: org.slf4j:slf4j-simple dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3d9cb07bc0..7567c91e24 100644 --- a/pom.xml +++ b/pom.xml @@ -128,7 +128,7 @@ org.slf4j slf4j-simple - 2.0.13 + 2.0.15 test From 0752fd0e51db0739d56e9cbd198907ac83fe9589 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 9 Aug 2024 08:02:18 -0400 Subject: [PATCH 055/169] Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.15 #413 --- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d5a5335f3b..aac51ae1a3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,6 +77,7 @@ The type attribute can be add,update,fix,remove. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. + Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.15 #413. From 651c9255db72b0f84aaa75c13287dc3ca3e3fcad Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 12 Aug 2024 07:35:37 -0400 Subject: [PATCH 056/169] Javadoc --- .../java/org/apache/commons/dbcp2/BasicDataSource.java | 10 +++++----- .../org/apache/commons/dbcp2/PoolableConnection.java | 4 ++-- .../commons/dbcp2/PoolableConnectionFactory.java | 8 ++++---- src/main/java/org/apache/commons/dbcp2/Utils.java | 4 +++- .../dbcp2/managed/PoolableManagedConnection.java | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index 45511a3fa5..95b756bf78 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -853,7 +853,7 @@ public int getDefaultTransactionIsolation() { } /** - * Gets the set of SQL_STATE codes considered to signal fatal conditions. + * Gets the set of SQL State codes considered to signal fatal conditions. * * @return fatal disconnection state codes * @see #setDisconnectionSqlCodes(Collection) @@ -950,7 +950,7 @@ public synchronized String getEvictionPolicyClassName() { /** * True means that validation will fail immediately for connections that have previously thrown SQLExceptions with - * SQL_STATE indicating fatal disconnection errors. + * SQL State indicating fatal disconnection errors. * * @return true if connections created by this datasource will fast fail validation. * @see #setDisconnectionSqlCodes(Collection) @@ -1945,11 +1945,11 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation } /** - * Sets the SQL_STATE codes considered to signal fatal conditions. + * Sets the SQL State codes considered to signal fatal conditions. *

    * Overrides the defaults in {@link Utils#getDisconnectionSqlCodes()} (plus anything starting with * {@link Utils#DISCONNECTION_SQL_CODE_PREFIX}). If this property is non-null and {@link #getFastFailValidation()} - * is {@code true}, whenever connections created by this datasource generate exceptions with SQL_STATE codes in this + * is {@code true}, whenever connections created by this datasource generate exceptions with SQL State codes in this * list, they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at * isValid or validation query). *

    @@ -1962,7 +1962,7 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation * setLoginTimeout, getLoginTimeout, getLogWriter}. *

    * - * @param disconnectionSqlCodes SQL_STATE codes considered to signal fatal conditions + * @param disconnectionSqlCodes SQL State codes considered to signal fatal conditions * @since 2.1 */ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java index c99e789a55..1497e9e61e 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java @@ -71,7 +71,7 @@ public class PoolableConnection extends DelegatingConnection impleme private boolean fatalSqlExceptionThrown; /** - * SQL_STATE codes considered to signal fatal conditions. Overrides the defaults in + * SQL State codes considered to signal fatal conditions. Overrides the defaults in * {@link Utils#getDisconnectionSqlCodes()} (plus anything starting with {@link Utils#DISCONNECTION_SQL_CODE_PREFIX}). */ private final Collection disconnectionSqlCodes; @@ -104,7 +104,7 @@ public PoolableConnection(final Connection conn, final ObjectPool * Overrides the defaults in {@link Utils#getDisconnectionSqlCodes()} (plus anything starting with * {@link Utils#DISCONNECTION_SQL_CODE_PREFIX}). If this property is non-null and {@link #isFastFailValidation()} is - * {@code true}, whenever connections created by this factory generate exceptions with SQL_STATE codes in this list, + * {@code true}, whenever connections created by this factory generate exceptions with SQL State codes in this list, * they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at isValid or * validation query). *

    @@ -283,7 +283,7 @@ public int getDefaultTransactionIsolation() { * If {@link #isFastFailValidation()} is {@code false} setting this property has no effect. *

    * - * @return SQL_STATE codes overriding defaults + * @return SQL State codes overriding defaults * @since 2.1 */ public Collection getDisconnectionSqlCodes() { @@ -391,7 +391,7 @@ public boolean isEnableAutoCommitOnReturn() { /** * True means that validation will fail immediately for connections that have previously thrown SQLExceptions with - * SQL_STATE indicating fatal disconnection errors. + * SQL State indicating fatal disconnection errors. * * @return true if connections created by this factory will fast fail validation. * @see #setDisconnectionSqlCodes(Collection) diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index d5c75f8b86..fd106d89a3 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -49,7 +49,9 @@ public final class Utils { @Deprecated public static final boolean IS_SECURITY_ENABLED = isSecurityEnabled(); - /** Any SQL_STATE starting with this value is considered a fatal disconnect */ + /** + * Any SQL State starting with this value is considered a fatal disconnect. + */ public static final String DISCONNECTION_SQL_CODE_PREFIX = "08"; /** diff --git a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java index 858a0c4401..29d0585b7b 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java @@ -57,7 +57,7 @@ public PoolableManagedConnection(final TransactionRegistry transactionRegistry, * @param pool * connection pool * @param disconnectSqlCodes - * SQL_STATE codes considered fatal disconnection errors + * SQL State codes considered fatal disconnection errors * @param fastFailValidation * true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to * run query or isValid) From 8768edab5fb6f3d9be1c59d48e318da3c4eea92f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 05:27:19 -0400 Subject: [PATCH 057/169] Bump github/codeql-action from 3.26.0 to 3.26.2 (#417) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.0 to 3.26.2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/eb055d739abdc2e8de2e5f4ba1a8b246daa779aa...429e1977040da7a23b6822b13c129cd1ba93dbb2) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 281af97917..e5d7315bb9 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 + uses: github/codeql-action/init@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 + uses: github/codeql-action/autobuild@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 + uses: github/codeql-action/analyze@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index bb13f9c0ad..5ddf1e85aa 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@eb055d739abdc2e8de2e5f4ba1a8b246daa779aa # 3.26.0 + uses: github/codeql-action/upload-sarif@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 with: sarif_file: results.sarif From 536d9560a25afc2133ed790f93026cc79a741fd1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:23:31 -0400 Subject: [PATCH 058/169] Bump org.slf4j:slf4j-simple from 2.0.15 to 2.0.16 (#418) Bumps org.slf4j:slf4j-simple from 2.0.15 to 2.0.16. --- updated-dependencies: - dependency-name: org.slf4j:slf4j-simple dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7567c91e24..d78c75f97c 100644 --- a/pom.xml +++ b/pom.xml @@ -128,7 +128,7 @@ org.slf4j slf4j-simple - 2.0.15 + 2.0.16 test From 49c846f1c8fbe8fbc085d12b3462edfb1ce32c52 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 16 Aug 2024 08:24:02 -0400 Subject: [PATCH 059/169] Bump org.slf4j:slf4j-simple from 2.0.15 to 2.0.16 #418 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index aac51ae1a3..029e85ffe4 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,7 +77,7 @@ The type attribute can be add,update,fix,remove. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. - Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.15 #413. + Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.16 #413, #418.
    From adfcfbcee8e7084cbe4ddf2b745d3e6a3feb2a32 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:57:22 -0400 Subject: [PATCH 060/169] Bump org.apache.commons:commons-parent from 72 to 73 (#420) Bumps [org.apache.commons:commons-parent](https://github.com/apache/commons-parent) from 72 to 73. - [Changelog](https://github.com/apache/commons-parent/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-parent/commits) --- updated-dependencies: - dependency-name: org.apache.commons:commons-parent dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d78c75f97c..29efb76891 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-parent - 72 + 73 4.0.0 commons-dbcp2 From 04dcb7d601d13669366b952c085674708da3e764 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 18 Aug 2024 10:57:51 -0400 Subject: [PATCH 061/169] Bump org.apache.commons:commons-parent from 72 to 73 (#420) --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 029e85ffe4..435e012a01 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -73,7 +73,7 @@ The type attribute can be add,update,fix,remove. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. - Bump org.apache.commons:commons-parent from 66 to 72 #360, #371, #395. + Bump org.apache.commons:commons-parent from 66 to 73 #360, #371, #395, #420. Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. From 0b4c934d3a5ac63e748e4daca7927bf08063136d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 10:45:58 -0400 Subject: [PATCH 062/169] Bump commons-logging:commons-logging from 1.3.3 to 1.3.4 (#423) Bumps commons-logging:commons-logging from 1.3.3 to 1.3.4. --- updated-dependencies: - dependency-name: commons-logging:commons-logging dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 29efb76891..ac095d0a83 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ commons-logging commons-logging - 1.3.3 + 1.3.4 From 2c13212c6a3a2859a92f929d322630eb4e796292 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 10:46:37 -0400 Subject: [PATCH 063/169] Bump commons-logging:commons-logging from 1.3.3 to 1.3.4 #423 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 435e012a01..e3341bcafe 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -74,7 +74,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 73 #360, #371, #395, #420. - Bump commons-logging:commons-logging from 1.3.0 to 1.3.3 #368, #399. + Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.16 #413, #418. From 25aa107a8fd349173dc3ce8727e33215fba29e5c Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Mon, 19 Aug 2024 18:17:03 +0200 Subject: [PATCH 064/169] Add support for ignoring non-fatal SQL state codes. (#421) * Add support for ignoring non-fatal SQL state codes. * Correct since tags. Fix javadocs. Add disconnectionIgnoreSqlCodes to xdoc. Throw illegal argument exception if sql state code configurations overlap. * More tests. * Check style fixes. --- .../apache/commons/dbcp2/BasicDataSource.java | 70 +++++++++++++++++++ .../commons/dbcp2/BasicDataSourceFactory.java | 17 ++++- .../commons/dbcp2/DataSourceMXBean.java | 10 +++ .../commons/dbcp2/PoolableConnection.java | 40 ++++++++++- .../dbcp2/PoolableConnectionFactory.java | 38 +++++++++- .../java/org/apache/commons/dbcp2/Utils.java | 23 ++++++ .../dbcp2/managed/BasicManagedDataSource.java | 1 + .../managed/PoolableManagedConnection.java | 26 ++++++- .../PoolableManagedConnectionFactory.java | 2 +- src/site/xdoc/configuration.xml | 8 +++ .../commons/dbcp2/TestBasicDataSource.java | 46 ++++++++++++ .../dbcp2/TestBasicDataSourceMXBean.java | 5 ++ .../commons/dbcp2/TestPoolableConnection.java | 22 ++++++ .../org/apache/commons/dbcp2/TestUtils.java | 58 +++++++++++++++ 14 files changed, 359 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index 95b756bf78..b7e3fe5113 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -16,6 +16,8 @@ */ package org.apache.commons.dbcp2; +import static org.apache.commons.dbcp2.Utils.checkForConflicts; + import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; @@ -346,6 +348,12 @@ protected static void validateConnectionFactory(final PoolableConnectionFactory private volatile Set disconnectionSqlCodes; + /** + * A collection of SQL State codes that are not considered fatal disconnection codes. + * @since 2.13.0 + */ + private volatile Set disconnectionIgnoreSqlCodes; + private boolean fastFailValidation; /** @@ -629,6 +637,7 @@ protected PoolableConnectionFactory createPoolableConnectionFactory(final Connec connectionFactory.setDefaultQueryTimeout(getDefaultQueryTimeoutDuration()); connectionFactory.setFastFailValidation(fastFailValidation); connectionFactory.setDisconnectionSqlCodes(disconnectionSqlCodes); + connectionFactory.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); validateConnectionFactory(connectionFactory); } catch (final RuntimeException e) { throw e; @@ -864,6 +873,22 @@ public Set getDisconnectionSqlCodes() { return result == null ? Collections.emptySet() : result; } + /** + * Gets the set of SQL State codes that are not considered fatal disconnection codes. + *

    + * This method returns the set of SQL State codes that have been specified to be ignored + * when determining if a {@link SQLException} signals a disconnection. These codes will not + * trigger a disconnection even if they match other disconnection criteria. + *

    + * + * @return a set of SQL State codes that should be ignored for disconnection checks, or an empty set if none have been specified. + * @since 2.13.0 + */ + public Set getDisconnectionIgnoreSqlCodes() { + final Set result = disconnectionIgnoreSqlCodes; + return result == null ? Collections.emptySet() : result; + } + /** * Provides the same data as {@link #getDisconnectionSqlCodes} but in an array so it is accessible via JMX. * @@ -874,6 +899,16 @@ public String[] getDisconnectionSqlCodesAsArray() { return getDisconnectionSqlCodes().toArray(Utils.EMPTY_STRING_ARRAY); } + /** + * Provides the same data as {@link #getDisconnectionIgnoreSqlCodes()} but in an array, so it is accessible via JMX. + * + * @since 2.13.0 + */ + @Override + public String[] getDisconnectionIgnoreSqlCodesAsArray() { + return getDisconnectionIgnoreSqlCodes().toArray(Utils.EMPTY_STRING_ARRAY); + } + /** * Gets the JDBC Driver that has been configured for use by this pool. *

    @@ -954,6 +989,7 @@ public synchronized String getEvictionPolicyClassName() { * * @return true if connections created by this datasource will fast fail validation. * @see #setDisconnectionSqlCodes(Collection) + * @see #setDisconnectionIgnoreSqlCodes(Collection) * @since 2.1 */ @Override @@ -1964,13 +2000,47 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation * * @param disconnectionSqlCodes SQL State codes considered to signal fatal conditions * @since 2.1 + * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionIgnoreSqlCodes}. */ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { + checkForConflicts(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes, + "disconnectionSqlCodes", "disconnectionIgnoreSqlCodes"); final Set collect = Utils.isEmpty(disconnectionSqlCodes) ? null : disconnectionSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); this.disconnectionSqlCodes = Utils.isEmpty(collect) ? null : collect; } + /** + * Sets the SQL State codes that should be ignored when determining fatal disconnection conditions. + *

    + * This method allows you to specify a collection of SQL State codes that will be excluded from + * disconnection checks. These codes will not trigger the "fatally disconnected" status even if they + * match the typical disconnection criteria. This can be useful in scenarios where certain SQL State + * codes (e.g., specific codes starting with "08") are known to be non-fatal in your environment. + *

    + *

    + * The effect of this method is similar to the one described in {@link #setDisconnectionSqlCodes(Collection)}, + * but instead of setting codes that signal fatal disconnections, it defines codes that should be ignored + * during such checks. + *

    + *

    + * Note: This method currently has no effect once the pool has been initialized. The pool is initialized the first + * time one of the following methods is invoked: {@code getConnection, setLogwriter, setLoginTimeout, + * getLoginTimeout, getLogWriter}. + *

    + * + * @param disconnectionIgnoreSqlCodes SQL State codes that should be ignored in disconnection checks + * @since 2.13.0 + * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionSqlCodes}. + */ + public void setDisconnectionIgnoreSqlCodes(final Collection disconnectionIgnoreSqlCodes) { + checkForConflicts(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes, + "disconnectionIgnoreSqlCodes", "disconnectionSqlCodes"); + final Set collect = Utils.isEmpty(disconnectionIgnoreSqlCodes) ? null + : disconnectionIgnoreSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); + this.disconnectionIgnoreSqlCodes = Utils.isEmpty(collect) ? null : collect; + } + /** * Sets the JDBC Driver instance to use for this pool. *

    diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java index a28b21bf52..84beb588dd 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java @@ -120,6 +120,18 @@ public class BasicDataSourceFactory implements ObjectFactory { */ private static final String PROP_DISCONNECTION_SQL_CODES = "disconnectionSqlCodes"; + /** + * Property key for specifying the SQL State codes that should be ignored during disconnection checks. + *

    + * The value for this property must be a comma-separated string of SQL State codes, where each code represents + * a state that will be excluded from being treated as a fatal disconnection. The expected format is a series + * of SQL State codes separated by commas, with no spaces between them (e.g., "08003,08004"). + *

    + * @since 2.13.0 + */ + private static final String PROP_DISCONNECTION_IGNORE_SQL_CODES = "disconnectionIgnoreSqlCodes"; + + /* * Block with obsolete properties from DBCP 1.x. Warn users that these are ignored and they should use the 2.x * properties. @@ -149,8 +161,8 @@ public class BasicDataSourceFactory implements ObjectFactory { PROP_CLEAR_STATEMENT_POOL_ON_RETURN, PROP_MAX_OPEN_PREPARED_STATEMENTS, PROP_CONNECTION_PROPERTIES, PROP_MAX_CONN_LIFETIME_MILLIS, PROP_LOG_EXPIRED_CONNECTIONS, PROP_ROLLBACK_ON_RETURN, PROP_ENABLE_AUTO_COMMIT_ON_RETURN, - PROP_DEFAULT_QUERY_TIMEOUT, PROP_FAST_FAIL_VALIDATION, PROP_DISCONNECTION_SQL_CODES, PROP_JMX_NAME, - PROP_REGISTER_CONNECTION_MBEAN, PROP_CONNECTION_FACTORY_CLASS_NAME); + PROP_DEFAULT_QUERY_TIMEOUT, PROP_FAST_FAIL_VALIDATION, PROP_DISCONNECTION_SQL_CODES, PROP_DISCONNECTION_IGNORE_SQL_CODES, + PROP_JMX_NAME, PROP_REGISTER_CONNECTION_MBEAN, PROP_CONNECTION_FACTORY_CLASS_NAME); /** * Obsolete properties from DBCP 1.x. with warning strings suggesting new properties. LinkedHashMap will guarantee @@ -302,6 +314,7 @@ public static BasicDataSource createDataSource(final Properties properties) thro acceptDurationOfSeconds(properties, PROP_DEFAULT_QUERY_TIMEOUT, dataSource::setDefaultQueryTimeout); acceptBoolean(properties, PROP_FAST_FAIL_VALIDATION, dataSource::setFastFailValidation); getOptional(properties, PROP_DISCONNECTION_SQL_CODES).ifPresent(v -> dataSource.setDisconnectionSqlCodes(parseList(v, ','))); + getOptional(properties, PROP_DISCONNECTION_IGNORE_SQL_CODES).ifPresent(v -> dataSource.setDisconnectionIgnoreSqlCodes(parseList(v, ','))); acceptString(properties, PROP_CONNECTION_FACTORY_CLASS_NAME, dataSource::setConnectionFactoryClassName); // DBCP-215 diff --git a/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java b/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java index d3208c20f5..3c55187bc7 100644 --- a/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java +++ b/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java @@ -93,6 +93,16 @@ default String getDefaultSchema() { */ String[] getDisconnectionSqlCodesAsArray(); + /** + * See {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}. + * + * @return {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}. + * @since 2.13.0 + */ + default String[] getDisconnectionIgnoreSqlCodesAsArray() { + return Utils.EMPTY_STRING_ARRAY; + } + /** * See {@link BasicDataSource#getDriverClassName()}. * diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java index 1497e9e61e..2694022162 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java @@ -76,6 +76,13 @@ public class PoolableConnection extends DelegatingConnection impleme */ private final Collection disconnectionSqlCodes; + /** + * A collection of SQL State codes that are not considered fatal disconnection codes. + * @since 2.13.0 + */ + private final Collection disconnectionIgnoreSqlCodes; + + /** Whether or not to fast fail validation after fatal connection errors */ private final boolean fastFailValidation; @@ -109,13 +116,38 @@ public PoolableConnection(final Connection conn, final ObjectPool pool, + final ObjectName jmxObjectName, final Collection disconnectSqlCodes, + final boolean fastFailValidation) { + this(conn, pool, jmxObjectName, disconnectSqlCodes, null, fastFailValidation); + } + + /** + * Creates a new {@link PoolableConnection} instance. + * + * @param conn + * my underlying connection + * @param pool + * the pool to which I should return when closed + * @param jmxObjectName + * JMX name + * @param disconnectSqlCodes + * SQL State codes considered fatal disconnection errors + * @param disconnectionIgnoreSqlCodes + * SQL State codes that should be ignored when determining fatal disconnection errors + * @param fastFailValidation + * true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to + * run query or isValid) + * @since 2.13.0 + */ public PoolableConnection(final Connection conn, final ObjectPool pool, final ObjectName jmxObjectName, final Collection disconnectSqlCodes, - final boolean fastFailValidation) { + final Collection disconnectionIgnoreSqlCodes, final boolean fastFailValidation) { super(conn); this.pool = pool; this.jmxObjectName = ObjectNameWrapper.wrap(jmxObjectName); this.disconnectionSqlCodes = disconnectSqlCodes; + this.disconnectionIgnoreSqlCodes = disconnectionIgnoreSqlCodes; this.fastFailValidation = fastFailValidation; if (jmxObjectName != null) { @@ -257,7 +289,8 @@ public boolean isClosed() throws SQLException { * If {@link #disconnectionSqlCodes} has been set, sql states are compared to those in the configured list of fatal * exception codes. If this property is not set, codes are compared against the default codes in * {@link Utils#getDisconnectionSqlCodes()} and in this case anything starting with #{link - * Utils.DISCONNECTION_SQL_CODE_PREFIX} is considered a disconnection. + * Utils.DISCONNECTION_SQL_CODE_PREFIX} is considered a disconnection. Additionally, any SQL state + * listed in {@link #disconnectionIgnoreSqlCodes} will be ignored and not treated as fatal. *

    * * @param e SQLException to be examined @@ -267,6 +300,9 @@ boolean isDisconnectionSqlException(final SQLException e) { boolean fatalException = false; final String sqlState = e.getSQLState(); if (sqlState != null) { + if (disconnectionIgnoreSqlCodes != null && disconnectionIgnoreSqlCodes.contains(sqlState)) { + return false; + } fatalException = disconnectionSqlCodes == null ? sqlState.startsWith(Utils.DISCONNECTION_SQL_CODE_PREFIX) || Utils.getDisconnectionSqlCodes().contains(sqlState) : disconnectionSqlCodes.contains(sqlState); diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java index 8de3a6367e..ff6d05131f 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java @@ -16,6 +16,8 @@ */ package org.apache.commons.dbcp2; +import static org.apache.commons.dbcp2.Utils.checkForConflicts; + import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; @@ -64,6 +66,8 @@ public class PoolableConnectionFactory implements PooledObjectFactory disconnectionSqlCodes; + private Collection disconnectionIgnoreSqlCodes; + private boolean fastFailValidation = true; private volatile ObjectPool pool; @@ -290,6 +294,21 @@ public Collection getDisconnectionSqlCodes() { return disconnectionSqlCodes; } + /** + * Retrieves the collection of SQL State codes that are not considered fatal disconnection codes. + *

    + * This method returns the collection of SQL State codes that have been set to be ignored when + * determining if a {@link SQLException} signals a disconnection. These codes are excluded from + * being treated as fatal even if they match the typical disconnection criteria. + *

    + * + * @return a {@link Collection} of SQL State codes that should be ignored for disconnection checks. + * @since 2.13.0 + */ + public Collection getDisconnectionIgnoreSqlCodes() { + return disconnectionIgnoreSqlCodes; + } + /** * Gets the Maximum connection duration. * @@ -464,7 +483,8 @@ public PooledObject makeObject() throws SQLException { } } - final PoolableConnection pc = new PoolableConnection(conn, pool, connJmxName, disconnectionSqlCodes, fastFailValidation); + final PoolableConnection pc = new PoolableConnection(conn, pool, connJmxName, + disconnectionSqlCodes, disconnectionIgnoreSqlCodes, fastFailValidation); pc.setCacheState(cacheState); return new DefaultPooledObject<>(pc); @@ -606,11 +626,27 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation * The disconnection SQL codes. * @see #getDisconnectionSqlCodes() * @since 2.1 + * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionIgnoreSqlCodes}. */ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { + checkForConflicts(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes, + "disconnectionSqlCodes", "disconnectionIgnoreSqlCodes"); this.disconnectionSqlCodes = disconnectionSqlCodes; } + /** + * @param disconnectionIgnoreSqlCodes + * The collection of SQL State codes to be ignored. + * @see #getDisconnectionIgnoreSqlCodes() + * @since 2.13.0 + * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionSqlCodes}. + */ + public void setDisconnectionIgnoreSqlCodes(Collection disconnectionIgnoreSqlCodes) { + checkForConflicts(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes, + "disconnectionIgnoreSqlCodes", "disconnectionSqlCodes"); + this.disconnectionIgnoreSqlCodes = disconnectionIgnoreSqlCodes; + } + /** * @param autoCommitOnReturn Whether to auto-commit on return. * @deprecated Use {@link #setAutoCommitOnReturn(boolean)}. diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index fd106d89a3..ad927225c6 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -138,6 +138,29 @@ public static void closeQuietly(final AutoCloseable autoCloseable) { close(autoCloseable, null); } + /** + * Checks for conflicts between two collections. + *

    + * If any overlap is found between the two provided collections, an {@link IllegalArgumentException} is thrown. + *

    + * + * @param codes1 The first collection of SQL state codes. + * @param codes2 The second collection of SQL state codes. + * @param name1 The name of the first collection (for exception message). + * @param name2 The name of the second collection (for exception message). + * @since 2.13.0 + * @throws IllegalArgumentException if any codes overlap between the two collections. + */ + static void checkForConflicts(Collection codes1, Collection codes2, String name1, String name2) { + if (codes1 != null && codes2 != null) { + for (String code : codes1) { + if (codes2.contains(code)) { + throw new IllegalArgumentException(code + " cannot be in both " + name1 + " and " + name2 + "."); + } + } + } + } + /** * Closes the Connection (which may be null). * diff --git a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java index 719ee4d09c..c293e27cd2 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java @@ -146,6 +146,7 @@ protected PoolableConnectionFactory createPoolableConnectionFactory(final Connec connectionFactory.setDefaultQueryTimeout(getDefaultQueryTimeoutDuration()); connectionFactory.setFastFailValidation(getFastFailValidation()); connectionFactory.setDisconnectionSqlCodes(getDisconnectionSqlCodes()); + connectionFactory.setDisconnectionIgnoreSqlCodes(getDisconnectionIgnoreSqlCodes()); validateConnectionFactory(connectionFactory); } catch (final RuntimeException e) { throw e; diff --git a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java index 29d0585b7b..5eea0397de 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java @@ -65,7 +65,31 @@ public PoolableManagedConnection(final TransactionRegistry transactionRegistry, public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, final ObjectPool pool, final Collection disconnectSqlCodes, final boolean fastFailValidation) { - super(conn, pool, null, disconnectSqlCodes, fastFailValidation); + this(transactionRegistry, conn, pool, disconnectSqlCodes, null, fastFailValidation); + } + + /** + * Create a PoolableManagedConnection. + * + * @param transactionRegistry + * transaction registry + * @param conn + * underlying connection + * @param pool + * connection pool + * @param disconnectSqlCodes + * SQL State codes considered fatal disconnection errors + * @param disconnectionIgnoreSqlCodes + * SQL State codes considered fatal disconnection errors + * @param fastFailValidation + * true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to + * run query or isValid) + * @since 2.13.0 + */ + public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, + final ObjectPool pool, final Collection disconnectSqlCodes, + final Collection disconnectionIgnoreSqlCodes, final boolean fastFailValidation) { + super(conn, pool, null, disconnectSqlCodes, disconnectionIgnoreSqlCodes, fastFailValidation); this.transactionRegistry = transactionRegistry; } diff --git a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java index 7eb810154d..92db944f65 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java @@ -104,7 +104,7 @@ public synchronized PooledObject makeObject() throws SQLExce ((PoolingConnection) conn).setCacheState(getCacheState()); } final PoolableManagedConnection pmc = new PoolableManagedConnection(transactionRegistry, conn, getPool(), - getDisconnectionSqlCodes(), isFastFailValidation()); + getDisconnectionSqlCodes(), getDisconnectionIgnoreSqlCodes(), isFastFailValidation()); pmc.setCacheState(getCacheState()); return new DefaultPooledObject<>(pmc); } diff --git a/src/site/xdoc/configuration.xml b/src/site/xdoc/configuration.xml index 9579736544..9f6ce90011 100644 --- a/src/site/xdoc/configuration.xml +++ b/src/site/xdoc/configuration.xml @@ -498,6 +498,14 @@ the parent connection. fastFailValidation is set to true. + + disconnectionIgnoreSqlCodes + null + Comma-delimited list of SQL State codes that should be ignored when determining fatal disconnection errors. + These codes will not trigger a fatal disconnection status, even if they match the usual criteria. + Setting this property has no effect unless fastFailValidation is set to true. + + jmxName diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java index 47a6d58062..3b3ec7ed50 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -459,6 +460,51 @@ public void testDisconnectSqlCodes() throws Exception { } } + @Test + public void testOverlapBetweenDisconnectionAndIgnoreSqlCodes() { + // Set initial disconnection SQL codes + final HashSet disconnectionSqlCodes = new HashSet<>(Arrays.asList("XXX", "ZZZ")); + ds.setDisconnectionSqlCodes(disconnectionSqlCodes); + + // Try setting ignore SQL codes with overlap + final HashSet disconnectionIgnoreSqlCodes = new HashSet<>(Arrays.asList("YYY", "XXX")); + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { + ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); + }); + + assertEquals("XXX cannot be in both disconnectionIgnoreSqlCodes and disconnectionSqlCodes.", exception.getMessage()); + } + + @Test + public void testNoOverlapBetweenDisconnectionAndIgnoreSqlCodes() { + // Set disconnection SQL codes without overlap + final HashSet disconnectionSqlCodes = new HashSet<>(Arrays.asList("XXX", "ZZZ")); + ds.setDisconnectionSqlCodes(disconnectionSqlCodes); + + // Set ignore SQL codes without overlap + final HashSet disconnectionIgnoreSqlCodes = new HashSet<>(Arrays.asList("YYY", "AAA")); + ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); + + assertEquals(disconnectionSqlCodes, ds.getDisconnectionSqlCodes(), "Disconnection SQL codes should match the set values."); + assertEquals(disconnectionIgnoreSqlCodes, ds.getDisconnectionIgnoreSqlCodes(), "Disconnection Ignore SQL codes should match the set values."); + } + + @Test + public void testDisconnectionIgnoreSqlCodes() throws Exception { + final ArrayList disconnectionIgnoreSqlCodes = new ArrayList<>(); + disconnectionIgnoreSqlCodes.add("XXXX"); + ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); + ds.setFastFailValidation(true); + try (Connection conn = ds.getConnection()) { // Triggers initialization - pcf creation + // Make sure factory got the properties + final PoolableConnectionFactory pcf = (PoolableConnectionFactory) ds.getConnectionPool().getFactory(); + assertTrue(pcf.isFastFailValidation()); + assertTrue(pcf.getDisconnectionIgnoreSqlCodes().contains("XXXX")); + assertEquals(1, pcf.getDisconnectionIgnoreSqlCodes().size()); + } + } + /** * JIRA DBCP-333: Check that a custom class loader is used. * @throws Exception diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java index 246fef1511..d1227b0d23 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java @@ -83,6 +83,11 @@ public String[] getDisconnectionSqlCodesAsArray() { return null; } + @Override + public String[] getDisconnectionIgnoreSqlCodesAsArray() { + return null; + } + @Override public String getDriverClassName() { return null; diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java index 30611d8c0e..4b7681fee4 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java @@ -25,6 +25,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import javax.management.OperationsException; @@ -182,6 +183,27 @@ public void testMXBeanCompliance() throws OperationsException { TestBasicDataSourceMXBean.testMXBeanCompliance(PoolableConnectionMXBean.class); } + @Test + public void testDisconnectionIgnoreSqlCodes() throws Exception { + pool.setTestOnReturn(true); + final PoolableConnectionFactory factory = (PoolableConnectionFactory) pool.getFactory(); + factory.setFastFailValidation(true); + factory.setDisconnectionIgnoreSqlCodes(Arrays.asList("08S02", "08007")); + + final PoolableConnection conn = pool.borrowObject(); + final TesterConnection nativeConnection = (TesterConnection) conn.getInnermostDelegate(); + + // set up non-fatal exception + nativeConnection.setFailure(new SQLException("Non-fatal connection error.", "08S02")); + assertThrows(SQLException.class, conn::createStatement); + nativeConnection.setFailure(null); + + // verify that non-fatal connection is returned to the pool + conn.close(); + assertEquals(0, pool.getNumActive(), "The pool should have no active connections"); + assertEquals(1, pool.getNumIdle(), "The pool should have one idle connection"); + } + // Bugzilla Bug 33591: PoolableConnection leaks connections if the // delegated connection closes itself. @Test diff --git a/src/test/java/org/apache/commons/dbcp2/TestUtils.java b/src/test/java/org/apache/commons/dbcp2/TestUtils.java index 490ee6d6a7..30bd871593 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestUtils.java +++ b/src/test/java/org/apache/commons/dbcp2/TestUtils.java @@ -19,12 +19,70 @@ import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class TestUtils { public static PStmtKey getPStmtKey(final PoolablePreparedStatement poolablePreparedStatement) { return poolablePreparedStatement.getKey(); } + @Test + public void testCheckForConflictsWithOverlap() { + Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); + Collection codes2 = new HashSet<>(Arrays.asList("08005", "08006")); + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { + Utils.checkForConflicts(codes1, codes2, "codes1", "codes2"); + }); + + assertEquals("08006 cannot be in both codes1 and codes2.", exception.getMessage()); + } + + @Test + public void testCheckForConflictsNoOverlap() { + Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); + Collection codes2 = new HashSet<>(Arrays.asList("08005", "08007")); + + assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + } + + @Test + public void testCheckForConflictsFirstCollectionNull() { + Collection codes1 = null; + Collection codes2 = new HashSet<>(Arrays.asList("08005", "08007")); + + assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + } + + @Test + public void testCheckForConflictsSecondCollectionNull() { + Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); + Collection codes2 = null; + + assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + } + + @Test + public void testCheckForConflictsBothCollectionsNull() { + assertDoesNotThrow(() -> Utils.checkForConflicts(null, null, "codes1", "codes2")); + } + + @Test + public void testCheckForConflictsEmptyCollections() { + Collection codes1 = Collections.emptySet(); + Collection codes2 = Collections.emptySet(); + + assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + } + @Test public void testClassLoads() { Utils.closeQuietly((AutoCloseable) null); From 6cc5ada2e7e47e24d35b79c6b98e08ebf2b7b1f2 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 12:18:18 -0400 Subject: [PATCH 065/169] Add support for ignoring non-fatal SQL state codes. #421 --- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e3341bcafe..bd523a9580 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -72,6 +72,7 @@ The type attribute can be add,update,fix,remove. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. + Add support for ignoring non-fatal SQL state codes #421. Bump org.apache.commons:commons-parent from 66 to 73 #360, #371, #395, #420. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. From fb4106db86bf66a530f655026a79b60e6956dbcf Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 12:55:35 -0400 Subject: [PATCH 066/169] Add support for ignoring non-fatal SQL state codes #421 - Error message should contain all SQL codes in conflict - Do not use static imports (only used these in unit tests) - Javadoc: Empty line before tags - Javadoc: Add missing sentences - Javadoc: @since tag is last in new elements - Use longer lines - Reduce redundant boilerplace - Sort members - Flip error message - Use final - Less whitespace - Simpler lambdas (less boilerplate) --- .../apache/commons/dbcp2/BasicDataSource.java | 108 +++++++++--------- .../commons/dbcp2/DataSourceMXBean.java | 16 +-- .../commons/dbcp2/PoolableConnection.java | 1 + .../dbcp2/PoolableConnectionFactory.java | 66 +++++------ .../java/org/apache/commons/dbcp2/Utils.java | 51 +++++---- .../dbcp2/managed/BasicManagedDataSource.java | 3 +- .../managed/PoolableManagedConnection.java | 21 ++-- .../commons/dbcp2/TestBasicDataSource.java | 108 ++++++++---------- .../dbcp2/TestBasicDataSourceMXBean.java | 4 +- .../dbcp2/TestDelegatingDatabaseMetaData.java | 8 +- .../commons/dbcp2/TestPoolableConnection.java | 42 +++---- .../org/apache/commons/dbcp2/TestUtils.java | 64 +++++------ .../cpdsadapter/TestDriverAdapterCPDS.java | 1 - 13 files changed, 238 insertions(+), 255 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index b7e3fe5113..963010286d 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -16,8 +16,6 @@ */ package org.apache.commons.dbcp2; -import static org.apache.commons.dbcp2.Utils.checkForConflicts; - import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; @@ -60,7 +58,6 @@ /** * Basic implementation of {@code javax.sql.DataSource} that is configured via JavaBeans properties. - * *

    * This is not the only way to combine the commons-dbcp2 and commons-pool2 packages, but provides a * one-stop solution for basic requirements. @@ -350,6 +347,7 @@ protected static void validateConnectionFactory(final PoolableConnectionFactory /** * A collection of SQL State codes that are not considered fatal disconnection codes. + * * @since 2.13.0 */ private volatile Set disconnectionIgnoreSqlCodes; @@ -861,18 +859,6 @@ public int getDefaultTransactionIsolation() { return this.defaultTransactionIsolation; } - /** - * Gets the set of SQL State codes considered to signal fatal conditions. - * - * @return fatal disconnection state codes - * @see #setDisconnectionSqlCodes(Collection) - * @since 2.1 - */ - public Set getDisconnectionSqlCodes() { - final Set result = disconnectionSqlCodes; - return result == null ? Collections.emptySet() : result; - } - /** * Gets the set of SQL State codes that are not considered fatal disconnection codes. *

    @@ -890,23 +876,35 @@ public Set getDisconnectionIgnoreSqlCodes() { } /** - * Provides the same data as {@link #getDisconnectionSqlCodes} but in an array so it is accessible via JMX. + * Provides the same data as {@link #getDisconnectionIgnoreSqlCodes()} but in an array, so it is accessible via JMX. * - * @since 2.1 + * @since 2.13.0 */ @Override - public String[] getDisconnectionSqlCodesAsArray() { - return getDisconnectionSqlCodes().toArray(Utils.EMPTY_STRING_ARRAY); + public String[] getDisconnectionIgnoreSqlCodesAsArray() { + return getDisconnectionIgnoreSqlCodes().toArray(Utils.EMPTY_STRING_ARRAY); } /** - * Provides the same data as {@link #getDisconnectionIgnoreSqlCodes()} but in an array, so it is accessible via JMX. + * Gets the set of SQL State codes considered to signal fatal conditions. * - * @since 2.13.0 + * @return fatal disconnection state codes + * @see #setDisconnectionSqlCodes(Collection) + * @since 2.1 + */ + public Set getDisconnectionSqlCodes() { + final Set result = disconnectionSqlCodes; + return result == null ? Collections.emptySet() : result; + } + + /** + * Provides the same data as {@link #getDisconnectionSqlCodes} but in an array so it is accessible via JMX. + * + * @since 2.1 */ @Override - public String[] getDisconnectionIgnoreSqlCodesAsArray() { - return getDisconnectionIgnoreSqlCodes().toArray(Utils.EMPTY_STRING_ARRAY); + public String[] getDisconnectionSqlCodesAsArray() { + return getDisconnectionSqlCodes().toArray(Utils.EMPTY_STRING_ARRAY); } /** @@ -1980,36 +1978,6 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation this.defaultTransactionIsolation = defaultTransactionIsolation; } - /** - * Sets the SQL State codes considered to signal fatal conditions. - *

    - * Overrides the defaults in {@link Utils#getDisconnectionSqlCodes()} (plus anything starting with - * {@link Utils#DISCONNECTION_SQL_CODE_PREFIX}). If this property is non-null and {@link #getFastFailValidation()} - * is {@code true}, whenever connections created by this datasource generate exceptions with SQL State codes in this - * list, they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at - * isValid or validation query). - *

    - *

    - * If {@link #getFastFailValidation()} is {@code false} setting this property has no effect. - *

    - *

    - * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first - * time one of the following methods is invoked: {@code getConnection, setLogwriter, - * setLoginTimeout, getLoginTimeout, getLogWriter}. - *

    - * - * @param disconnectionSqlCodes SQL State codes considered to signal fatal conditions - * @since 2.1 - * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionIgnoreSqlCodes}. - */ - public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { - checkForConflicts(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes, - "disconnectionSqlCodes", "disconnectionIgnoreSqlCodes"); - final Set collect = Utils.isEmpty(disconnectionSqlCodes) ? null - : disconnectionSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); - this.disconnectionSqlCodes = Utils.isEmpty(collect) ? null : collect; - } - /** * Sets the SQL State codes that should be ignored when determining fatal disconnection conditions. *

    @@ -2030,17 +1998,45 @@ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCo *

    * * @param disconnectionIgnoreSqlCodes SQL State codes that should be ignored in disconnection checks - * @since 2.13.0 * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionSqlCodes}. + * @since 2.13.0 */ public void setDisconnectionIgnoreSqlCodes(final Collection disconnectionIgnoreSqlCodes) { - checkForConflicts(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes, - "disconnectionIgnoreSqlCodes", "disconnectionSqlCodes"); + Utils.checkSqlCodes(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes); final Set collect = Utils.isEmpty(disconnectionIgnoreSqlCodes) ? null : disconnectionIgnoreSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); this.disconnectionIgnoreSqlCodes = Utils.isEmpty(collect) ? null : collect; } + /** + * Sets the SQL State codes considered to signal fatal conditions. + *

    + * Overrides the defaults in {@link Utils#getDisconnectionSqlCodes()} (plus anything starting with + * {@link Utils#DISCONNECTION_SQL_CODE_PREFIX}). If this property is non-null and {@link #getFastFailValidation()} + * is {@code true}, whenever connections created by this datasource generate exceptions with SQL State codes in this + * list, they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at + * isValid or validation query). + *

    + *

    + * If {@link #getFastFailValidation()} is {@code false} setting this property has no effect. + *

    + *

    + * Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first + * time one of the following methods is invoked: {@code getConnection, setLogwriter, + * setLoginTimeout, getLoginTimeout, getLogWriter}. + *

    + * + * @param disconnectionSqlCodes SQL State codes considered to signal fatal conditions + * @since 2.1 + * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionIgnoreSqlCodes}. + */ + public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { + Utils.checkSqlCodes(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes); + final Set collect = Utils.isEmpty(disconnectionSqlCodes) ? null + : disconnectionSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); + this.disconnectionSqlCodes = Utils.isEmpty(collect) ? null : collect; + } + /** * Sets the JDBC Driver instance to use for this pool. *

    diff --git a/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java b/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java index 3c55187bc7..c28bd1f616 100644 --- a/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java +++ b/src/main/java/org/apache/commons/dbcp2/DataSourceMXBean.java @@ -85,14 +85,6 @@ default String getDefaultSchema() { */ int getDefaultTransactionIsolation(); - /** - * See {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}. - * - * @return {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}. - * @since 2.1 - */ - String[] getDisconnectionSqlCodesAsArray(); - /** * See {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}. * @@ -103,6 +95,14 @@ default String[] getDisconnectionIgnoreSqlCodesAsArray() { return Utils.EMPTY_STRING_ARRAY; } + /** + * See {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}. + * + * @return {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}. + * @since 2.1 + */ + String[] getDisconnectionSqlCodesAsArray(); + /** * See {@link BasicDataSource#getDriverClassName()}. * diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java index 2694022162..612560a3d0 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java @@ -78,6 +78,7 @@ public class PoolableConnection extends DelegatingConnection impleme /** * A collection of SQL State codes that are not considered fatal disconnection codes. + * * @since 2.13.0 */ private final Collection disconnectionIgnoreSqlCodes; diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java index ff6d05131f..c2f12d2e5a 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java @@ -16,8 +16,6 @@ */ package org.apache.commons.dbcp2; -import static org.apache.commons.dbcp2.Utils.checkForConflicts; - import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; @@ -275,7 +273,22 @@ public int getDefaultTransactionIsolation() { } /** - * SQL State codes considered to signal fatal conditions. + * Gets the collection of SQL State codes that are not considered fatal disconnection codes. + *

    + * This method returns the collection of SQL State codes that have been set to be ignored when + * determining if a {@link SQLException} signals a disconnection. These codes are excluded from + * being treated as fatal even if they match the typical disconnection criteria. + *

    + * + * @return a {@link Collection} of SQL State codes that should be ignored for disconnection checks. + * @since 2.13.0 + */ + public Collection getDisconnectionIgnoreSqlCodes() { + return disconnectionIgnoreSqlCodes; + } + + /** + * Gets SQL State codes considered to signal fatal conditions. *

    * Overrides the defaults in {@link Utils#getDisconnectionSqlCodes()} (plus anything starting with * {@link Utils#DISCONNECTION_SQL_CODE_PREFIX}). If this property is non-null and {@link #isFastFailValidation()} is @@ -294,21 +307,6 @@ public Collection getDisconnectionSqlCodes() { return disconnectionSqlCodes; } - /** - * Retrieves the collection of SQL State codes that are not considered fatal disconnection codes. - *

    - * This method returns the collection of SQL State codes that have been set to be ignored when - * determining if a {@link SQLException} signals a disconnection. These codes are excluded from - * being treated as fatal even if they match the typical disconnection criteria. - *

    - * - * @return a {@link Collection} of SQL State codes that should be ignored for disconnection checks. - * @since 2.13.0 - */ - public Collection getDisconnectionIgnoreSqlCodes() { - return disconnectionIgnoreSqlCodes; - } - /** * Gets the Maximum connection duration. * @@ -622,6 +620,22 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation } /** + * Sets the disconnection SQL codes to ignore. + * + * @param disconnectionIgnoreSqlCodes + * The collection of SQL State codes to be ignored. + * @see #getDisconnectionIgnoreSqlCodes() + * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionSqlCodes}. + * @since 2.13.0 + */ + public void setDisconnectionIgnoreSqlCodes(Collection disconnectionIgnoreSqlCodes) { + Utils.checkSqlCodes(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes); + this.disconnectionIgnoreSqlCodes = disconnectionIgnoreSqlCodes; + } + + /** + * Sets the disconnection SQL codes. + * * @param disconnectionSqlCodes * The disconnection SQL codes. * @see #getDisconnectionSqlCodes() @@ -629,24 +643,10 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionIgnoreSqlCodes}. */ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { - checkForConflicts(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes, - "disconnectionSqlCodes", "disconnectionIgnoreSqlCodes"); + Utils.checkSqlCodes(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes); this.disconnectionSqlCodes = disconnectionSqlCodes; } - /** - * @param disconnectionIgnoreSqlCodes - * The collection of SQL State codes to be ignored. - * @see #getDisconnectionIgnoreSqlCodes() - * @since 2.13.0 - * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionSqlCodes}. - */ - public void setDisconnectionIgnoreSqlCodes(Collection disconnectionIgnoreSqlCodes) { - checkForConflicts(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes, - "disconnectionIgnoreSqlCodes", "disconnectionSqlCodes"); - this.disconnectionIgnoreSqlCodes = disconnectionIgnoreSqlCodes; - } - /** * @param autoCommitOnReturn Whether to auto-commit on return. * @deprecated Use {@link #setAutoCommitOnReturn(boolean)}. diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index ad927225c6..6f236c525d 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -82,6 +82,34 @@ public final class Utils { DISCONNECTION_SQL_CODES.add("JZ0C1"); // Sybase disconnect error } + /** + * Checks for conflicts between two collections. + *

    + * If any overlap is found between the two provided collections, an {@link IllegalArgumentException} is thrown. + *

    + * + * @param codes1 The first collection of SQL state codes. + * @param codes2 The second collection of SQL state codes. + * @throws IllegalArgumentException if any codes overlap between the two collections. + * @since 2.13.0 + */ + static void checkSqlCodes(final Collection codes1, final Collection codes2) { +// if (codes1 != null && codes2 != null) { +// for (String code : codes1) { +// if (codes2.contains(code)) { +// throw new IllegalArgumentException(code + " cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes."); +// } +// } +// } + if (codes1 != null && codes2 != null) { + final Set test = new HashSet<>(codes1); + test.retainAll(codes2); + if (!test.isEmpty()) { + throw new IllegalArgumentException(test + " cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes."); + } + } + } + /** * Clones the given char[] if not null. * @@ -138,29 +166,6 @@ public static void closeQuietly(final AutoCloseable autoCloseable) { close(autoCloseable, null); } - /** - * Checks for conflicts between two collections. - *

    - * If any overlap is found between the two provided collections, an {@link IllegalArgumentException} is thrown. - *

    - * - * @param codes1 The first collection of SQL state codes. - * @param codes2 The second collection of SQL state codes. - * @param name1 The name of the first collection (for exception message). - * @param name2 The name of the second collection (for exception message). - * @since 2.13.0 - * @throws IllegalArgumentException if any codes overlap between the two collections. - */ - static void checkForConflicts(Collection codes1, Collection codes2, String name1, String name2) { - if (codes1 != null && codes2 != null) { - for (String code : codes1) { - if (codes2.contains(code)) { - throw new IllegalArgumentException(code + " cannot be in both " + name1 + " and " + name2 + "."); - } - } - } - } - /** * Closes the Connection (which may be null). * diff --git a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java index c293e27cd2..9bd1c99354 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java @@ -126,8 +126,7 @@ protected PoolableConnectionFactory createPoolableConnectionFactory(final Connec throws SQLException { PoolableConnectionFactory connectionFactory = null; try { - connectionFactory = new PoolableManagedConnectionFactory((XAConnectionFactory) driverConnectionFactory, - getRegisteredJmxName()); + connectionFactory = new PoolableManagedConnectionFactory((XAConnectionFactory) driverConnectionFactory, getRegisteredJmxName()); connectionFactory.setValidationQuery(getValidationQuery()); connectionFactory.setValidationQueryTimeout(getValidationQueryTimeoutDuration()); connectionFactory.setConnectionInitSql(getConnectionInitSqls()); diff --git a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java index 5eea0397de..2be2e1a4f1 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnection.java @@ -33,7 +33,7 @@ public class PoolableManagedConnection extends PoolableConnection { private final TransactionRegistry transactionRegistry; /** - * Create a PoolableManagedConnection. + * Creates a PoolableManagedConnection. * * @param transactionRegistry * transaction registry @@ -42,13 +42,12 @@ public class PoolableManagedConnection extends PoolableConnection { * @param pool * connection pool */ - public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, - final ObjectPool pool) { + public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, final ObjectPool pool) { this(transactionRegistry, conn, pool, null, true); } /** - * Create a PoolableManagedConnection. + * Creates a PoolableManagedConnection. * * @param transactionRegistry * transaction registry @@ -62,14 +61,13 @@ public PoolableManagedConnection(final TransactionRegistry transactionRegistry, * true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to * run query or isValid) */ - public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, - final ObjectPool pool, final Collection disconnectSqlCodes, - final boolean fastFailValidation) { + public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, final ObjectPool pool, + final Collection disconnectSqlCodes, final boolean fastFailValidation) { this(transactionRegistry, conn, pool, disconnectSqlCodes, null, fastFailValidation); } /** - * Create a PoolableManagedConnection. + * Creates a PoolableManagedConnection. * * @param transactionRegistry * transaction registry @@ -86,14 +84,15 @@ public PoolableManagedConnection(final TransactionRegistry transactionRegistry, * run query or isValid) * @since 2.13.0 */ - public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, - final ObjectPool pool, final Collection disconnectSqlCodes, - final Collection disconnectionIgnoreSqlCodes, final boolean fastFailValidation) { + public PoolableManagedConnection(final TransactionRegistry transactionRegistry, final Connection conn, final ObjectPool pool, + final Collection disconnectSqlCodes, final Collection disconnectionIgnoreSqlCodes, final boolean fastFailValidation) { super(conn, pool, null, disconnectSqlCodes, disconnectionIgnoreSqlCodes, fastFailValidation); this.transactionRegistry = transactionRegistry; } /** + * Gets the transaction registry. + * * @return The transaction registry. * @since 2.6.0 */ diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java index 3b3ec7ed50..66c852d1c1 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java @@ -440,6 +440,21 @@ public void testDeprecatedAccessors() throws SQLException { } } + @Test + public void testDisconnectionIgnoreSqlCodes() throws Exception { + final ArrayList disconnectionIgnoreSqlCodes = new ArrayList<>(); + disconnectionIgnoreSqlCodes.add("XXXX"); + ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); + ds.setFastFailValidation(true); + try (Connection conn = ds.getConnection()) { // Triggers initialization - pcf creation + // Make sure factory got the properties + final PoolableConnectionFactory pcf = (PoolableConnectionFactory) ds.getConnectionPool().getFactory(); + assertTrue(pcf.isFastFailValidation()); + assertTrue(pcf.getDisconnectionIgnoreSqlCodes().contains("XXXX")); + assertEquals(1, pcf.getDisconnectionIgnoreSqlCodes().size()); + } + } + /** * JIRA: DBCP-437 * Verify that BasicDataSource sets disconnect codes properties. @@ -460,51 +475,6 @@ public void testDisconnectSqlCodes() throws Exception { } } - @Test - public void testOverlapBetweenDisconnectionAndIgnoreSqlCodes() { - // Set initial disconnection SQL codes - final HashSet disconnectionSqlCodes = new HashSet<>(Arrays.asList("XXX", "ZZZ")); - ds.setDisconnectionSqlCodes(disconnectionSqlCodes); - - // Try setting ignore SQL codes with overlap - final HashSet disconnectionIgnoreSqlCodes = new HashSet<>(Arrays.asList("YYY", "XXX")); - - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { - ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); - }); - - assertEquals("XXX cannot be in both disconnectionIgnoreSqlCodes and disconnectionSqlCodes.", exception.getMessage()); - } - - @Test - public void testNoOverlapBetweenDisconnectionAndIgnoreSqlCodes() { - // Set disconnection SQL codes without overlap - final HashSet disconnectionSqlCodes = new HashSet<>(Arrays.asList("XXX", "ZZZ")); - ds.setDisconnectionSqlCodes(disconnectionSqlCodes); - - // Set ignore SQL codes without overlap - final HashSet disconnectionIgnoreSqlCodes = new HashSet<>(Arrays.asList("YYY", "AAA")); - ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); - - assertEquals(disconnectionSqlCodes, ds.getDisconnectionSqlCodes(), "Disconnection SQL codes should match the set values."); - assertEquals(disconnectionIgnoreSqlCodes, ds.getDisconnectionIgnoreSqlCodes(), "Disconnection Ignore SQL codes should match the set values."); - } - - @Test - public void testDisconnectionIgnoreSqlCodes() throws Exception { - final ArrayList disconnectionIgnoreSqlCodes = new ArrayList<>(); - disconnectionIgnoreSqlCodes.add("XXXX"); - ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); - ds.setFastFailValidation(true); - try (Connection conn = ds.getConnection()) { // Triggers initialization - pcf creation - // Make sure factory got the properties - final PoolableConnectionFactory pcf = (PoolableConnectionFactory) ds.getConnectionPool().getFactory(); - assertTrue(pcf.isFastFailValidation()); - assertTrue(pcf.getDisconnectionIgnoreSqlCodes().contains("XXXX")); - assertEquals(1, pcf.getDisconnectionIgnoreSqlCodes().size()); - } - } - /** * JIRA DBCP-333: Check that a custom class loader is used. * @throws Exception @@ -628,15 +598,15 @@ public void testInvalidateConnection() throws Exception { } @Test - public void testInvalidConnectionInitSqlList() { - ds.setConnectionInitSqls(Arrays.asList("SELECT 1", "invalid")); + public void testInvalidConnectionInitSqlCollection() { + ds.setConnectionInitSqls((Collection) Arrays.asList("SELECT 1", "invalid")); final SQLException e = assertThrows(SQLException.class, ds::getConnection); assertTrue(e.toString().contains("invalid")); } @Test - public void testInvalidConnectionInitSqlCollection() { - ds.setConnectionInitSqls((Collection) Arrays.asList("SELECT 1", "invalid")); + public void testInvalidConnectionInitSqlList() { + ds.setConnectionInitSqls(Arrays.asList("SELECT 1", "invalid")); final SQLException e = assertThrows(SQLException.class, ds::getConnection); assertTrue(e.toString().contains("invalid")); } @@ -704,23 +674,14 @@ public void testJmxDisabled() throws Exception { @Test public void testJmxDoesNotExposePassword() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - try (Connection c = ds.getConnection()) { // nothing } final ObjectName objectName = new ObjectName(ds.getJmxName()); - final MBeanAttributeInfo[] attributes = mbs.getMBeanInfo(objectName).getAttributes(); - assertTrue(attributes != null && attributes.length > 0); - - Arrays.asList(attributes).forEach(attrInfo -> { - assertFalse("password".equalsIgnoreCase(attrInfo.getName())); - }); - - assertThrows(AttributeNotFoundException.class, () -> { - mbs.getAttribute(objectName, "Password"); - }); + Arrays.asList(attributes).forEach(attrInfo -> assertFalse("password".equalsIgnoreCase(attrInfo.getName()))); + assertThrows(AttributeNotFoundException.class, () -> mbs.getAttribute(objectName, "Password")); } @Test @@ -830,6 +791,33 @@ public void testNoAccessToUnderlyingConnectionAllowed() throws Exception { } } + @Test + public void testNoOverlapBetweenDisconnectionAndIgnoreSqlCodes() { + // Set disconnection SQL codes without overlap + final HashSet disconnectionSqlCodes = new HashSet<>(Arrays.asList("XXX", "ZZZ")); + ds.setDisconnectionSqlCodes(disconnectionSqlCodes); + + // Set ignore SQL codes without overlap + final HashSet disconnectionIgnoreSqlCodes = new HashSet<>(Arrays.asList("YYY", "AAA")); + ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes); + + assertEquals(disconnectionSqlCodes, ds.getDisconnectionSqlCodes(), "Disconnection SQL codes should match the set values."); + assertEquals(disconnectionIgnoreSqlCodes, ds.getDisconnectionIgnoreSqlCodes(), "Disconnection Ignore SQL codes should match the set values."); + } + + @Test + public void testOverlapBetweenDisconnectionAndIgnoreSqlCodes() { + // Set initial disconnection SQL codes + final HashSet disconnectionSqlCodes = new HashSet<>(Arrays.asList("XXX", "ZZZ")); + ds.setDisconnectionSqlCodes(disconnectionSqlCodes); + // Try setting ignore SQL codes with overlap + final HashSet disconnectionIgnoreSqlCodes = new HashSet<>(Arrays.asList("YYY", "XXX")); + + final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> ds.setDisconnectionIgnoreSqlCodes(disconnectionIgnoreSqlCodes)); + assertEquals("[XXX] cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes.", exception.getMessage()); + } + /** * Verifies correct handling of exceptions generated by the underlying pool as it closes * connections in response to BDS#close. Exceptions have to be either swallowed by the diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java index d1227b0d23..56b78fc710 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java @@ -79,12 +79,12 @@ public int getDefaultTransactionIsolation() { } @Override - public String[] getDisconnectionSqlCodesAsArray() { + public String[] getDisconnectionIgnoreSqlCodesAsArray() { return null; } @Override - public String[] getDisconnectionIgnoreSqlCodesAsArray() { + public String[] getDisconnectionSqlCodesAsArray() { return null; } diff --git a/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java b/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java index 74886cccac..05fed11441 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java +++ b/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java @@ -772,12 +772,8 @@ public void testLocatorsUpdateCopy() throws Exception { @Test public void testNullArguments() throws Exception { - assertThrows(NullPointerException.class, () -> { - new DelegatingDatabaseMetaData(null, null); - }); - assertThrows(NullPointerException.class, () -> { - new DelegatingDatabaseMetaData(new DelegatingConnection(null), null); - }); + assertThrows(NullPointerException.class, () -> new DelegatingDatabaseMetaData(null, null)); + assertThrows(NullPointerException.class, () -> new DelegatingDatabaseMetaData(new DelegatingConnection(null), null)); } @Test diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java index 4b7681fee4..d36e1ff468 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java @@ -90,6 +90,27 @@ public void testConnectionPool() throws Exception { assertEquals(0, pool.getNumActive(), "There should now be zero active objects in the pool"); } + @Test + public void testDisconnectionIgnoreSqlCodes() throws Exception { + pool.setTestOnReturn(true); + final PoolableConnectionFactory factory = (PoolableConnectionFactory) pool.getFactory(); + factory.setFastFailValidation(true); + factory.setDisconnectionIgnoreSqlCodes(Arrays.asList("08S02", "08007")); + + final PoolableConnection conn = pool.borrowObject(); + final TesterConnection nativeConnection = (TesterConnection) conn.getInnermostDelegate(); + + // set up non-fatal exception + nativeConnection.setFailure(new SQLException("Non-fatal connection error.", "08S02")); + assertThrows(SQLException.class, conn::createStatement); + nativeConnection.setFailure(null); + + // verify that non-fatal connection is returned to the pool + conn.close(); + assertEquals(0, pool.getNumActive(), "The pool should have no active connections"); + assertEquals(1, pool.getNumIdle(), "The pool should have one idle connection"); + } + @Test public void testFastFailValidation() throws Exception { pool.setTestOnReturn(true); @@ -183,27 +204,6 @@ public void testMXBeanCompliance() throws OperationsException { TestBasicDataSourceMXBean.testMXBeanCompliance(PoolableConnectionMXBean.class); } - @Test - public void testDisconnectionIgnoreSqlCodes() throws Exception { - pool.setTestOnReturn(true); - final PoolableConnectionFactory factory = (PoolableConnectionFactory) pool.getFactory(); - factory.setFastFailValidation(true); - factory.setDisconnectionIgnoreSqlCodes(Arrays.asList("08S02", "08007")); - - final PoolableConnection conn = pool.borrowObject(); - final TesterConnection nativeConnection = (TesterConnection) conn.getInnermostDelegate(); - - // set up non-fatal exception - nativeConnection.setFailure(new SQLException("Non-fatal connection error.", "08S02")); - assertThrows(SQLException.class, conn::createStatement); - nativeConnection.setFailure(null); - - // verify that non-fatal connection is returned to the pool - conn.close(); - assertEquals(0, pool.getNumActive(), "The pool should have no active connections"); - assertEquals(1, pool.getNumIdle(), "The pool should have one idle connection"); - } - // Bugzilla Bug 33591: PoolableConnection leaks connections if the // delegated connection closes itself. @Test diff --git a/src/test/java/org/apache/commons/dbcp2/TestUtils.java b/src/test/java/org/apache/commons/dbcp2/TestUtils.java index 30bd871593..79d06eb0b9 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestUtils.java +++ b/src/test/java/org/apache/commons/dbcp2/TestUtils.java @@ -17,16 +17,16 @@ package org.apache.commons.dbcp2; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.Test; public class TestUtils { @@ -35,52 +35,52 @@ public static PStmtKey getPStmtKey(final PoolablePreparedStatement poo } @Test - public void testCheckForConflictsWithOverlap() { - Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); - Collection codes2 = new HashSet<>(Arrays.asList("08005", "08006")); - - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { - Utils.checkForConflicts(codes1, codes2, "codes1", "codes2"); - }); - - assertEquals("08006 cannot be in both codes1 and codes2.", exception.getMessage()); + public void testCheckForConflictsBothCollectionsNull() { + assertDoesNotThrow(() -> Utils.checkSqlCodes(null, null)); } @Test - public void testCheckForConflictsNoOverlap() { - Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); - Collection codes2 = new HashSet<>(Arrays.asList("08005", "08007")); - - assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + public void testCheckForConflictsEmptyCollections() { + final Collection codes1 = Collections.emptySet(); + final Collection codes2 = Collections.emptySet(); + assertDoesNotThrow(() -> Utils.checkSqlCodes(codes1, codes2)); } @Test public void testCheckForConflictsFirstCollectionNull() { - Collection codes1 = null; - Collection codes2 = new HashSet<>(Arrays.asList("08005", "08007")); + final Collection codes1 = null; + final Collection codes2 = new HashSet<>(Arrays.asList("08005", "08007")); + assertDoesNotThrow(() -> Utils.checkSqlCodes(codes1, codes2)); + } - assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + @Test + public void testCheckForConflictsNoOverlap() { + final Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); + final Collection codes2 = new HashSet<>(Arrays.asList("08005", "08007")); + assertDoesNotThrow(() -> Utils.checkSqlCodes(codes1, codes2)); } @Test public void testCheckForConflictsSecondCollectionNull() { - Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); - Collection codes2 = null; - - assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + final Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); + final Collection codes2 = null; + assertDoesNotThrow(() -> Utils.checkSqlCodes(codes1, codes2)); } @Test - public void testCheckForConflictsBothCollectionsNull() { - assertDoesNotThrow(() -> Utils.checkForConflicts(null, null, "codes1", "codes2")); + public void testCheckForConflictsWith1Overlap() { + final Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006")); + final Collection codes2 = new HashSet<>(Arrays.asList("08005", "08006")); + final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Utils.checkSqlCodes(codes1, codes2)); + assertEquals("[08006] cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes.", exception.getMessage()); } @Test - public void testCheckForConflictsEmptyCollections() { - Collection codes1 = Collections.emptySet(); - Collection codes2 = Collections.emptySet(); - - assertDoesNotThrow(() -> Utils.checkForConflicts(codes1, codes2, "codes1", "codes2")); + public void testCheckForConflictsWith2Overlap() { + final Collection codes1 = new HashSet<>(Arrays.asList("08003", "08006", "08007")); + final Collection codes2 = new HashSet<>(Arrays.asList("08005", "08006", "08007")); + final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> Utils.checkSqlCodes(codes1, codes2)); + assertEquals("[08006, 08007] cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes.", exception.getMessage()); } @Test diff --git a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java index 68573f42e4..737466690d 100644 --- a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java +++ b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.io.PrintWriter; import java.sql.Connection; From f6fbc21ccf8840330f31ae7614dd708bbde22fe7 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 12:56:30 -0400 Subject: [PATCH 067/169] Bump version to feature --- pom.xml | 8 ++++---- src/changes/changes.xml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ac095d0a83..4aea96f66b 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 commons-dbcp2 - 2.12.1-SNAPSHOT + 2.13.0-SNAPSHOT Apache Commons DBCP 2001 @@ -181,8 +181,8 @@ RC1 org.apache.commons.dbcp2 - 2.12.0 - 2.12.1 + 2.13.0 + 2.13.1 for JDBC 4.2 on Java 8 sha512 @@ -200,7 +200,7 @@ javax.transaction;version="1.1.0",javax.transaction.xa;version="1.1.0";partial=true;mandatory:=partial,* true - 2.11.0 + 2.12.0 true false false diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bd523a9580..71037c5435 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -62,7 +62,7 @@ The type attribute can be add,update,fix,remove. EvictionTimer --> - + Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. From f57c9fef0d55e6faaac89c86786cf1319c984b80 Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Mon, 19 Aug 2024 19:28:28 +0200 Subject: [PATCH 068/169] Avoid object creation when invoking isDisconnectionSqlException. (#422) * Avoid object creation when invoking isDisconnectionSqlException. * Update since tag. --- .../apache/commons/dbcp2/PoolableConnection.java | 2 +- .../java/org/apache/commons/dbcp2/Utils.java | 11 +++++++++++ .../java/org/apache/commons/dbcp2/TestUtils.java | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java index 612560a3d0..01ce941deb 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java @@ -305,7 +305,7 @@ boolean isDisconnectionSqlException(final SQLException e) { return false; } fatalException = disconnectionSqlCodes == null - ? sqlState.startsWith(Utils.DISCONNECTION_SQL_CODE_PREFIX) || Utils.getDisconnectionSqlCodes().contains(sqlState) + ? sqlState.startsWith(Utils.DISCONNECTION_SQL_CODE_PREFIX) || Utils.isDisconnectionSqlCode(sqlState) : disconnectionSqlCodes.contains(sqlState); } return fatalException; diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index 6f236c525d..e9324adb6b 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -216,6 +216,17 @@ public static Set getDisconnectionSqlCodes() { return new HashSet<>(DISCONNECTION_SQL_CODES); } + /** + * Checks if the given SQL state corresponds to a fatal connection error. + * + * @param sqlState the SQL state to check. + * @return true if the SQL state is a fatal connection error, false otherwise. + * @since 2.13.0 + */ + static boolean isDisconnectionSqlCode(String sqlState) { + return DISCONNECTION_SQL_CODES.contains(sqlState); + } + /** * Gets the correct i18n message for the given key. * diff --git a/src/test/java/org/apache/commons/dbcp2/TestUtils.java b/src/test/java/org/apache/commons/dbcp2/TestUtils.java index 79d06eb0b9..395d25b26b 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestUtils.java +++ b/src/test/java/org/apache/commons/dbcp2/TestUtils.java @@ -19,15 +19,17 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import org.junit.jupiter.api.Test; - public class TestUtils { public static PStmtKey getPStmtKey(final PoolablePreparedStatement poolablePreparedStatement) { @@ -87,4 +89,14 @@ public void testCheckForConflictsWith2Overlap() { public void testClassLoads() { Utils.closeQuietly((AutoCloseable) null); } + + @Test + public void testIsDisconnectionSqlCode() { + assertTrue(Utils.isDisconnectionSqlCode("57P01"), "57P01 should be recognised as a disconnection SQL code."); + assertTrue(Utils.isDisconnectionSqlCode("01002"), "01002 should be recognised as a disconnection SQL code."); + assertTrue(Utils.isDisconnectionSqlCode("JZ0C0"), "JZ0C0 should be recognised as a disconnection SQL code."); + + assertFalse(Utils.isDisconnectionSqlCode("INVALID"), "INVALID should not be recognised as a disconnection SQL code."); + assertFalse(Utils.isDisconnectionSqlCode("00000"), "00000 should not be recognised as a disconnection SQL code."); + } } From e31c128999677f3ee19305be03c687435cf064a0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 13:29:27 -0400 Subject: [PATCH 069/169] Avoid object creation when invoking isDisconnectionSqlException. #422 --- src/changes/changes.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 71037c5435..a90740fa36 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -71,8 +71,9 @@ The type attribute can be add,update,fix,remove. Fix PMD UnnecessaryFullyQualifiedName in LocalXAConnectionFactory. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. + Avoid object creation when invoking isDisconnectionSqlException #422. - Add support for ignoring non-fatal SQL state codes #421. + Add support for ignoring non-fatal SQL state codes #421. Bump org.apache.commons:commons-parent from 66 to 73 #360, #371, #395, #420. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. From aa04de7af36bfc8fad52a426ba7723e0793e6298 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 13:29:53 -0400 Subject: [PATCH 070/169] Sort members --- .../java/org/apache/commons/dbcp2/Utils.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index e9324adb6b..f67f2b60b9 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -216,17 +216,6 @@ public static Set getDisconnectionSqlCodes() { return new HashSet<>(DISCONNECTION_SQL_CODES); } - /** - * Checks if the given SQL state corresponds to a fatal connection error. - * - * @param sqlState the SQL state to check. - * @return true if the SQL state is a fatal connection error, false otherwise. - * @since 2.13.0 - */ - static boolean isDisconnectionSqlCode(String sqlState) { - return DISCONNECTION_SQL_CODES.contains(sqlState); - } - /** * Gets the correct i18n message for the given key. * @@ -253,6 +242,17 @@ public static String getMessage(final String key, final Object... args) { return mf.format(args, new StringBuffer(), null).toString(); } + /** + * Checks if the given SQL state corresponds to a fatal connection error. + * + * @param sqlState the SQL state to check. + * @return true if the SQL state is a fatal connection error, false otherwise. + * @since 2.13.0 + */ + static boolean isDisconnectionSqlCode(String sqlState) { + return DISCONNECTION_SQL_CODES.contains(sqlState); + } + static boolean isEmpty(final Collection collection) { return collection == null || collection.isEmpty(); } From 94736302cebadfcf7fd4ef621a9d6ffba4e40cc2 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 13:31:17 -0400 Subject: [PATCH 071/169] Sort imports --- src/test/java/org/apache/commons/dbcp2/TestUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestUtils.java b/src/test/java/org/apache/commons/dbcp2/TestUtils.java index 395d25b26b..0d0b157328 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestUtils.java +++ b/src/test/java/org/apache/commons/dbcp2/TestUtils.java @@ -23,13 +23,13 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Test; - import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import org.junit.jupiter.api.Test; + public class TestUtils { public static PStmtKey getPStmtKey(final PoolablePreparedStatement poolablePreparedStatement) { From 088e4a7197811bd310d513b71ccf3cf83ba09a7c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 19 Aug 2024 13:32:58 -0400 Subject: [PATCH 072/169] Use final Remove trailing whitespace --- .../org/apache/commons/dbcp2/PoolableConnectionFactory.java | 2 +- src/main/java/org/apache/commons/dbcp2/Utils.java | 2 +- src/test/java/org/apache/commons/dbcp2/TesterDriver.java | 2 +- .../apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java | 2 +- .../commons/dbcp2/datasources/TestPerUserPoolDataSource.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java index c2f12d2e5a..c182d17421 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java @@ -628,7 +628,7 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation * @throws IllegalArgumentException if any SQL state codes overlap with those in {@link #disconnectionSqlCodes}. * @since 2.13.0 */ - public void setDisconnectionIgnoreSqlCodes(Collection disconnectionIgnoreSqlCodes) { + public void setDisconnectionIgnoreSqlCodes(final Collection disconnectionIgnoreSqlCodes) { Utils.checkSqlCodes(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes); this.disconnectionIgnoreSqlCodes = disconnectionIgnoreSqlCodes; } diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index f67f2b60b9..7e3e7c7af0 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -249,7 +249,7 @@ public static String getMessage(final String key, final Object... args) { * @return true if the SQL state is a fatal connection error, false otherwise. * @since 2.13.0 */ - static boolean isDisconnectionSqlCode(String sqlState) { + static boolean isDisconnectionSqlCode(final String sqlState) { return DISCONNECTION_SQL_CODES.contains(sqlState); } diff --git a/src/test/java/org/apache/commons/dbcp2/TesterDriver.java b/src/test/java/org/apache/commons/dbcp2/TesterDriver.java index 5f3c71fab6..38e3d5cf63 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterDriver.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterDriver.java @@ -40,7 +40,7 @@ * */ public class TesterDriver implements Driver { - + static TesterDriver INSTANCE = new TesterDriver(); private static final Properties validUserPasswords = new Properties(); diff --git a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java index 737466690d..784eff84b5 100644 --- a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java +++ b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java @@ -295,7 +295,7 @@ public void testIncorrectPassword() throws Exception { assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "zlsafjk"), "Able to retrieve connection with incorrect password"); // Use good password - SQLException e = assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "x"), "Able to retrieve connection with incorrect password"); + final SQLException e = assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "x"), "Able to retrieve connection with incorrect password"); assertTrue(e.getMessage().startsWith("x is not the correct password")); // else the exception was expected diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java index d74edc9fd8..4d3080edcb 100644 --- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java @@ -90,7 +90,7 @@ public void tearDown() throws Exception { ((PerUserPoolDataSource) ds).close(); } - /** + /** * See DBCP-8 */ @Test From 936d4d414afeabc1b17b699905bebed7e14f8d0e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 Aug 2024 01:46:41 -0400 Subject: [PATCH 073/169] Bump github/codeql-action from 3.26.2 to 3.26.4 (#424) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.2 to 3.26.4. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/429e1977040da7a23b6822b13c129cd1ba93dbb2...f0f3afee809481da311ca3a6ff1ff51d81dbeb24) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e5d7315bb9..4395234391 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 + uses: github/codeql-action/init@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 + uses: github/codeql-action/autobuild@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 + uses: github/codeql-action/analyze@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 5ddf1e85aa..83eee00d0b 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@429e1977040da7a23b6822b13c129cd1ba93dbb2 # 3.26.2 + uses: github/codeql-action/upload-sarif@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 with: sarif_file: results.sarif From e8cc314273a821410246060426f07818a0e643cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Aug 2024 08:34:03 -0400 Subject: [PATCH 074/169] Bump org.apache.commons:commons-parent from 73 to 74 (#426) Bumps [org.apache.commons:commons-parent](https://github.com/apache/commons-parent) from 73 to 74. - [Changelog](https://github.com/apache/commons-parent/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-parent/commits) --- updated-dependencies: - dependency-name: org.apache.commons:commons-parent dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4aea96f66b..b58137846d 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-parent - 73 + 74 4.0.0 commons-dbcp2 From 8774ea52b2093bff4a7e55776b90a141f9faef40 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 29 Aug 2024 08:34:33 -0400 Subject: [PATCH 075/169] Bump org.apache.commons:commons-parent from 73 to 74 #426 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a90740fa36..c30f5374ef 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,7 +75,7 @@ The type attribute can be add,update,fix,remove. Add support for ignoring non-fatal SQL state codes #421. - Bump org.apache.commons:commons-parent from 66 to 73 #360, #371, #395, #420. + Bump org.apache.commons:commons-parent from 66 to 74 #360, #371, #395, #420, #426. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. From 200cd6f250ba164fbf86d84d548096053b115f67 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:49:12 -0400 Subject: [PATCH 076/169] Bump org.apache.commons:commons-lang3 from 3.16.0 to 3.17.0 (#427) Bumps org.apache.commons:commons-lang3 from 3.16.0 to 3.17.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b58137846d..1409b4ae5d 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ org.apache.commons commons-lang3 - 3.16.0 + 3.17.0 test From 5492859756356b85c5851475813d4bad874e7056 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 29 Aug 2024 17:49:47 -0400 Subject: [PATCH 077/169] Bump org.apache.commons:commons-lang3 from 3.16.0 to 3.17.0 #427 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c30f5374ef..0cd2f5b691 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,7 +77,7 @@ The type attribute can be add,update,fix,remove. Bump org.apache.commons:commons-parent from 66 to 74 #360, #371, #395, #420, #426. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. - Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.16.0 #404, #412. + Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #404, #412, #427. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.16 #413, #418. From d5914a1bb4b50e00eab214d857ca5909e006c019 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 01:18:59 -0400 Subject: [PATCH 078/169] Bump github/codeql-action from 3.26.4 to 3.26.6 (#428) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.4 to 3.26.6. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/f0f3afee809481da311ca3a6ff1ff51d81dbeb24...4dd16135b69a43b6c8efb853346f8437d92d3c93) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 4395234391..52bccaf748 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 + uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 + uses: github/codeql-action/autobuild@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 + uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 83eee00d0b..da2deb7894 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # 3.26.4 + uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 with: sarif_file: results.sarif From e1960bd6dfb043024b72646b1c5d15b1638286c6 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 1 Sep 2024 18:51:01 -0400 Subject: [PATCH 079/169] Use Assertions.assertInstanceOf() --- .../java/org/apache/commons/dbcp2/TestBasicDataSource.java | 5 +++-- .../org/apache/commons/dbcp2/TestDelegatingConnection.java | 6 +++--- .../org/apache/commons/dbcp2/TestDelegatingStatement.java | 4 ++-- .../commons/dbcp2/managed/TestSynchronizationOrder.java | 5 +++-- .../commons/dbcp2/managed/TestTransactionContext.java | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java index 66c852d1c1..7e72902832 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java @@ -20,6 +20,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; @@ -112,7 +113,7 @@ public void testAccessToUnderlyingConnectionAllowed() throws Exception { dconn = ((DelegatingConnection) conn).getInnermostDelegate(); assertNotNull(dconn); - assertTrue(dconn instanceof TesterConnection); + assertInstanceOf(TesterConnection.class, dconn); } } @@ -484,7 +485,7 @@ public void testDriverClassLoader() throws Exception { try (Connection conn = getConnection()) { final ClassLoader cl = ds.getDriverClassLoader(); assertNotNull(cl); - assertTrue(cl instanceof TesterClassLoader); + assertInstanceOf(TesterClassLoader.class, cl); assertTrue(((TesterClassLoader) cl).didLoad(ds.getDriverClassName())); } } diff --git a/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java b/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java index 3519b171b4..ad712526ee 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java @@ -205,7 +205,7 @@ public void testPassivateWithResultSetCloseException() { delegatingConnection.passivate(); Assertions.fail("Expected SQLExceptionList"); } catch (final SQLException e) { - Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertInstanceOf(SQLExceptionList.class, e); Assertions.assertEquals(1, ((SQLExceptionList) e).getCauseList().size()); } finally { testerResultSet.setSqlExceptionOnClose(false); @@ -222,7 +222,7 @@ public void testPassivateWithResultSetCloseExceptionAndStatementCloseException() delegatingConnection.passivate(); Assertions.fail("Expected SQLExceptionList"); } catch (final SQLException e) { - Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertInstanceOf(SQLExceptionList.class, e); Assertions.assertEquals(2, ((SQLExceptionList) e).getCauseList().size()); } finally { testerStatement.setSqlExceptionOnClose(false); @@ -238,7 +238,7 @@ public void testPassivateWithStatementCloseException() { delegatingConnection.passivate(); Assertions.fail("Expected SQLExceptionList"); } catch (final SQLException e) { - Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertInstanceOf(SQLExceptionList.class, e); Assertions.assertEquals(1, ((SQLExceptionList) e).getCauseList().size()); } finally { testerStatement.setSqlExceptionOnClose(false); diff --git a/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java b/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java index 770e379afc..770e8443ca 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java @@ -142,7 +142,7 @@ public void testCloseWithResultSetCloseException() throws Exception { delegatingStatement.close(); Assertions.fail("Excpected a SQLExceptionList"); } catch (final SQLException e) { - Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertInstanceOf(SQLExceptionList.class, e); } finally { testerResultSet.setSqlExceptionOnClose(false); } @@ -156,7 +156,7 @@ public void testCloseWithStatementCloseException() throws Exception { delegatingTesterStatement.close(); Assertions.fail("Excpected a SQLExceptionList"); } catch (final SQLException e) { - Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertInstanceOf(SQLExceptionList.class, e); } finally { testerStatement.setSqlExceptionOnClose(false); } diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java b/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java index e37f10a943..47cb93eef6 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java @@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more package org.apache.commons.dbcp2.managed; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.InvocationHandler; @@ -187,7 +188,7 @@ public void testInterposedSynchronization() throws Exception { transactionManager.begin(); try (final Connection connectionA = ds.getConnection()) { // Check and close right away. - assertTrue(connectionA instanceof DelegatingConnection); + assertInstanceOf(DelegatingConnection.class, connectionA); } transactionManager.commit(); assertFalse(transactionManagerRegistered); @@ -220,7 +221,7 @@ public void testSessionSynchronization() throws Exception { transactionManager.begin(); try (final Connection connectionA = ds.getConnection()) { // Check and close right away. - assertTrue(connectionA instanceof DelegatingConnection); + assertInstanceOf(DelegatingConnection.class, connectionA); } transactionManager.commit(); assertTrue(transactionManagerRegistered); diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java b/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java index 2c46cd8c38..211cca002e 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java @@ -17,8 +17,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more */ package org.apache.commons.dbcp2.managed; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; import java.sql.SQLException; @@ -62,7 +62,7 @@ public void testSetSharedConnectionEnlistFailure() throws Exception { basicManagedDataSource.setPassword("password"); basicManagedDataSource.setMaxIdle(1); try (final Connection conn = basicManagedDataSource.getConnection()) { - assertTrue(conn instanceof ManagedConnection); + assertInstanceOf(ManagedConnection.class, conn); final UncooperativeTransaction transaction = new UncooperativeTransaction(); final TransactionContext transactionContext = new TransactionContext(basicManagedDataSource.getTransactionRegistry(), transaction); assertThrows(SQLException.class, () -> transactionContext.setSharedConnection(conn)); From 476048ede93f257d566510cf7021de30ee5eedb9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:09:04 -0700 Subject: [PATCH 080/169] Bump actions/upload-artifact from 4.3.6 to 4.4.0 (#429) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.6 to 4.4.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/834a144ee995460fba8ed112a2fc961b36a5ec5a...50769540e7f4bd5e21e526ee35c689e35e0d6874) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/scorecards-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index da2deb7894..c18f0c3f12 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -57,7 +57,7 @@ jobs: publish_results: true - name: "Upload artifact" - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # 4.3.6 + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # 4.4.0 with: name: SARIF file path: results.sarif From 40fc857adb7f4948297ea89473d0686a3a8c3408 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2024 08:36:52 -0400 Subject: [PATCH 081/169] Convert cascading if-else to switch --- .../commons/dbcp2/BasicDataSourceFactory.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java index 84beb588dd..11a154c90a 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java @@ -239,17 +239,23 @@ public static BasicDataSource createDataSource(final Properties properties) thro getOptional(properties, PROP_DEFAULT_TRANSACTION_ISOLATION).ifPresent(value -> { value = value.toUpperCase(Locale.ROOT); int level = PoolableConnectionFactory.UNKNOWN_TRANSACTION_ISOLATION; - if ("NONE".equals(value)) { + switch (value) { + case "NONE": level = Connection.TRANSACTION_NONE; - } else if ("READ_COMMITTED".equals(value)) { + break; + case "READ_COMMITTED": level = Connection.TRANSACTION_READ_COMMITTED; - } else if ("READ_UNCOMMITTED".equals(value)) { + break; + case "READ_UNCOMMITTED": level = Connection.TRANSACTION_READ_UNCOMMITTED; - } else if ("REPEATABLE_READ".equals(value)) { + break; + case "REPEATABLE_READ": level = Connection.TRANSACTION_REPEATABLE_READ; - } else if ("SERIALIZABLE".equals(value)) { + break; + case "SERIALIZABLE": level = Connection.TRANSACTION_SERIALIZABLE; - } else { + break; + default: try { level = Integer.parseInt(value); } catch (final NumberFormatException e) { @@ -258,6 +264,7 @@ public static BasicDataSource createDataSource(final Properties properties) thro System.err.println("using default value of database driver"); level = PoolableConnectionFactory.UNKNOWN_TRANSACTION_ISOLATION; } + break; } dataSource.setDefaultTransactionIsolation(level); }); From 4ee88ee0da027cd7f5dac64c6157ff60ee56d04e Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2024 08:36:57 -0400 Subject: [PATCH 082/169] Convert cascading if-else to switch --- .../managed/TestDataSourceXAConnectionFactory.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java b/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java index 6646bb13fc..870876589a 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java @@ -55,15 +55,16 @@ protected XAConnection getXAConnection() throws SQLException { public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final String methodName = method.getName(); - if (methodName.equals("hashCode")) { + switch (methodName) { + case "hashCode": return System.identityHashCode(proxy); - } - if (methodName.equals("equals")) { + case "equals": return proxy == args[0]; - } - if (methodName.equals("getXAConnection")) { + case "getXAConnection": // both zero and 2-arg signatures return getXAConnection(); + default: + break; } try { return method.invoke(ds, args); From 010b028376bb576fd52f074b2c78a7de78b2e643 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2024 08:37:02 -0400 Subject: [PATCH 083/169] Convert cascading if-else to switch --- .../dbcp2/managed/TesterBasicXAConnection.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java b/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java index 9d36c93c25..b5994ef594 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TesterBasicXAConnection.java @@ -75,17 +75,17 @@ public void closeHandle() { public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final String methodName = method.getName(); - if (methodName.equals("hashCode")) { + switch (methodName) { + case "hashCode": return System.identityHashCode(proxy); - } - if (methodName.equals("equals")) { + case "equals": return proxy == args[0]; - } - if (methodName.equals("isClosed")) { + case "isClosed": return conn == null; - } - if (methodName.equals("close")) { + case "close": return close(); + default: + break; } if (conn == null) { throw new SQLException("Connection closed"); From 1743fdd9f0f2a5a4d13b84c42c49803d22e4d810 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2024 08:37:06 -0400 Subject: [PATCH 084/169] Convert cascading if-else to switch --- .../org/apache/commons/dbcp2/TesterConnection.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TesterConnection.java b/src/test/java/org/apache/commons/dbcp2/TesterConnection.java index 3e6e4bb4e6..449801719c 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterConnection.java @@ -282,14 +282,15 @@ public CallableStatement prepareCall(final String sql, final int resultSetType, @Override public PreparedStatement prepareStatement(final String sql) throws SQLException { checkOpen(); - if ("null".equals(sql)) { + switch (sql) { + case "null": return null; - } - if ("invalid".equals(sql)) { + case "invalid": throw new SQLException("invalid query"); - } - if ("broken".equals(sql)) { + case "broken": throw new SQLException("broken connection"); + default: + break; } return new TesterPreparedStatement(this, sql); } From 78eca7e16d8d16669dd28b6da03cea997b61c657 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2024 08:37:09 -0400 Subject: [PATCH 085/169] Convert cascading if-else to switch --- .../org/apache/commons/dbcp2/TesterStatement.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java index 0b6479c8fb..764372693d 100644 --- a/src/test/java/org/apache/commons/dbcp2/TesterStatement.java +++ b/src/test/java/org/apache/commons/dbcp2/TesterStatement.java @@ -175,20 +175,21 @@ public long executeLargeUpdate(final String sql, final String[] columnNames) thr @Override public ResultSet executeQuery(final String sql) throws SQLException { checkOpen(); - if ("null".equals(sql)) { + switch (sql) { + case "null": return null; - } - if ("invalid".equals(sql)) { + case "invalid": throw new SQLException("invalid query"); - } - if ("broken".equals(sql)) { + case "broken": throw new SQLException("broken connection"); - } - if ("select username".equals(sql)) { + case "select username": { final String userName = ((TesterConnection) connection).getUserName(); final Object[][] data = { { userName } }; return new TesterResultSet(this, data); } + default: + break; + } // Simulate timeout if queryTimout is set to less than 5 seconds if (queryTimeout > 0 && queryTimeout < 5) { throw new SQLException("query timeout"); From 6d1153f0d5b5307f026a414bf443b3fc40ac2af5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 12 Sep 2024 08:41:29 -0400 Subject: [PATCH 086/169] Convert cascading if-else to switch --- .../dbcp2/managed/TestSynchronizationOrder.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java b/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java index 47cb93eef6..81ba125689 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java @@ -134,15 +134,16 @@ protected XAConnection getXAConnection() throws SQLException { public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final String methodName = method.getName(); - if (methodName.equals("hashCode")) { + switch (methodName) { + case "hashCode": return System.identityHashCode(proxy); - } - if (methodName.equals("equals")) { + case "equals": return proxy == args[0]; - } - if (methodName.equals("getXAConnection")) { + case "getXAConnection": // both zero and 2-arg signatures return getXAConnection(); + default: + break; } try { return method.invoke(bds, args); From d90918027f353ab8db3839c64a095c93ef859576 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 02:51:50 -0400 Subject: [PATCH 087/169] Bump actions/setup-java from 4.2.2 to 4.3.0 (#431) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.2.2 to 4.3.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/6a0805fcefea3d4657a47ac4c165951e33482018...2dfa2011c5b2a0f1489bf9e433881c92c1631f88) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 822b7994d4..64be3c59af 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,7 +46,7 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4.2.2 + uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4.3.0 with: distribution: 'temurin' java-version: ${{ matrix.java }} From 5cafbb3c5fc8c1e20b0b693130830dc8c2ee7c35 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 18 Sep 2024 20:33:54 -0400 Subject: [PATCH 088/169] CI builds: Replace Java 22 with Java 23 --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 64be3c59af..0f957feca3 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,10 +27,10 @@ jobs: continue-on-error: ${{ matrix.experimental }} strategy: matrix: - java: [ 8, 11, 17, 21, 22 ] + java: [ 8, 11, 17, 21 ] experimental: [false] include: - - java: 23-ea + - java: 23 experimental: true - java: 24-ea experimental: true From 09f7209c5080270bcfef90685b12135e73f8e111 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Sep 2024 01:07:50 -0400 Subject: [PATCH 089/169] Bump github/codeql-action from 3.26.6 to 3.26.8 (#433) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.6 to 3.26.8. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/4dd16135b69a43b6c8efb853346f8437d92d3c93...294a9d92911152fe08befb9ec03e240add280cb3) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 52bccaf748..cb162be7d4 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 + uses: github/codeql-action/init@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 + uses: github/codeql-action/autobuild@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 + uses: github/codeql-action/analyze@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index c18f0c3f12..f80c265c40 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # 3.26.6 + uses: github/codeql-action/upload-sarif@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 with: sarif_file: results.sarif From 007181535220e81f9fe5bc0cd3cc8adaca190c9f Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 20 Sep 2024 19:59:17 -0400 Subject: [PATCH 090/169] Add dependency-review.yml to GitHub CI --- .github/workflows/dependency-review.yml | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/dependency-review.yml diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000000..0748cf09ac --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v4 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v4 From 7d932ac73576bd93873cb05b13ed7139240cca35 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 23 Sep 2024 09:28:33 -0400 Subject: [PATCH 091/169] Also run DR on push --- .github/workflows/dependency-review.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 0748cf09ac..ae11bd031b 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -16,7 +16,7 @@ # under the License. name: 'Dependency Review' -on: [pull_request] +on: [push, pull_request] permissions: contents: read @@ -27,5 +27,8 @@ jobs: steps: - name: 'Checkout Repository' uses: actions/checkout@v4 - - name: 'Dependency Review' - uses: actions/dependency-review-action@v4 + - name: 'Dependency Review PR' + uses: actions/dependency-review-action@v4.3.4 + with: + base-ref: ${{ github.event.before }} + head-ref: ${{ github.sha }} From 295cb3251d7c2239110dacd31ce0a0ba21d842b8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 04:22:24 -0400 Subject: [PATCH 092/169] Bump github/codeql-action from 3.26.8 to 3.26.9 (#434) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.8 to 3.26.9. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/294a9d92911152fe08befb9ec03e240add280cb3...461ef6c76dfe95d5c364de2f431ddbd31a417628) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index cb162be7d4..637f98ab79 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 + uses: github/codeql-action/init@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 + uses: github/codeql-action/autobuild@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 + uses: github/codeql-action/analyze@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index f80c265c40..dcf5cbaeff 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@294a9d92911152fe08befb9ec03e240add280cb3 # 3.26.8 + uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 with: sarif_file: results.sarif From b6955bf4129162d4c1f5eb4ae8dae953a18c273c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 04:22:41 -0400 Subject: [PATCH 093/169] Bump actions/setup-java from 4.3.0 to 4.4.0 (#435) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.3.0 to 4.4.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/2dfa2011c5b2a0f1489bf9e433881c92c1631f88...b36c23c0d998641eff861008f374ee103c25ac73) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0f957feca3..b6d422d936 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,7 +46,7 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4.3.0 + uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 with: distribution: 'temurin' java-version: ${{ matrix.java }} From 391e51b3f20876db0361e3b16bff2ed5ef51acf7 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 28 Sep 2024 16:20:14 -0400 Subject: [PATCH 094/169] Pin GitHub action versions --- .github/workflows/dependency-review.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index ae11bd031b..173a3f1ac5 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -26,9 +26,9 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout Repository' - uses: actions/checkout@v4 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: 'Dependency Review PR' - uses: actions/dependency-review-action@v4.3.4 + uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 with: base-ref: ${{ github.event.before }} head-ref: ${{ github.sha }} From c519311deaa4cf8a429db7464d54b20109b7af86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 28 Sep 2024 20:52:18 -0400 Subject: [PATCH 095/169] Bump org.apache.commons:commons-parent from 74 to 76 (#436) Bumps [org.apache.commons:commons-parent](https://github.com/apache/commons-parent) from 74 to 76. - [Changelog](https://github.com/apache/commons-parent/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-parent/commits) --- updated-dependencies: - dependency-name: org.apache.commons:commons-parent dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1409b4ae5d..2eff6db1b4 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-parent - 74 + 76 4.0.0 commons-dbcp2 From 1b1c81d42dd96d08217bee7672f5a00e5eebc38b Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 28 Sep 2024 20:52:56 -0400 Subject: [PATCH 096/169] Bump org.apache.commons:commons-parent from 74 to 76 #436 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0cd2f5b691..802c9f0fd3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,7 +75,7 @@ The type attribute can be add,update,fix,remove. Add support for ignoring non-fatal SQL state codes #421. - Bump org.apache.commons:commons-parent from 66 to 74 #360, #371, #395, #420, #426. + Bump org.apache.commons:commons-parent from 66 to 76 #360, #371, #395, #420, #426, #436. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #404, #412, #427. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. From 98933fef0bb41372a59ec566b791aa32cc54fb48 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 1 Oct 2024 10:40:29 -0400 Subject: [PATCH 097/169] Make test more readable and maintainable, and less verbose - Use JUnit 5 APIs - Be consistent throughout tests --- pom.xml | 14 -------------- .../apache/commons/dbcp2/TestBasicDataSource.java | 5 +---- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 2eff6db1b4..fcb72d6319 100644 --- a/pom.xml +++ b/pom.xml @@ -59,40 +59,34 @@ commons-pool2 ${commons.pool.version}
    - commons-logging commons-logging 1.3.4 - org.junit.jupiter junit-jupiter test - org.mockito mockito-core 4.11.0 test - org.apache.commons commons-lang3 3.17.0 test - jakarta.transaction jakarta.transaction-api 1.3.3 - tomcat @@ -100,14 +94,12 @@ 5.0.28 test - tomcat naming-java 5.0.28 test - org.apache.geronimo.modules @@ -163,12 +155,6 @@ 3.4.3.Final test - - org.hamcrest - hamcrest - 3.0 - test - diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java index 7e72902832..bffe838723 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java @@ -17,7 +17,6 @@ package org.apache.commons.dbcp2; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -49,7 +48,6 @@ import javax.management.ObjectName; import javax.sql.DataSource; -import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -577,8 +575,7 @@ public void testInstanceNotFoundExceptionLogSuppressed() throws Exception { } StackMessageLog.clear(); ds.close(); - assertThat(StackMessageLog.popMessage(), - CoreMatchers.not(CoreMatchers.containsString("InstanceNotFoundException"))); + assertNull(StackMessageLog.popMessage()); assertNull(ds.getRegisteredJmxName()); } From 1d71ab447c9c6d01496bcb9a00bdec95f3d8d486 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:29:42 -0400 Subject: [PATCH 098/169] Bump actions/checkout from 4.1.7 to 4.2.0 (#438) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.7 to 4.2.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/692973e3d937129bcbf40652eb9f2f61becf3332...d632683dd7b4114ad314bca15554477dd762a938) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/dependency-review.yml | 2 +- .github/workflows/maven.yml | 2 +- .github/workflows/scorecards-analysis.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 637f98ab79..467265101f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 173a3f1ac5..13f691e212 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout Repository' - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: 'Dependency Review PR' uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 with: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b6d422d936..9785b74ed0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -36,7 +36,7 @@ jobs: experimental: true steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index dcf5cbaeff..d837145b6e 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -40,7 +40,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false From 171dd1e271d347e02e8e90689548c1ad1ac6ac9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:29:56 -0400 Subject: [PATCH 099/169] Bump github/codeql-action from 3.26.9 to 3.26.11 (#439) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.9 to 3.26.11. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/461ef6c76dfe95d5c364de2f431ddbd31a417628...6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 467265101f..3ec6f22dff 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 + uses: github/codeql-action/init@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 + uses: github/codeql-action/autobuild@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 + uses: github/codeql-action/analyze@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index d837145b6e..7a4b0a5397 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # 3.26.9 + uses: github/codeql-action/upload-sarif@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 with: sarif_file: results.sarif From de897d5f116d5fda2576921647c428596ff595ab Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 6 Oct 2024 08:44:51 -0400 Subject: [PATCH 100/169] Fix Javadoc on Java 23 --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index fcb72d6319..825947c054 100644 --- a/pom.xml +++ b/pom.xml @@ -240,9 +240,8 @@ ${commons.javadoc.version} - http://docs.oracle.com/javase/8/docs/api https://commons.apache.org/proper/commons-pool/apidocs - http://docs.oracle.com/javaee/7/api/ + ${commons.javadoc.javaee.link} From 2fc0bbd114a344e4ca24bfc041c1c8d016a77292 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 6 Oct 2024 08:48:43 -0400 Subject: [PATCH 101/169] The Java 23 build is no longer experimental --- .github/workflows/maven.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9785b74ed0..61255bc6d1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,11 +27,9 @@ jobs: continue-on-error: ${{ matrix.experimental }} strategy: matrix: - java: [ 8, 11, 17, 21 ] + java: [ 8, 11, 17, 21, 23 ] experimental: [false] include: - - java: 23 - experimental: true - java: 24-ea experimental: true From 7faad73248c3ae51189e2c0f527545e5880c6733 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:09:30 -0400 Subject: [PATCH 102/169] Bump org.apache.commons:commons-parent from 76 to 77 (#441) Bumps [org.apache.commons:commons-parent](https://github.com/apache/commons-parent) from 76 to 77. - [Changelog](https://github.com/apache/commons-parent/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-parent/commits) --- updated-dependencies: - dependency-name: org.apache.commons:commons-parent dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 825947c054..d8dbc49122 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-parent - 76 + 77 4.0.0 commons-dbcp2 From 8df7aca94a32f1caefcd626e2a687239abe84432 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 9 Oct 2024 15:10:03 -0400 Subject: [PATCH 103/169] Bump org.apache.commons:commons-parent from 76 to 77 #441 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 802c9f0fd3..ec1058b14b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,7 +75,7 @@ The type attribute can be add,update,fix,remove. Add support for ignoring non-fatal SQL state codes #421. - Bump org.apache.commons:commons-parent from 66 to 76 #360, #371, #395, #420, #426, #436. + Bump org.apache.commons:commons-parent from 66 to 77 #360, #371, #395, #420, #426, #436, #441. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #404, #412, #427. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. From 77c21e796215481b2ed0483fb3c5301e290f70c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 04:02:41 -0400 Subject: [PATCH 104/169] Bump github/codeql-action from 3.26.11 to 3.26.12 (#442) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.11 to 3.26.12. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea...c36620d31ac7c881962c3d9dd939c40ec9434f2b) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3ec6f22dff..102e2a21ba 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 + uses: github/codeql-action/init@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 + uses: github/codeql-action/autobuild@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 + uses: github/codeql-action/analyze@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 7a4b0a5397..25e76ae80f 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # 3.26.11 + uses: github/codeql-action/upload-sarif@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 with: sarif_file: results.sarif From 80ffd54656d7600530b28a2794f89fc87ea94fe0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 04:02:58 -0400 Subject: [PATCH 105/169] Bump actions/upload-artifact from 4.4.0 to 4.4.3 (#445) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.4.0 to 4.4.3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/50769540e7f4bd5e21e526ee35c689e35e0d6874...b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/scorecards-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 25e76ae80f..a43544c988 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -57,7 +57,7 @@ jobs: publish_results: true - name: "Upload artifact" - uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # 4.4.0 + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # 4.4.3 with: name: SARIF file path: results.sarif From 097b2dc08bb10b58260e58c64406e03d1960fd1e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 04:03:24 -0400 Subject: [PATCH 106/169] Bump actions/checkout from 4.2.0 to 4.2.1 (#444) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/d632683dd7b4114ad314bca15554477dd762a938...eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/dependency-review.yml | 2 +- .github/workflows/maven.yml | 2 +- .github/workflows/scorecards-analysis.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 102e2a21ba..3fcbbcbd73 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 13f691e212..21e60b1a96 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout Repository' - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 - name: 'Dependency Review PR' uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 with: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 61255bc6d1..72fc46d896 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -34,7 +34,7 @@ jobs: experimental: true steps: - - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index a43544c988..621296f849 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -40,7 +40,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 + uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false From 9d805e06b1cba28ff43d731e9fd7b53899dd131e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 04:03:39 -0400 Subject: [PATCH 107/169] Bump actions/cache from 4.0.2 to 4.1.1 (#443) Bumps [actions/cache](https://github.com/actions/cache) from 4.0.2 to 4.1.1. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/0c45773b623bea8c8e75f6c82b208c3cf94ea4f9...3624ceb22c1c5a301c8db4169662070a689d9ea8) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/maven.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3fcbbcbd73..99c1907d45 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -48,7 +48,7 @@ jobs: uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false - - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + - uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 72fc46d896..836efc5564 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false - - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + - uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} From e995fc7857de3fb85034dc390fcfac198adf2eca Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 14 Oct 2024 07:09:49 -0400 Subject: [PATCH 108/169] Fix GH badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f467f4ec4c..4f40191be5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Apache Commons DBCP =================== [![Java CI](https://github.com/apache/commons-dbcp/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/maven.yml) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/?gav=true) +[![Maven Central](https://img.shields.io/maven-central/v/org.apache.commons/commons-dbcp2?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.commons/commons-dbcp2) [![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.12.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.12.0) [![CodeQL](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp) From f352219966a48b8f01068f34d72c86d8807239a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 03:09:00 -0400 Subject: [PATCH 109/169] Bump github/codeql-action from 3.26.12 to 3.26.13 (#446) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.12 to 3.26.13. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/c36620d31ac7c881962c3d9dd939c40ec9434f2b...f779452ac5af1c261dce0346a8f964149f49322b) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 99c1907d45..c99ebe62f2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 + uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 + uses: github/codeql-action/autobuild@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 + uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 621296f849..86f966c45f 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@c36620d31ac7c881962c3d9dd939c40ec9434f2b # 3.26.12 + uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 with: sarif_file: results.sarif From 3c438d439e3e00c0ea5f2651b125030e5f80e6e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:32:29 -0400 Subject: [PATCH 110/169] Bump org.apache.commons:commons-parent from 77 to 78 (#449) Bumps [org.apache.commons:commons-parent](https://github.com/apache/commons-parent) from 77 to 78. - [Changelog](https://github.com/apache/commons-parent/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-parent/commits) --- updated-dependencies: - dependency-name: org.apache.commons:commons-parent dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d8dbc49122..d1fcf22b6c 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.apache.commons commons-parent - 77 + 78 4.0.0 commons-dbcp2 From 93e27b321097082e2104c5988bd374315937c76d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 22 Oct 2024 10:33:00 -0400 Subject: [PATCH 111/169] Bump org.apache.commons:commons-parent from 77 to 78 #449 --- src/changes/changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ec1058b14b..814d8f6a06 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -75,7 +75,7 @@ The type attribute can be add,update,fix,remove. Add support for ignoring non-fatal SQL state codes #421. - Bump org.apache.commons:commons-parent from 66 to 77 #360, #371, #395, #420, #426, #436, #441. + Bump org.apache.commons:commons-parent from 66 to 78 #360, #371, #395, #420, #426, #436, #441, #449. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #404, #412, #427. Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. From 795cbabeb221564031d38b715381822b04a90eab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 05:59:23 -0400 Subject: [PATCH 112/169] Bump actions/dependency-review-action from 4.3.4 to 4.3.5 (#450) Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.3.4 to 4.3.5. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/5a2ce3f5b92ee19cbb1541a4984c76d921601d7c...a6993e2c61fd5dc440b409aa1d6904921c5e1894) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dependency-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 21e60b1a96..c13bd3f92e 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -28,7 +28,7 @@ jobs: - name: 'Checkout Repository' uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 - name: 'Dependency Review PR' - uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 + uses: actions/dependency-review-action@a6993e2c61fd5dc440b409aa1d6904921c5e1894 # v4.3.5 with: base-ref: ${{ github.event.before }} head-ref: ${{ github.sha }} From 4f3820ffa71680b3aad2a9e5a973aee51e0db197 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 05:59:41 -0400 Subject: [PATCH 113/169] Bump actions/cache from 4.1.1 to 4.1.2 (#454) Bumps [actions/cache](https://github.com/actions/cache) from 4.1.1 to 4.1.2. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/3624ceb22c1c5a301c8db4169662070a689d9ea8...6849a6489940f00c2f30c0fb92c6274307ccb58a) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/maven.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c99ebe62f2..5e45af8db9 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -48,7 +48,7 @@ jobs: uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false - - uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1 + - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 836efc5564..5dfd4c3276 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 with: persist-credentials: false - - uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1 + - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} From 52e032cada5b51910f3bb9632ce94e019853ede2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 05:59:53 -0400 Subject: [PATCH 114/169] Bump actions/setup-java from 4.4.0 to 4.5.0 (#453) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/b36c23c0d998641eff861008f374ee103c25ac73...8df1039502a15bceb9433410b1a100fbe190c53b) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5dfd4c3276..57e5cea96d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -44,7 +44,7 @@ jobs: restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4.4.0 + uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0 with: distribution: 'temurin' java-version: ${{ matrix.java }} From a45209f87bbbdfbc2925e21101f885a5ce97b709 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 06:00:07 -0400 Subject: [PATCH 115/169] Bump github/codeql-action from 3.26.13 to 3.27.0 (#452) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.13 to 3.27.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/f779452ac5af1c261dce0346a8f964149f49322b...662472033e021d55d94146f66f6058822b0b39fd) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5e45af8db9..d5d9fd7900 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 + uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 + uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 + uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 86f966c45f..cccd14dc95 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # 3.26.13 + uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 with: sarif_file: results.sarif From 2859c8ea41ce4e505c08877691fe0b7aa0d22ee2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 06:02:13 -0400 Subject: [PATCH 116/169] Bump actions/checkout from 4.2.1 to 4.2.2 (#451) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.2.1 to 4.2.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871...11bd71901bbe5b1630ceea73d27597364c9af683) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/dependency-review.yml | 2 +- .github/workflows/maven.yml | 2 +- .github/workflows/scorecards-analysis.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d5d9fd7900..ebb0e32a39 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,7 +45,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index c13bd3f92e..a932f55dd4 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout Repository' - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: 'Dependency Review PR' uses: actions/dependency-review-action@a6993e2c61fd5dc440b409aa1d6904921c5e1894 # v4.3.5 with: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 57e5cea96d..7ef29c773e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -34,7 +34,7 @@ jobs: experimental: true steps: - - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index cccd14dc95..ac3fdad816 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -40,7 +40,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false From 0e290f516cef464dfebb38a6ea56855d542aee0a Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 1 Nov 2024 07:31:41 -0400 Subject: [PATCH 117/169] Only run actions/dependency-review-action on pull_request --- .github/workflows/dependency-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index a932f55dd4..47e7d042b7 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -16,7 +16,7 @@ # under the License. name: 'Dependency Review' -on: [push, pull_request] +on: [pull_request] permissions: contents: read From 21d22b8c92a6bbd47f87dc9b0dbbe6fc64fbce9c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 09:07:43 -0400 Subject: [PATCH 118/169] Bump actions/dependency-review-action from 4.3.5 to 4.4.0 (#455) Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.3.5 to 4.4.0. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/a6993e2c61fd5dc440b409aa1d6904921c5e1894...4081bf99e2866ebe428fc0477b69eb4fcda7220a) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dependency-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 47e7d042b7..154ab43040 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -28,7 +28,7 @@ jobs: - name: 'Checkout Repository' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: 'Dependency Review PR' - uses: actions/dependency-review-action@a6993e2c61fd5dc440b409aa1d6904921c5e1894 # v4.3.5 + uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0 with: base-ref: ${{ github.event.before }} head-ref: ${{ github.sha }} From 04933534b1df11ed575d83cabb005b29afa3501c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 3 Nov 2024 14:31:34 -0500 Subject: [PATCH 119/169] PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError --- src/changes/changes.xml | 1 + .../org/apache/commons/dbcp2/PoolableConnectionFactory.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 814d8f6a06..8ce351cb7d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -72,6 +72,7 @@ The type attribute can be add,update,fix,remove. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. Avoid object creation when invoking isDisconnectionSqlException #422. + PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. Add support for ignoring non-fatal SQL state codes #421. diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java index c182d17421..3a4f65cd26 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java @@ -149,7 +149,7 @@ public void destroyObject(final PooledObject p) throws SQLEx @Override public void destroyObject(final PooledObject p, final DestroyMode mode) throws SQLException { if (mode == DestroyMode.ABANDONED) { - p.getObject().getInnermostDelegate().abort(Runnable::run); + Jdbc41Bridge.abort(p.getObject().getInnermostDelegate(), Runnable::run); } else { p.getObject().reallyClose(); } From b85809ee82bfa3204c47e5717732375019545ef2 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 15:52:17 -0500 Subject: [PATCH 120/169] Fix up action types Add reference to DBCP-599 --- src/changes/changes.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8ce351cb7d..29373c5dea 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -64,17 +64,17 @@ The type attribute can be add,update,fix,remove. - Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. - Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. - Fix PMD UnnecessaryFullyQualifiedName in PoolablePreparedStatement. - Fix PMD UnnecessaryFullyQualifiedName in Utils. - Fix PMD UnnecessaryFullyQualifiedName in LocalXAConnectionFactory. - Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. - Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. - Avoid object creation when invoking isDisconnectionSqlException #422. - PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. + Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. + Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. + Fix PMD UnnecessaryFullyQualifiedName in PoolablePreparedStatement. + Fix PMD UnnecessaryFullyQualifiedName in Utils. + Fix PMD UnnecessaryFullyQualifiedName in LocalXAConnectionFactory. + Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. + Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. + Avoid object creation when invoking isDisconnectionSqlException #422. + PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. - Add support for ignoring non-fatal SQL state codes #421. + Add support for ignoring non-fatal SQL state codes #421. Bump org.apache.commons:commons-parent from 66 to 78 #360, #371, #395, #420, #426, #436, #441, #449. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. From 65fe477e09dd1d212533be638c4d8379c21de894 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 15:54:22 -0500 Subject: [PATCH 121/169] Remove old code comments --- src/main/java/org/apache/commons/dbcp2/Utils.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index 7e3e7c7af0..16f23a2fff 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -94,13 +94,6 @@ public final class Utils { * @since 2.13.0 */ static void checkSqlCodes(final Collection codes1, final Collection codes2) { -// if (codes1 != null && codes2 != null) { -// for (String code : codes1) { -// if (codes2.contains(code)) { -// throw new IllegalArgumentException(code + " cannot be in both disconnectionSqlCodes and disconnectionIgnoreSqlCodes."); -// } -// } -// } if (codes1 != null && codes2 != null) { final Set test = new HashSet<>(codes1); test.retainAll(codes2); From f12500a00ebcf741f423ea997afdb3f6d54f2e03 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 16:03:44 -0500 Subject: [PATCH 122/169] DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge --- src/changes/changes.xml | 2 ++ .../java/org/apache/commons/dbcp2/DelegatingConnection.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 29373c5dea..32af9da4f8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -73,6 +73,8 @@ The type attribute can be add,update,fix,remove. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. Avoid object creation when invoking isDisconnectionSqlException #422. PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. + DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. + DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Add support for ignoring non-fatal SQL state codes #421. diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java index 9231246a4d..3aec922b23 100644 --- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java @@ -974,7 +974,7 @@ public void setSchema(final String schema) throws SQLException { try { Jdbc41Bridge.setSchema(connection, schema); if (cacheState) { - cachedSchema = connection.getSchema(); + cachedSchema = Jdbc41Bridge.getSchema(connection); } } catch (final SQLException e) { cachedSchema = null; From 566203def248935fa8a4e6ff18b98205e19bfd02 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 17:07:56 -0500 Subject: [PATCH 123/169] Javadoc --- src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index 963010286d..a06e6dcc68 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -1642,10 +1642,10 @@ protected void log(final String message) { } /** - * Logs the given throwable. - * @param message TODO - * @param throwable the throwable. + * Logs the given message and throwable. * + * @param message value to be log. + * @param throwable the throwable. * @since 2.7.0 */ protected void log(final String message, final Throwable throwable) { From a3f8a1a902f18460d18c77070680ec1ecf5d1703 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 17:21:09 -0500 Subject: [PATCH 124/169] Add @FunctionalInterface to SwallowedExceptionListener --- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 32af9da4f8..a0ce5bafcf 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,6 +77,7 @@ The type attribute can be add,update,fix,remove. DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Add support for ignoring non-fatal SQL state codes #421. + Add @FunctionalInterface to SwallowedExceptionListener. Bump org.apache.commons:commons-parent from 66 to 78 #360, #371, #395, #420, #426, #436, #441, #449. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. From 2e8eb15a2250d8040806d64eeb55acd368774559 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 17:24:46 -0500 Subject: [PATCH 125/169] Update action description DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge --- src/changes/changes.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a0ce5bafcf..2c7045c440 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -72,8 +72,7 @@ The type attribute can be add,update,fix,remove. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. Avoid object creation when invoking isDisconnectionSqlException #422. - PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. - DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. + PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Add support for ignoring non-fatal SQL state codes #421. From fab4c7853af8b29d1840cec3ad657295e5dedcdb Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 17:30:02 -0500 Subject: [PATCH 126/169] Javadoc --- .../commons/dbcp2/managed/TransactionContextListener.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/managed/TransactionContextListener.java b/src/main/java/org/apache/commons/dbcp2/managed/TransactionContextListener.java index 4ebb7e7133..cc1b34c1c7 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/TransactionContextListener.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/TransactionContextListener.java @@ -22,13 +22,14 @@ * @since 2.0 */ public interface TransactionContextListener { + /** - * Occurs after the transaction commits or rolls back. + * Called after a transaction commits or rolls back. * * @param transactionContext - * the transaction context that completed + * the transaction context that completed. * @param committed - * true if the transaction committed; false otherwise + * true if the transaction committed; false otherwise. */ void afterCompletion(TransactionContext transactionContext, boolean committed); } From 4582d02e71d4502c2b57535da2a3fa6072de24f0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 17:31:16 -0500 Subject: [PATCH 127/169] Javadoc No need for fully-qualifed type names --- .../apache/commons/dbcp2/managed/XAConnectionFactory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/managed/XAConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/managed/XAConnectionFactory.java index 3421fda810..abef80981a 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/XAConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/XAConnectionFactory.java @@ -30,16 +30,16 @@ * @since 2.0 */ public interface XAConnectionFactory extends ConnectionFactory { + /** - * Create a new {@link java.sql.Connection} in an implementation specific fashion. + * Creates a new {@link Connection} in an implementation specific fashion. *

    * An implementation can assume that the caller of this will wrap the connection in a proxy that protects access to * the setAutoCommit, commit and rollback when enrolled in a XA transaction. *

    * - * @return a new {@link java.sql.Connection} - * @throws java.sql.SQLException - * if a database error occurs creating the connection + * @return a new {@link Connection} + * @throws SQLException if a database error occurs creating the connection */ @Override Connection createConnection() throws SQLException; From cd773657fd063b071c004edfa86d3bec8b4e2de1 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 17:34:05 -0500 Subject: [PATCH 128/169] Javadoc: Add missing @deprecated description --- src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index a06e6dcc68..491e68b892 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -1479,7 +1479,7 @@ public synchronized String getUrl() { * Gets the JDBC connection {code userName} property. * * @return the {code userName} passed to the JDBC driver to establish connections - * @deprecated + * @deprecated Use {@link #getUserName()}. */ @Deprecated @Override From 2216da5299cfb15026536097ee990ee39e06d460 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 4 Nov 2024 18:00:08 -0500 Subject: [PATCH 129/169] Javadoc: Fix build warnings --- .../apache/commons/dbcp2/DriverConnectionFactory.java | 10 ++++++++-- .../dbcp2/managed/LocalXAConnectionFactory.java | 7 +++++++ .../commons/dbcp2/managed/ManagedConnection.java | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java index 99b0ddfc52..3f59e2d210 100644 --- a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java @@ -53,6 +53,8 @@ public Connection createConnection() throws SQLException { } /** + * Gets the connection String. + * * @return The connection String. * @since 2.6.0 */ @@ -61,7 +63,9 @@ public String getConnectionString() { } /** - * @return The Driver. + * Gets the JDBC Driver. + * + * @return The JDBC Driver. * @since 2.6.0 */ public Driver getDriver() { @@ -69,7 +73,9 @@ public Driver getDriver() { } /** - * @return The Properties. + * Gets the properties. + * + * @return The properties. * @since 2.6.0 */ public Properties getProperties() { diff --git a/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java index a4a08b9891..e69b98804f 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java @@ -368,6 +368,8 @@ public Connection createConnection() throws SQLException { } /** + * Gets the connection factory. + * * @return The connection factory. * @since 2.6.0 */ @@ -375,6 +377,11 @@ public ConnectionFactory getConnectionFactory() { return connectionFactory; } + /** + * Gets the transaction registry. + * + * @return The transaction registry. + */ @Override public TransactionRegistry getTransactionRegistry() { return transactionRegistry; diff --git a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java index 126a39d2bd..3108dc870f 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java @@ -148,6 +148,8 @@ public Connection getInnermostDelegate() { } /** + * Gets the transaction context. + * * @return The transaction context. * @since 2.6.0 */ @@ -156,6 +158,8 @@ public TransactionContext getTransactionContext() { } /** + * Gets the transaction registry. + * * @return The transaction registry. * @since 2.6.0 */ From d73cae3b70f5d9c6df5bd8e76b4cc07e82b2248d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 5 Nov 2024 07:03:01 -0500 Subject: [PATCH 130/169] Use preferred spelling for "cannot" --- .../dbcp2/managed/LocalXAConnectionFactory.java | 2 +- .../commons/dbcp2/managed/ManagedConnection.java | 10 +++++----- .../dbcp2/managed/TestConnectionWithNarayana.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java index e69b98804f..248c5cff44 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/LocalXAConnectionFactory.java @@ -211,7 +211,7 @@ public synchronized int prepare(final Xid xid) { } /** - * Always returns a zero length Xid array. The LocalXAConnectionFactory can not support recovery, so no xids + * Always returns a zero length Xid array. The LocalXAConnectionFactory cannot support recovery, so no xids * will ever be found. * * @param flag diff --git a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java index 3108dc870f..a5a72d1a28 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java @@ -122,7 +122,7 @@ public void close() throws SQLException { @Override public void commit() throws SQLException { if (transactionContext != null) { - throw new SQLException("Commit can not be set while enrolled in a transaction"); + throw new SQLException("Commit cannot be set while enrolled in a transaction"); } super.commit(); } @@ -179,7 +179,7 @@ public boolean isAccessToUnderlyingConnectionAllowed() { @Override public void rollback() throws SQLException { if (transactionContext != null) { - throw new SQLException("Commit can not be set while enrolled in a transaction"); + throw new SQLException("Commit cannot be set while enrolled in a transaction"); } super.rollback(); } @@ -187,7 +187,7 @@ public void rollback() throws SQLException { @Override public void setAutoCommit(final boolean autoCommit) throws SQLException { if (transactionContext != null) { - throw new SQLException("Auto-commit can not be set while enrolled in a transaction"); + throw new SQLException("Auto-commit cannot be set while enrolled in a transaction"); } super.setAutoCommit(autoCommit); } @@ -195,7 +195,7 @@ public void setAutoCommit(final boolean autoCommit) throws SQLException { @Override public void setReadOnly(final boolean readOnly) throws SQLException { if (transactionContext != null) { - throw new SQLException("Read-only can not be set while enrolled in a transaction"); + throw new SQLException("Read-only cannot be set while enrolled in a transaction"); } super.setReadOnly(readOnly); } @@ -244,7 +244,7 @@ private void updateTransactionStatus() throws SQLException { if (transactionContext != null && !transactionContext.isTransactionComplete()) { if (transactionContext.isActive()) { if (transactionContext != transactionRegistry.getActiveTransactionContext()) { - throw new SQLException("Connection can not be used while enlisted in another transaction"); + throw new SQLException("Connection cannot be used while enlisted in another transaction"); } return; } diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java b/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java index dcf9c50b08..f560cbd02c 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java @@ -119,7 +119,7 @@ public void testConnectionCommitAfterTimeout() throws Exception { fail("Should not work after timeout"); } catch (final SQLException e) { // Expected - Assertions.assertEquals("Commit can not be set while enrolled in a transaction", e.getMessage()); + Assertions.assertEquals("Commit cannot be set while enrolled in a transaction", e.getMessage()); } mds.getTransactionManager().rollback(); } From 20b61408c623828735446f3f08e53d20470202c9 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 8 Nov 2024 07:19:49 -0500 Subject: [PATCH 131/169] Fix dependency-review.yml for PR only --- .github/workflows/dependency-review.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 154ab43040..6da427d50d 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -29,6 +29,3 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: 'Dependency Review PR' uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0 - with: - base-ref: ${{ github.event.before }} - head-ref: ${{ github.sha }} From de8f2ed7ce0bc22484ce78618ff365f2c43f24d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 07:07:26 -0500 Subject: [PATCH 132/169] Bump github/codeql-action from 3.27.0 to 3.27.4 (#456) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.0 to 3.27.4. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/662472033e021d55d94146f66f6058822b0b39fd...ea9e4e37992a54ee68a9622e985e60c8e8f12d9f) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ebb0e32a39..3cbe0b46a7 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 + uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 + uses: github/codeql-action/autobuild@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 + uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index ac3fdad816..3aaf39bc3e 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # 3.27.0 + uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 with: sarif_file: results.sarif From 5f7ff5ac952d6811dc7bcaaf6042be076aff5951 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 15 Nov 2024 11:12:36 -0500 Subject: [PATCH 133/169] Javadoc: Use semantic tag instead of style tag --- src/main/java/org/apache/commons/dbcp2/package-info.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/package-info.java b/src/main/java/org/apache/commons/dbcp2/package-info.java index 7fbc736a5d..61d0e38c28 100644 --- a/src/main/java/org/apache/commons/dbcp2/package-info.java +++ b/src/main/java/org/apache/commons/dbcp2/package-info.java @@ -19,7 +19,7 @@ *

    * Database Connection Pool API. *

    - * Overview in Dialog Form + * Overview in Dialog Form *

    * Q: How do I use the DBCP package? *

    From cf7e602b798836841e1039138bbd0d8bec0f64f1 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 21 Nov 2024 14:36:41 -0500 Subject: [PATCH 134/169] Add support for ignoring non-fatal SQL state codes - BasicDataSource.setDisconnectionIgnoreSqlCodes(Collection) - Return a set with predictable iteration order --- src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index 491e68b892..bf95236418 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -30,6 +30,7 @@ import java.time.Duration; import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; import java.util.Properties; @@ -2004,7 +2005,7 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation public void setDisconnectionIgnoreSqlCodes(final Collection disconnectionIgnoreSqlCodes) { Utils.checkSqlCodes(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes); final Set collect = Utils.isEmpty(disconnectionIgnoreSqlCodes) ? null - : disconnectionIgnoreSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); + : disconnectionIgnoreSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toCollection(LinkedHashSet::new)); this.disconnectionIgnoreSqlCodes = Utils.isEmpty(collect) ? null : collect; } From 4e780c7e96a1679a8fdef5490b1d62cd673071e5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 21 Nov 2024 15:10:05 -0500 Subject: [PATCH 135/169] Return a set with predictable iteration order from BasicDataSource.setDisconnectionSqlCodes(Collection) --- .../java/org/apache/commons/dbcp2/BasicDataSource.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java index bf95236418..259835df2f 100644 --- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java @@ -37,6 +37,7 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.logging.Logger; +import java.util.stream.Collector; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -2005,7 +2006,7 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation public void setDisconnectionIgnoreSqlCodes(final Collection disconnectionIgnoreSqlCodes) { Utils.checkSqlCodes(disconnectionIgnoreSqlCodes, this.disconnectionSqlCodes); final Set collect = Utils.isEmpty(disconnectionIgnoreSqlCodes) ? null - : disconnectionIgnoreSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toCollection(LinkedHashSet::new)); + : disconnectionIgnoreSqlCodes.stream().filter(s -> !isEmpty(s)).collect(toLinkedHashSet()); this.disconnectionIgnoreSqlCodes = Utils.isEmpty(collect) ? null : collect; } @@ -2034,7 +2035,7 @@ public void setDisconnectionIgnoreSqlCodes(final Collection disconnectio public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { Utils.checkSqlCodes(disconnectionSqlCodes, this.disconnectionIgnoreSqlCodes); final Set collect = Utils.isEmpty(disconnectionSqlCodes) ? null - : disconnectionSqlCodes.stream().filter(s -> !isEmpty(s)).collect(Collectors.toSet()); + : disconnectionSqlCodes.stream().filter(s -> !isEmpty(s)).collect(toLinkedHashSet()); this.disconnectionSqlCodes = Utils.isEmpty(collect) ? null : collect; } @@ -2653,6 +2654,10 @@ protected void startPoolMaintenance() { } } + private Collector> toLinkedHashSet() { + return Collectors.toCollection(LinkedHashSet::new); + } + @Override public T unwrap(final Class iface) throws SQLException { if (isWrapperFor(iface)) { From 578d8f100b72f2318f3e27f281dc85c03beb6bbe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 06:59:30 -0500 Subject: [PATCH 136/169] Bump github/codeql-action from 3.27.4 to 3.27.5 (#457) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.4 to 3.27.5. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/ea9e4e37992a54ee68a9622e985e60c8e8f12d9f...f09c1c0a94de965c15400f5634aa42fac8fb8f88) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/scorecards-analysis.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3cbe0b46a7..b5db1297e1 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 + uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # 3.27.5 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 + uses: github/codeql-action/autobuild@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # 3.27.5 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 + uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # 3.27.5 diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 3aaf39bc3e..94d1bedb66 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -64,6 +64,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # 3.27.4 + uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # 3.27.5 with: sarif_file: results.sarif From 809fc00f2a51da63c4c3e748c4c405b803dacd2f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 06:59:48 -0500 Subject: [PATCH 137/169] Bump actions/dependency-review-action from 4.4.0 to 4.5.0 (#458) Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/4081bf99e2866ebe428fc0477b69eb4fcda7220a...3b139cfc5fae8b618d3eae3675e383bb1769c019) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dependency-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 6da427d50d..c6ece650e2 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -28,4 +28,4 @@ jobs: - name: 'Checkout Repository' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: 'Dependency Review PR' - uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0 + uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4.5.0 From 8042827978a20732df580eeda00e569817abad94 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:16:34 -0500 Subject: [PATCH 138/169] Add missing Javadoc comments and descriptions --- src/changes/changes.xml | 1 + .../org/apache/commons/dbcp2/Constants.java | 20 ++++++++- .../commons/dbcp2/DelegatingConnection.java | 23 ++++++++++ .../dbcp2/DelegatingDatabaseMetaData.java | 6 +++ .../dbcp2/PoolableConnectionFactory.java | 43 ++++++++++++++++--- .../datasources/SharedPoolDataSource.java | 3 -- 6 files changed, 86 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2c7045c440..30c9902279 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,6 +77,7 @@ The type attribute can be add,update,fix,remove. Add support for ignoring non-fatal SQL state codes #421. Add @FunctionalInterface to SwallowedExceptionListener. + Add missing Javadoc comments and descriptions. Bump org.apache.commons:commons-parent from 66 to 78 #360, #371, #395, #420, #426, #436, #441, #449. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. diff --git a/src/main/java/org/apache/commons/dbcp2/Constants.java b/src/main/java/org/apache/commons/dbcp2/Constants.java index 26bf3df1a1..7094d62498 100644 --- a/src/main/java/org/apache/commons/dbcp2/Constants.java +++ b/src/main/java/org/apache/commons/dbcp2/Constants.java @@ -23,13 +23,29 @@ */ public class Constants { + /** + * Constant used to build JMX strings. + */ public static final String JMX_CONNECTION_POOL_BASE_EXT = ",connectionpool="; + + /** + * Constant used to build JMX strings. + */ public static final String JMX_CONNECTION_POOL_PREFIX = "connections"; - public static final String JMX_CONNECTION_BASE_EXT = JMX_CONNECTION_POOL_BASE_EXT + JMX_CONNECTION_POOL_PREFIX - + ",connection="; + /** + * Constant used to build JMX strings. + */ + public static final String JMX_CONNECTION_BASE_EXT = JMX_CONNECTION_POOL_BASE_EXT + JMX_CONNECTION_POOL_PREFIX + ",connection="; + /** + * Constant used to build JMX strings. + */ public static final String JMX_STATEMENT_POOL_BASE_EXT = JMX_CONNECTION_BASE_EXT; + + /** + * Constant used to build JMX strings. + */ public static final String JMX_STATEMENT_POOL_PREFIX = ",statementpool=statements"; /** diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java index 3aec922b23..4484ac83a8 100644 --- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java @@ -95,6 +95,9 @@ public void abort(final Executor executor) throws SQLException { } } + /** + * Marks this instance as used and delegates to a wrapped {@link DelegatingConnection#activate()}. + */ protected void activate() { closed = false; setLastUsed(); @@ -103,6 +106,11 @@ protected void activate() { } } + /** + * Throws a SQLException if this connection is not open. + * + * @throws SQLException Thrown if this connection is not open. + */ protected void checkOpen() throws SQLException { if (closed) { if (null != connection) { @@ -578,6 +586,11 @@ public boolean isClosed() throws SQLException { return closed || connection == null || connection.isClosed(); } + /** + * Tests the raw internal closed state. + * + * @return the raw internal closed state. + */ protected boolean isClosedInternal() { return closed; } @@ -649,6 +662,11 @@ public String nativeSQL(final String sql) throws SQLException { } } + /** + * Clears the list of objects being traced by this object. + * + * @throws SQLException Thrown if not all traced objects were closed. + */ protected void passivate() throws SQLException { // The JDBC specification requires that a Connection close any open // Statements when it is closed. @@ -873,6 +891,11 @@ public void setClientInfo(final String name, final String value) throws SQLClien } } + /** + * Sets the raw internal closed state. + * + * @param closed the raw internal closed state. + */ protected void setClosedInternal(final boolean closed) { this.closed = closed; } diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java index ccbc52bbac..f19f3bbbc8 100644 --- a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java +++ b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java @@ -984,6 +984,12 @@ public ResultSet getVersionColumns(final String catalog, final String schema, fi } } + /** + * Delegates to the connection's {@link DelegatingConnection#handleException(SQLException)}. + * + * @param e the exception to throw or delegate. + * @throws SQLException the exception to throw. + */ protected void handleException(final SQLException e) throws SQLException { if (connection == null) { throw e; diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java index 3a4f65cd26..532e857879 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java @@ -156,7 +156,7 @@ public void destroyObject(final PooledObject p, final Destro } /** - * Gets the cache state. + * Gets the cache state to propagate in {@link #makeObject()}. * * @return The cache state. * @since 2.6.0. @@ -338,14 +338,20 @@ protected int getMaxOpenPreparedStatements() { public synchronized ObjectPool getPool() { return pool; } + /** + * Tests whether to pool statements. + * * @return Whether to pool statements. * @since 2.6.0. */ public boolean getPoolStatements() { return poolStatements; } + /** + * Gets the validation query. + * * @return Validation query. * @since 2.6.0 */ @@ -390,7 +396,9 @@ protected void initializeConnection(final Connection conn) throws SQLException { } /** - * @return Whether to auto-commit on return. + * Tests whether to set auto-commit on {@link #passivateObject(PooledObject)}. + * + * @return Whether to set auto-commit on {@link #passivateObject(PooledObject)}. * @since 2.6.0 */ public boolean isAutoCommitOnReturn() { @@ -398,7 +406,9 @@ public boolean isAutoCommitOnReturn() { } /** - * @return Whether to auto-commit on return. + * Tests whether to set auto-commit on {@link #passivateObject(PooledObject)}. + * + * @return Whether to set auto-commit on {@link #passivateObject(PooledObject)}. * @deprecated Use {@link #isAutoCommitOnReturn()}. */ @Deprecated @@ -420,6 +430,8 @@ public boolean isFastFailValidation() { } /** + * Tests whether to rollback on return. + * * @return Whether to rollback on return. */ public boolean isRollbackOnReturn() { @@ -518,10 +530,20 @@ public void passivateObject(final PooledObject p) throws SQL conn.passivate(); } + /** + * Sets whether to set auto-commit on {@link #passivateObject(PooledObject)}. + * + * @param autoCommitOnReturn whether to set auto-commit. + */ public void setAutoCommitOnReturn(final boolean autoCommitOnReturn) { this.autoCommitOnReturn = autoCommitOnReturn; } + /** + * Sets the cache state to propagate in {@link #makeObject()}. + * + * @param cacheState the cache state to propagate. + */ public void setCacheState(final boolean cacheState) { this.cacheState = cacheState; } @@ -648,8 +670,9 @@ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCo } /** - * @param autoCommitOnReturn Whether to auto-commit on return. - * @deprecated Use {@link #setAutoCommitOnReturn(boolean)}. + * Sets whether to set auto-commit on {@link #passivateObject(PooledObject)}. + * + * @param autoCommitOnReturn whether to set auto-commit. */ @Deprecated public void setEnableAutoCommitOnReturn(final boolean autoCommitOnReturn) { @@ -726,10 +749,20 @@ public synchronized void setPool(final ObjectPool pool) { this.pool = pool; } + /** + * Sets whether to pool statements. + * + * @param poolStatements whether to pool statements. + */ public void setPoolStatements(final boolean poolStatements) { this.poolStatements = poolStatements; } + /** + * Sets whether to rollback on return. + * + * @param rollbackOnReturn whether to rollback on return. + */ public void setRollbackOnReturn(final boolean rollbackOnReturn) { this.rollbackOnReturn = rollbackOnReturn; } diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index 54e8b8a036..f3e233a108 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -89,9 +89,6 @@ public int getMaxTotal() { return this.maxTotal; } - // ---------------------------------------------------------------------- - // Instrumentation Methods - /** * Gets the number of active connections in the pool. * From 80722a56c914acd20b88eac97398e05c3da832fb Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:23:41 -0500 Subject: [PATCH 139/169] Move important fixed to the top --- src/changes/changes.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 30c9902279..7862775b43 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -64,6 +64,9 @@ The type attribute can be add,update,fix,remove. + Avoid object creation when invoking isDisconnectionSqlException #422. + PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge + DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. Fix PMD UnnecessaryFullyQualifiedName in PoolablePreparedStatement. @@ -71,9 +74,6 @@ The type attribute can be add,update,fix,remove. Fix PMD UnnecessaryFullyQualifiedName in LocalXAConnectionFactory. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. - Avoid object creation when invoking isDisconnectionSqlException #422. - PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge - DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Add support for ignoring non-fatal SQL state codes #421. Add @FunctionalInterface to SwallowedExceptionListener. From 04fcba6aa2b41933f96f9dd7ce05f440ef863578 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:28:00 -0500 Subject: [PATCH 140/169] Remove unused package-private constructor --- .../dbcp2/datasources/PooledConnectionAndInfo.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java b/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java index 04e066dd54..01deb37744 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PooledConnectionAndInfo.java @@ -30,15 +30,6 @@ final class PooledConnectionAndInfo { private final UserPassKey userPassKey; - /** - * Constructs a new instance. - * - * @since 2.4.0 - */ - PooledConnectionAndInfo(final PooledConnection pooledConnection, final char[] userName, final char[] userPassword) { - this(pooledConnection, new UserPassKey(userName, userPassword)); - } - PooledConnectionAndInfo(final PooledConnection pooledConnection, final UserPassKey userPassKey) { this.pooledConnection = pooledConnection; this.userPassKey = userPassKey; From 504d5feb41c1a4d29d160d77c021d085680874e9 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:28:15 -0500 Subject: [PATCH 141/169] Remove unused package-private constructor --- .../org/apache/commons/dbcp2/datasources/UserPassKey.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java b/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java index 94643c8070..cde1bf15dd 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java @@ -42,10 +42,6 @@ final class UserPassKey implements Serializable { private final CharArray name; private final CharArray password; - UserPassKey(final char[] userName, final char[] password) { - this(new CharArray(userName), new CharArray(password)); - } - UserPassKey(final CharArray userName, final CharArray userPassword) { this.name = userName; this.password = userPassword; From 17fa27397478b7091b93d44569627b9f7bf01845 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:38:10 -0500 Subject: [PATCH 142/169] Javadoc --- .../datasources/KeyedCPDSConnectionFactory.java | 3 +-- .../dbcp2/datasources/SharedPoolDataSource.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java index 3b21c653c7..db7fee5c22 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java @@ -38,8 +38,7 @@ import org.apache.commons.pool2.impl.DefaultPooledObject; /** - * A {@link KeyedPooledObjectFactory} that creates {@link org.apache.commons.dbcp2.PoolableConnection - * PoolableConnection}s. + * A {@link KeyedPooledObjectFactory} that creates {@link PoolableConnection}s. * * @since 2.0 */ diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index f3e233a108..a30438881e 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -27,6 +27,7 @@ import javax.sql.ConnectionPoolDataSource; import org.apache.commons.pool2.KeyedObjectPool; +import org.apache.commons.pool2.KeyedPooledObjectFactory; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; @@ -51,10 +52,19 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { private static final long serialVersionUID = -1458539734480586454L; - // Pool properties + /** + * Max total defaults to {@value}. + */ private int maxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL; + /** + * Maps user credentials to pooled connection with credentials. + */ private transient KeyedObjectPool pool; + + /** + * A {@link KeyedPooledObjectFactory} that creates {@link PoolableConnection}s. + */ private transient KeyedCPDSConnectionFactory factory; /** From 8dc0e02f5cfa25e1993bf2a8bdb695bda8b0222f Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:51:15 -0500 Subject: [PATCH 143/169] Internal refactoring using generics --- .../datasources/PerUserPoolDataSource.java | 104 +++++------------- 1 file changed, 28 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 46dcf3ae94..8beb6d1507 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -140,6 +140,16 @@ private Map convertMap(final Map currentMap, } + /** + * Gets the user specific default value in a map for the specified user's pool. + * + * @param userName The user name key. + * @return The user specific value. + */ + private V get(final Map map, final String userName) { + return map != null ? map.get(userName) : null; + } + @Override protected PooledConnectionManager getConnectionManager(final UserPassKey upKey) { return managers.get(getPoolKey(upKey.getUserName())); @@ -208,10 +218,7 @@ public int getNumIdle(final String userName) { * @return The user specific value. */ public boolean getPerUserBlockWhenExhausted(final String userName) { - Boolean value = null; - if (perUserBlockWhenExhausted != null) { - value = perUserBlockWhenExhausted.get(userName); - } + final Boolean value = get(perUserBlockWhenExhausted, userName); if (value == null) { return getDefaultBlockWhenExhausted(); } @@ -226,11 +233,7 @@ public boolean getPerUserBlockWhenExhausted(final String userName) { * @return The user specific value. */ public Boolean getPerUserDefaultAutoCommit(final String userName) { - Boolean value = null; - if (perUserDefaultAutoCommit != null) { - value = perUserDefaultAutoCommit.get(userName); - } - return value; + return get(perUserDefaultAutoCommit, userName); } /** @@ -241,11 +244,7 @@ public Boolean getPerUserDefaultAutoCommit(final String userName) { * @return The user specific value. */ public Boolean getPerUserDefaultReadOnly(final String userName) { - Boolean value = null; - if (perUserDefaultReadOnly != null) { - value = perUserDefaultReadOnly.get(userName); - } - return value; + return get(perUserDefaultReadOnly, userName); } /** @@ -257,11 +256,7 @@ public Boolean getPerUserDefaultReadOnly(final String userName) { * @return The user specific value. */ public Integer getPerUserDefaultTransactionIsolation(final String userName) { - Integer value = null; - if (perUserDefaultTransactionIsolation != null) { - value = perUserDefaultTransactionIsolation.get(userName); - } - return value; + return get(perUserDefaultTransactionIsolation, userName); } /** @@ -274,10 +269,7 @@ public Integer getPerUserDefaultTransactionIsolation(final String userName) { * @since 2.10.0 */ public Duration getPerUserDurationBetweenEvictionRuns(final String userName) { - Duration value = null; - if (perUserDurationBetweenEvictionRuns != null) { - value = perUserDurationBetweenEvictionRuns.get(userName); - } + final Duration value = get(perUserDurationBetweenEvictionRuns, userName); if (value == null) { return getDefaultDurationBetweenEvictionRuns(); } @@ -293,10 +285,7 @@ public Duration getPerUserDurationBetweenEvictionRuns(final String userName) { * @return The user specific value. */ public String getPerUserEvictionPolicyClassName(final String userName) { - String value = null; - if (perUserEvictionPolicyClassName != null) { - value = perUserEvictionPolicyClassName.get(userName); - } + final String value = get(perUserEvictionPolicyClassName, userName); if (value == null) { return getDefaultEvictionPolicyClassName(); } @@ -312,10 +301,7 @@ public String getPerUserEvictionPolicyClassName(final String userName) { * @return The user specific value. */ public boolean getPerUserLifo(final String userName) { - Boolean value = null; - if (perUserLifo != null) { - value = perUserLifo.get(userName); - } + final Boolean value = get(perUserLifo, userName); if (value == null) { return getDefaultLifo(); } @@ -331,10 +317,7 @@ public boolean getPerUserLifo(final String userName) { * @return The user specific value. */ public int getPerUserMaxIdle(final String userName) { - Integer value = null; - if (perUserMaxIdle != null) { - value = perUserMaxIdle.get(userName); - } + final Integer value = get(perUserMaxIdle, userName); if (value == null) { return getDefaultMaxIdle(); } @@ -350,10 +333,7 @@ public int getPerUserMaxIdle(final String userName) { * @return The user specific value. */ public int getPerUserMaxTotal(final String userName) { - Integer value = null; - if (perUserMaxTotal != null) { - value = perUserMaxTotal.get(userName); - } + final Integer value = get(perUserMaxTotal, userName); if (value == null) { return getDefaultMaxTotal(); } @@ -370,10 +350,7 @@ public int getPerUserMaxTotal(final String userName) { * @since 2.10.0 */ public Duration getPerUserMaxWaitDuration(final String userName) { - Duration value = null; - if (perUserMaxWaitDuration != null) { - value = perUserMaxWaitDuration.get(userName); - } + final Duration value = get(perUserMaxWaitDuration, userName); if (value == null) { return getDefaultMaxWait(); } @@ -404,10 +381,7 @@ public long getPerUserMaxWaitMillis(final String userName) { * @since 2.10.0 */ public Duration getPerUserMinEvictableIdleDuration(final String userName) { - Duration value = null; - if (perUserMinEvictableIdleDuration != null) { - value = perUserMinEvictableIdleDuration.get(userName); - } + final Duration value = get(perUserMinEvictableIdleDuration, userName); if (value == null) { return getDefaultMinEvictableIdleDuration(); } @@ -437,10 +411,7 @@ public long getPerUserMinEvictableIdleTimeMillis(final String userName) { * @return The user specific value. */ public int getPerUserMinIdle(final String userName) { - Integer value = null; - if (perUserMinIdle != null) { - value = perUserMinIdle.get(userName); - } + final Integer value = get(perUserMinIdle, userName); if (value == null) { return getDefaultMinIdle(); } @@ -456,10 +427,7 @@ public int getPerUserMinIdle(final String userName) { * @return The user specific value. */ public int getPerUserNumTestsPerEvictionRun(final String userName) { - Integer value = null; - if (perUserNumTestsPerEvictionRun != null) { - value = perUserNumTestsPerEvictionRun.get(userName); - } + final Integer value = get(perUserNumTestsPerEvictionRun, userName); if (value == null) { return getDefaultNumTestsPerEvictionRun(); } @@ -476,10 +444,7 @@ public int getPerUserNumTestsPerEvictionRun(final String userName) { * @since 2.10.0 */ public Duration getPerUserSoftMinEvictableIdleDuration(final String userName) { - Duration value = null; - if (perUserSoftMinEvictableIdleDuration != null) { - value = perUserSoftMinEvictableIdleDuration.get(userName); - } + final Duration value = get(perUserSoftMinEvictableIdleDuration, userName); if (value == null) { return getDefaultSoftMinEvictableIdleDuration(); } @@ -509,10 +474,7 @@ public long getPerUserSoftMinEvictableIdleTimeMillis(final String userName) { * @return The user specific value. */ public boolean getPerUserTestOnBorrow(final String userName) { - Boolean value = null; - if (perUserTestOnBorrow != null) { - value = perUserTestOnBorrow.get(userName); - } + final Boolean value = get(perUserTestOnBorrow, userName); if (value == null) { return getDefaultTestOnBorrow(); } @@ -528,10 +490,7 @@ public boolean getPerUserTestOnBorrow(final String userName) { * @return The user specific value. */ public boolean getPerUserTestOnCreate(final String userName) { - Boolean value = null; - if (perUserTestOnCreate != null) { - value = perUserTestOnCreate.get(userName); - } + final Boolean value = get(perUserTestOnCreate, userName); if (value == null) { return getDefaultTestOnCreate(); } @@ -547,10 +506,7 @@ public boolean getPerUserTestOnCreate(final String userName) { * @return The user specific value. */ public boolean getPerUserTestOnReturn(final String userName) { - Boolean value = null; - if (perUserTestOnReturn != null) { - value = perUserTestOnReturn.get(userName); - } + final Boolean value = get(perUserTestOnReturn, userName); if (value == null) { return getDefaultTestOnReturn(); } @@ -566,10 +522,7 @@ public boolean getPerUserTestOnReturn(final String userName) { * @return The user specific value. */ public boolean getPerUserTestWhileIdle(final String userName) { - Boolean value = null; - if (perUserTestWhileIdle != null) { - value = perUserTestWhileIdle.get(userName); - } + final Boolean value = get(perUserTestWhileIdle, userName); if (value == null) { return getDefaultTestWhileIdle(); } @@ -605,7 +558,6 @@ private ObjectPool getPool(final PoolKey poolKey) { @Override protected PooledConnectionAndInfo getPooledConnectionAndInfo(final String userName, final String password) throws SQLException { - final PoolKey key = getPoolKey(userName); ObjectPool pool; PooledConnectionManager manager; From f246d38179c4efb644f3598f70c548995c56d53a Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 16:51:23 -0500 Subject: [PATCH 144/169] Javadoc --- .../apache/commons/dbcp2/datasources/SharedPoolDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java index a30438881e..1de7ccff7c 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java @@ -53,7 +53,7 @@ public class SharedPoolDataSource extends InstanceKeyDataSource { private static final long serialVersionUID = -1458539734480586454L; /** - * Max total defaults to {@value}. + * Max total defaults to {@link GenericKeyedObjectPoolConfig#DEFAULT_MAX_TOTAL}. */ private int maxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL; From 28ef1403c774facd715d4e5c8cee238f0276aebb Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 17:54:49 -0500 Subject: [PATCH 145/169] Javadoc --- src/main/java/org/apache/commons/dbcp2/Utils.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/apache/commons/dbcp2/Utils.java b/src/main/java/org/apache/commons/dbcp2/Utils.java index 16f23a2fff..3020f89339 100644 --- a/src/main/java/org/apache/commons/dbcp2/Utils.java +++ b/src/main/java/org/apache/commons/dbcp2/Utils.java @@ -274,6 +274,13 @@ public static String toString(final char[] value) { return value == null ? null : String.valueOf(value); } + /** + * Throws a LifetimeExceededException if the given pooled object's lifetime has exceeded a maximum duration. + * + * @param p The pooled object to test. + * @param maxDuration The maximum lifetime. + * @throws LifetimeExceededException Thrown if the given pooled object's lifetime has exceeded a maximum duration. + */ public static void validateLifetime(final PooledObject p, final Duration maxDuration) throws LifetimeExceededException { if (maxDuration.compareTo(Duration.ZERO) > 0) { final Duration lifetimeDuration = Duration.between(p.getCreateInstant(), Instant.now()); From 8cfe1bd8a6fd834319d3fc9a971e16f6996f0f03 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 18:01:30 -0500 Subject: [PATCH 146/169] Use try-with-resources --- .../commons/dbcp2/TestPoolingConnection.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java index 27fbccc6d1..eeb6634a34 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.sql.SQLException; import java.time.Duration; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; @@ -173,11 +174,13 @@ public void testPrepareStatementWithResultSetHoldability() throws Exception { * Tests DBCP-596 PoolingConnection.toString() causes StackOverflowError. */ @Test - public void testToStringStackOverflow() { - final PoolingConnection conn = new PoolingConnection(null); - final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig<>(); - final GenericKeyedObjectPool stmtPool = new GenericKeyedObjectPool<>(conn, config); - conn.setStatementPool(stmtPool); - conn.toString(); + public void testToStringStackOverflow() throws SQLException { + try (PoolingConnection conn = new PoolingConnection(null)) { + final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig<>(); + try (GenericKeyedObjectPool stmtPool = new GenericKeyedObjectPool<>(conn, config)) { + conn.setStatementPool(stmtPool); + } + conn.toString(); + } } } From 95ef723114b03f2826ab1ddc4e29ce1d8c63b983 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 18:03:10 -0500 Subject: [PATCH 147/169] Fix generics warning --- .../java/org/apache/commons/dbcp2/TestPoolingConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java index eeb6634a34..6bed282433 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java @@ -177,7 +177,7 @@ public void testPrepareStatementWithResultSetHoldability() throws Exception { public void testToStringStackOverflow() throws SQLException { try (PoolingConnection conn = new PoolingConnection(null)) { final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig<>(); - try (GenericKeyedObjectPool stmtPool = new GenericKeyedObjectPool<>(conn, config)) { + try (GenericKeyedObjectPool stmtPool = new GenericKeyedObjectPool<>(conn, config)) { conn.setStatementPool(stmtPool); } conn.toString(); From 0b9a0054df253c9983d686f624956f6797e1bb0c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 18:49:02 -0500 Subject: [PATCH 148/169] Fix possible NullPointerException in PoolingConnection.close() --- src/changes/changes.xml | 3 ++- .../java/org/apache/commons/dbcp2/PoolingConnection.java | 6 +++++- .../org/apache/commons/dbcp2/TestPoolingConnection.java | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7862775b43..7e87d3d690 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -66,7 +66,8 @@ The type attribute can be add,update,fix,remove. Avoid object creation when invoking isDisconnectionSqlException #422. PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge - DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. + DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. + Fix possible NullPointerException in PoolingConnection.close(). Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. Fix PMD UnnecessaryFullyQualifiedName in PoolablePreparedStatement. diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java index b4ce3eb619..a5fe2b34d5 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java @@ -122,7 +122,11 @@ public synchronized void close() throws SQLException { } } finally { try { - getDelegateInternal().close(); + @SuppressWarnings("resource") + final Connection delegateInternal = getDelegateInternal(); + if (delegateInternal != null) { + delegateInternal.close(); + } } finally { setClosedInternal(true); } diff --git a/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java b/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java index 6bed282433..e944f9ecab 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java @@ -175,6 +175,7 @@ public void testPrepareStatementWithResultSetHoldability() throws Exception { */ @Test public void testToStringStackOverflow() throws SQLException { + // Also tests a possible NullPointerException in PoolingConnection.close() try (PoolingConnection conn = new PoolingConnection(null)) { final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig<>(); try (GenericKeyedObjectPool stmtPool = new GenericKeyedObjectPool<>(conn, config)) { From cb116861bb5e1b1c82b5a8eb90266962bd12edd4 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 23:00:05 -0500 Subject: [PATCH 149/169] Add Jdbc41BridgeTest --- .../commons/dbcp2/Jdbc41BridgeTest.java | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java diff --git a/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java b/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java new file mode 100644 index 0000000000..28216d8e84 --- /dev/null +++ b/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.dbcp2; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +/** + * Tests {@link Jdbc41Bridge}. + */ +public class Jdbc41BridgeTest { + + @SuppressWarnings("resource") + @Test + public void testAbort() throws SQLException { + // Normal + try (Connection conn = getConnection()) { + Jdbc41Bridge.abort(conn, r -> { + // empty for now + }); + } + // Force AbstractMethodError + try (Connection conn = getConnection()) { + final Connection spy = Mockito.spy(conn); + Mockito.doThrow(new AbstractMethodError()).when(spy).abort(r -> { + // empty for now + }); + Jdbc41Bridge.abort(spy, r -> { + // empty for now + }); + } + } + + @SuppressWarnings("resource") + @Test + public void testCloseOnCompletion() throws SQLException { + // Normal + try (Connection conn = getConnection(); + Statement stmt = conn.createStatement()) { + Jdbc41Bridge.closeOnCompletion(stmt); + } + // Force AbstractMethodError + try (Connection conn = getConnection(); + Statement stmt = conn.createStatement()) { + final Statement spy = Mockito.spy(stmt); + Mockito.doThrow(new AbstractMethodError()).when(spy).closeOnCompletion(); + Jdbc41Bridge.closeOnCompletion(spy); + } + } + + @SuppressWarnings("resource") + @Test + public void testGeneratedKeyAlwaysReturned() throws SQLException { + // Normal + try (Connection conn = getConnection()) { + assertTrue(Jdbc41Bridge.generatedKeyAlwaysReturned(conn.getMetaData())); + } + // Cannot mock a final class + // Force AbstractMethodError +// try (Connection conn = getConnection()) { +// final DatabaseMetaData spy = Mockito.spy(conn.getMetaData()); +// Mockito.when(spy.generatedKeyAlwaysReturned()).thenThrow(AbstractMethodError.class); +// assertTrue(Jdbc41Bridge.generatedKeyAlwaysReturned(spy)); +// } + } + + @Test + public void testGetNetworkTimeout() throws SQLException { + // Normal + try (Connection conn = getConnection()) { + Jdbc41Bridge.setNetworkTimeout(conn, r -> { + }, 30_000); + // noop in H2 + assertEquals(0, Jdbc41Bridge.getNetworkTimeout(conn)); + } + } + + @Test + public void testGetObjectIndex() throws SQLException { + // Normal + try (Connection conn = getConnection(); + ResultSet rs = conn.getMetaData().getTypeInfo()) { + rs.next(); + assertNotNull(Jdbc41Bridge.getObject(rs, 1, String.class)); + } + } + + @Test + public void testGetObjectName() throws SQLException { + // Normal + try (Connection conn = getConnection(); + ResultSet rs = conn.getMetaData().getTypeInfo()) { + rs.next(); + assertNotNull(Jdbc41Bridge.getObject(rs, "TYPE_NAME", String.class)); + } + } + + @SuppressWarnings("resource") + @Test + public void testGetSchema() throws SQLException { + // Normal + try (Connection conn = getConnection()) { + assertNotNull(Jdbc41Bridge.getSchema(conn)); + final Connection spy = Mockito.spy(conn); + Mockito.when(spy.getSchema()).thenThrow(AbstractMethodError.class); + assertNull(Jdbc41Bridge.getSchema(spy)); + } + } + + @Test + public void testIsCloseOnCompletion() throws SQLException { + // Normal + try (Connection conn = getConnection(); + Statement stmt = conn.createStatement()) { + assertFalse(Jdbc41Bridge.isCloseOnCompletion(stmt)); + } + } + + @Test + public void testSetNetworkTimeout() throws SQLException { + // Normal + try (Connection conn = getConnection(); + Statement stmt = conn.createStatement()) { + // noop in H2 + Jdbc41Bridge.setNetworkTimeout(conn, r -> { + // empty for now + }, 30_0000); + assertEquals(0, Jdbc41Bridge.getNetworkTimeout(conn)); + } + } + + @Test + public void testSetSchema() throws SQLException { + // Normal + try (Connection conn = getConnection(); + Statement stmt = conn.createStatement()) { + Jdbc41Bridge.setSchema(conn, Jdbc41Bridge.getSchema(conn)); + final String expected = "PUBLIC"; + Jdbc41Bridge.setSchema(conn, expected); + assertEquals(expected, Jdbc41Bridge.getSchema(conn)); + } + } + + private Connection getConnection() throws SQLException { + return DriverManager.getConnection("jdbc:h2:mem:test"); + } +} From a697f46ee4f30a8100dde6eff80c993962b373db Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 23:00:20 -0500 Subject: [PATCH 150/169] Internal refactoring using lambdas --- .../datasources/PerUserPoolDataSource.java | 175 ++++++++++-------- 1 file changed, 99 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 8beb6d1507..67e5c2369c 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; +import java.util.function.Supplier; import javax.naming.NamingException; import javax.naming.Reference; @@ -67,23 +68,94 @@ private static HashMap createMap() { return new HashMap<>(); } + /** + * Maps user names to a data source property: BlockWhenExhausted. + */ private Map perUserBlockWhenExhausted; + + /** + * Maps user names to a data source property: EvictionPolicyClassName. + */ private Map perUserEvictionPolicyClassName; + + /** + * Maps user names to a data source property: Lifo. + */ private Map perUserLifo; + + /** + * Maps user names to a data source property: MaxIdle. + */ private Map perUserMaxIdle; + + /** + * Maps user names to a data source property: MaxTotal. + */ private Map perUserMaxTotal; + + /** + * Maps user names to a data source property: MaxWaitDuration. + */ private Map perUserMaxWaitDuration; + + /** + * Maps user names to a data source property: MinEvictableIdleDuration. + */ private Map perUserMinEvictableIdleDuration; + + /** + * Maps user names to a data source property: MinIdle. + */ private Map perUserMinIdle; + + /** + * Maps user names to a data source property: NumTestsPerEvictionRun. + */ private Map perUserNumTestsPerEvictionRun; + + /** + * Maps user names to a data source property: SoftMinEvictableIdleDuration. + */ private Map perUserSoftMinEvictableIdleDuration; + + /** + * Maps user names to a data source property: TestOnCreate. + */ private Map perUserTestOnCreate; + + /** + * Maps user names to a data source property: TestOnBorrow. + */ private Map perUserTestOnBorrow; + + /** + * Maps user names to a data source property: TestOnReturn. + */ private Map perUserTestOnReturn; + + /** + * Maps user names to a data source property: TestWhileIdle. + */ private Map perUserTestWhileIdle; + + /** + * Maps user names to a data source property: DurationBetweenEvictionRuns. + */ private Map perUserDurationBetweenEvictionRuns; + + /** + * Maps user names to a data source property: DefaultAutoCommit. + */ private Map perUserDefaultAutoCommit; + + /** + * Maps user names to a data source property: DefaultTransactionIsolation. + */ private Map perUserDefaultTransactionIsolation; + + /** + * Maps user names to a data source property: DefaultReadOnly. + */ private Map perUserDefaultReadOnly; /** @@ -92,7 +164,7 @@ private static HashMap createMap() { private transient Map managers = createMap(); /** - * Default no-arg constructor for Serialization. + * Constructs a new instance. */ public PerUserPoolDataSource() { } @@ -150,6 +222,17 @@ private V get(final Map map, final String userName) { return map != null ? map.get(userName) : null; } + /** + * Gets the user specific default value in a map for the specified user's pool. + * + * @param userName The user name key. + * @return The user specific value. + */ + private V get(final Map map, final String userName, final Supplier defaultSupplier) { + final V v = get(map, userName); + return v != null ? v : defaultSupplier.get(); + } + @Override protected PooledConnectionManager getConnectionManager(final UserPassKey upKey) { return managers.get(getPoolKey(upKey.getUserName())); @@ -218,11 +301,7 @@ public int getNumIdle(final String userName) { * @return The user specific value. */ public boolean getPerUserBlockWhenExhausted(final String userName) { - final Boolean value = get(perUserBlockWhenExhausted, userName); - if (value == null) { - return getDefaultBlockWhenExhausted(); - } - return value; + return get(perUserBlockWhenExhausted, userName, this::getDefaultBlockWhenExhausted); } /** @@ -269,11 +348,7 @@ public Integer getPerUserDefaultTransactionIsolation(final String userName) { * @since 2.10.0 */ public Duration getPerUserDurationBetweenEvictionRuns(final String userName) { - final Duration value = get(perUserDurationBetweenEvictionRuns, userName); - if (value == null) { - return getDefaultDurationBetweenEvictionRuns(); - } - return value; + return get(perUserDurationBetweenEvictionRuns, userName, this::getDefaultDurationBetweenEvictionRuns); } /** @@ -285,11 +360,7 @@ public Duration getPerUserDurationBetweenEvictionRuns(final String userName) { * @return The user specific value. */ public String getPerUserEvictionPolicyClassName(final String userName) { - final String value = get(perUserEvictionPolicyClassName, userName); - if (value == null) { - return getDefaultEvictionPolicyClassName(); - } - return value; + return get(perUserEvictionPolicyClassName, userName, this::getDefaultEvictionPolicyClassName); } /** @@ -301,11 +372,7 @@ public String getPerUserEvictionPolicyClassName(final String userName) { * @return The user specific value. */ public boolean getPerUserLifo(final String userName) { - final Boolean value = get(perUserLifo, userName); - if (value == null) { - return getDefaultLifo(); - } - return value; + return get(perUserLifo, userName, this::getDefaultLifo); } /** @@ -317,11 +384,7 @@ public boolean getPerUserLifo(final String userName) { * @return The user specific value. */ public int getPerUserMaxIdle(final String userName) { - final Integer value = get(perUserMaxIdle, userName); - if (value == null) { - return getDefaultMaxIdle(); - } - return value; + return get(perUserMaxIdle, userName, this::getDefaultMaxIdle); } /** @@ -333,11 +396,7 @@ public int getPerUserMaxIdle(final String userName) { * @return The user specific value. */ public int getPerUserMaxTotal(final String userName) { - final Integer value = get(perUserMaxTotal, userName); - if (value == null) { - return getDefaultMaxTotal(); - } - return value; + return get(perUserMaxTotal, userName, this::getDefaultMaxTotal); } /** @@ -350,11 +409,7 @@ public int getPerUserMaxTotal(final String userName) { * @since 2.10.0 */ public Duration getPerUserMaxWaitDuration(final String userName) { - final Duration value = get(perUserMaxWaitDuration, userName); - if (value == null) { - return getDefaultMaxWait(); - } - return value; + return get(perUserMaxWaitDuration, userName, this::getDefaultMaxWait); } /** @@ -381,11 +436,7 @@ public long getPerUserMaxWaitMillis(final String userName) { * @since 2.10.0 */ public Duration getPerUserMinEvictableIdleDuration(final String userName) { - final Duration value = get(perUserMinEvictableIdleDuration, userName); - if (value == null) { - return getDefaultMinEvictableIdleDuration(); - } - return value; + return get(perUserMinEvictableIdleDuration, userName, this::getDefaultMinEvictableIdleDuration); } /** @@ -411,11 +462,7 @@ public long getPerUserMinEvictableIdleTimeMillis(final String userName) { * @return The user specific value. */ public int getPerUserMinIdle(final String userName) { - final Integer value = get(perUserMinIdle, userName); - if (value == null) { - return getDefaultMinIdle(); - } - return value; + return get(perUserMinIdle, userName, this::getDefaultMinIdle); } /** @@ -427,11 +474,7 @@ public int getPerUserMinIdle(final String userName) { * @return The user specific value. */ public int getPerUserNumTestsPerEvictionRun(final String userName) { - final Integer value = get(perUserNumTestsPerEvictionRun, userName); - if (value == null) { - return getDefaultNumTestsPerEvictionRun(); - } - return value; + return get(perUserNumTestsPerEvictionRun, userName, this::getDefaultNumTestsPerEvictionRun); } /** @@ -444,11 +487,7 @@ public int getPerUserNumTestsPerEvictionRun(final String userName) { * @since 2.10.0 */ public Duration getPerUserSoftMinEvictableIdleDuration(final String userName) { - final Duration value = get(perUserSoftMinEvictableIdleDuration, userName); - if (value == null) { - return getDefaultSoftMinEvictableIdleDuration(); - } - return value; + return get(perUserSoftMinEvictableIdleDuration, userName, this::getDefaultSoftMinEvictableIdleDuration); } /** @@ -474,11 +513,7 @@ public long getPerUserSoftMinEvictableIdleTimeMillis(final String userName) { * @return The user specific value. */ public boolean getPerUserTestOnBorrow(final String userName) { - final Boolean value = get(perUserTestOnBorrow, userName); - if (value == null) { - return getDefaultTestOnBorrow(); - } - return value; + return get(perUserTestOnBorrow, userName, this::getDefaultTestOnBorrow); } /** @@ -490,11 +525,7 @@ public boolean getPerUserTestOnBorrow(final String userName) { * @return The user specific value. */ public boolean getPerUserTestOnCreate(final String userName) { - final Boolean value = get(perUserTestOnCreate, userName); - if (value == null) { - return getDefaultTestOnCreate(); - } - return value; + return get(perUserTestOnCreate, userName, this::getDefaultTestOnCreate); } /** @@ -506,11 +537,7 @@ public boolean getPerUserTestOnCreate(final String userName) { * @return The user specific value. */ public boolean getPerUserTestOnReturn(final String userName) { - final Boolean value = get(perUserTestOnReturn, userName); - if (value == null) { - return getDefaultTestOnReturn(); - } - return value; + return get(perUserTestOnReturn, userName, this::getDefaultTestOnReturn); } /** @@ -522,11 +549,7 @@ public boolean getPerUserTestOnReturn(final String userName) { * @return The user specific value. */ public boolean getPerUserTestWhileIdle(final String userName) { - final Boolean value = get(perUserTestWhileIdle, userName); - if (value == null) { - return getDefaultTestWhileIdle(); - } - return value; + return get(perUserTestWhileIdle, userName, this::getDefaultTestWhileIdle); } /** From b4d4809357ea1abc7a43dad062331786ce82d197 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 22 Nov 2024 23:14:32 -0500 Subject: [PATCH 151/169] Add to Jdbc41BridgeTest --- .../commons/dbcp2/Jdbc41BridgeTest.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java b/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java index 28216d8e84..d982909e1f 100644 --- a/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java +++ b/src/test/java/org/apache/commons/dbcp2/Jdbc41BridgeTest.java @@ -23,12 +23,14 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import org.h2.jdbcx.JdbcDataSource; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -37,6 +39,10 @@ */ public class Jdbc41BridgeTest { + private Connection getConnection() throws SQLException { + return DriverManager.getConnection("jdbc:h2:mem:test"); + } + @SuppressWarnings("resource") @Test public void testAbort() throws SQLException { @@ -109,6 +115,16 @@ public void testGetObjectIndex() throws SQLException { ResultSet rs = conn.getMetaData().getTypeInfo()) { rs.next(); assertNotNull(Jdbc41Bridge.getObject(rs, 1, String.class)); + // + assertNotNull(Jdbc41Bridge.getObject(rs, 2, Integer.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, 2, Long.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, 2, Double.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, 2, Float.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, 2, Byte.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, 2, BigDecimal.class)); + // + assertNotNull(Jdbc41Bridge.getObject(rs, 7, Short.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, 8, Boolean.class)); } } @@ -119,6 +135,26 @@ public void testGetObjectName() throws SQLException { ResultSet rs = conn.getMetaData().getTypeInfo()) { rs.next(); assertNotNull(Jdbc41Bridge.getObject(rs, "TYPE_NAME", String.class)); + // + assertNotNull(Jdbc41Bridge.getObject(rs, "DATA_TYPE", Integer.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, "DATA_TYPE", Long.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, "DATA_TYPE", Double.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, "DATA_TYPE", Float.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, "DATA_TYPE", Byte.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, "DATA_TYPE", BigDecimal.class)); + // + assertNotNull(Jdbc41Bridge.getObject(rs, "NULLABLE", Short.class)); + assertNotNull(Jdbc41Bridge.getObject(rs, "CASE_SENSITIVE", Boolean.class)); + } + } + + @Test + public void testGetParentLogger() throws SQLException { + // Normal + try (Connection conn = getConnection(); + Statement stmt = conn.createStatement()) { + // returns null for H2 (not supported). + Jdbc41Bridge.getParentLogger(new JdbcDataSource()); } } @@ -167,8 +203,4 @@ public void testSetSchema() throws SQLException { assertEquals(expected, Jdbc41Bridge.getSchema(conn)); } } - - private Connection getConnection() throws SQLException { - return DriverManager.getConnection("jdbc:h2:mem:test"); - } } From cef23df8a91f22cef33f5cdfa45f2ee3ed788019 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 00:32:28 -0500 Subject: [PATCH 152/169] Add basic missing tests in TestDelegatingConnection --- .../dbcp2/TestDelegatingConnection.java | 185 +++++++++++++++++- 1 file changed, 176 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java b/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java index ad712526ee..f29273c66a 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java @@ -20,33 +20,38 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; +import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.sql.Savepoint; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** + * Tests {@link DelegatingConnection}. */ public class TestDelegatingConnection { /** - * Delegate that doesn't support read-only or auto-commit. - * It will merely take the input value of setReadOnly and - * setAutoCommit and discard it, to keep false. + * Delegate that doesn't support read-only or auto-commit. It will merely take the input value of setReadOnly and setAutoCommit and discard it, to keep + * false. */ static class NoReadOnlyOrAutoCommitConnection extends TesterConnection { private final boolean readOnly = false; private final boolean autoCommit = false; public NoReadOnlyOrAutoCommitConnection() { - super("",""); + super("", ""); } @Override @@ -71,13 +76,12 @@ public void setReadOnly(final boolean readOnly) { } /** - * Delegate that will throw RTE on toString - * Used to validate fix for DBCP-241 + * Delegate that will throw RTE on toString Used to validate fix for DBCP-241 */ static class RTEGeneratingConnection extends TesterConnection { public RTEGeneratingConnection() { - super("",""); + super("", ""); } @Override @@ -90,9 +94,15 @@ public String toString() { private DelegatingConnection delegatingConnection; private Connection connection; private Connection connection2; + private DelegatingConnection h2DConnection; private TesterStatement testerStatement; private TesterResultSet testerResultSet; + @AfterEach + public void afterEach() throws SQLException { + h2DConnection.close(); + } + @BeforeEach public void setUp() throws Exception { connection = new TesterConnection("test", "test"); @@ -100,6 +110,13 @@ public void setUp() throws Exception { delegatingConnection = new DelegatingConnection<>(connection); testerStatement = new TesterStatement(delegatingConnection); testerResultSet = new TesterResultSet(testerStatement); + h2DConnection = new DelegatingConnection<>(DriverManager.getConnection("jdbc:h2:mem:test")); + } + + @Test + public void testAbort() throws Exception { + h2DConnection.abort(r -> { + }); } @Test @@ -153,7 +170,8 @@ public void testCheckOpenNull() throws Exception { delegatingConnection = new DelegatingConnection<>(pc); pc.close(); delegatingConnection.close(); - try (PreparedStatement ps = delegatingConnection.prepareStatement("")){} + try (PreparedStatement ps = delegatingConnection.prepareStatement("")) { + } fail("Expecting SQLException"); } catch (final SQLException ex) { assertTrue(ex.getMessage().endsWith("is closed.")); @@ -169,6 +187,11 @@ public void testCheckOpenNull() throws Exception { } } + @Test + public void testCommit() throws Exception { + h2DConnection.commit(); + } + @Test public void testConnectionToString() throws Exception { final String s = delegatingConnection.toString(); @@ -176,11 +199,82 @@ public void testConnectionToString() throws Exception { assertFalse(s.isEmpty()); } + @Test + public void testCreateArrayOf() throws Exception { + assertNotNull(h2DConnection.createArrayOf("CHARACTER", new Object[] { "A", "B" })); + } + + @Test + public void testCreateBlob() throws Exception { + assertNotNull(h2DConnection.createBlob()); + } + + @Test + public void testCreateClob() throws Exception { + assertNotNull(h2DConnection.createClob()); + } + + @Test + public void testCreateNClob() throws Exception { + assertNotNull(h2DConnection.createNClob()); + } + + @Test + public void testCreateSQLXML() throws Exception { + assertNotNull(h2DConnection.createSQLXML()); + } + + @Test + public void testCreateStruct() throws Exception { + // not supported by H2 + assertThrows(SQLException.class, () -> h2DConnection.createStruct("CHARACTER", new Object[] { "A", "B" })); + } + + @Test + public void testGetCacheState() throws Exception { + assertTrue(h2DConnection.getCacheState()); + } + + @Test + public void testGetClientInfo() throws Exception { + assertNotNull(h2DConnection.getClientInfo()); + } + + @Test + public void testGetClientInfoString() throws Exception { + assertNull(h2DConnection.getClientInfo("xyz")); + } + + @Test + public void testGetDefaultQueryTimeout() throws Exception { + assertNull(h2DConnection.getDefaultQueryTimeout()); + } + + @Test + public void testGetDefaultQueryTimeoutDuration() throws Exception { + assertNull(h2DConnection.getDefaultQueryTimeoutDuration()); + } + @Test public void testGetDelegate() throws Exception { assertEquals(connection, delegatingConnection.getDelegate()); } + @Test + public void testGetHoldability() throws Exception { + assertEquals(1, h2DConnection.getHoldability()); + } + + @Test + public void testGetNetworkTimeout() throws Exception { + assertEquals(0, h2DConnection.getNetworkTimeout()); + } + + @Test + public void testGetTypeMap() throws Exception { + assertNull(h2DConnection.getTypeMap()); + } + @Test public void testIsClosed() throws Exception { delegatingConnection.checkOpen(); @@ -197,6 +291,19 @@ public void testIsClosedNullDelegate() throws Exception { assertTrue(delegatingConnection.isClosed()); } + @SuppressWarnings("resource") + @Test + public void testIsWrapperFor() throws Exception { + assertTrue(delegatingConnection.isWrapperFor(delegatingConnection.getClass())); + assertTrue(delegatingConnection.isWrapperFor(delegatingConnection.getDelegate().getClass())); + assertThrows(SQLException.class, () -> delegatingConnection.isWrapperFor(Integer.class)); + } + + @Test + public void testNativeSQL() throws Exception { + assertNotNull(h2DConnection.nativeSQL("select 1")); + } + @Test public void testPassivateWithResultSetCloseException() { try { @@ -226,7 +333,7 @@ public void testPassivateWithResultSetCloseExceptionAndStatementCloseException() Assertions.assertEquals(2, ((SQLExceptionList) e).getCauseList().size()); } finally { testerStatement.setSqlExceptionOnClose(false); - testerResultSet.setSqlExceptionOnClose(false); + testerResultSet.setSqlExceptionOnClose(false); } } @@ -256,4 +363,64 @@ public void testReadOnlyCaching() throws SQLException { assertFalse(delCon.isReadOnly()); } + @Test + public void testReleaseSavepoint() throws Exception { + final Savepoint s = h2DConnection.setSavepoint(); + h2DConnection.releaseSavepoint(s); + } + + @Test + public void testRollback() throws Exception { + h2DConnection.rollback(); + } + + @Test + public void testRollbackSavepoint() throws Exception { + h2DConnection.setAutoCommit(false); + try { + h2DConnection.rollback(h2DConnection.setSavepoint()); + } finally { + h2DConnection.setAutoCommit(true); + } + } + + @Test + public void testSetClientInfo() throws Exception { + // TODO + // h2DConnection.setClientInfo("ApplicationName", "app1"); + } + + @Test + public void testSetDefaultQueryTimeout() throws Exception { + final int expected = 1; + delegatingConnection.setDefaultQueryTimeout(expected); + assertEquals(expected, delegatingConnection.getDefaultQueryTimeout()); + } + + @Test + public void testSetHoldability() throws Exception { + final int expected = 1; + h2DConnection.setHoldability(expected); + assertEquals(expected, h2DConnection.getHoldability()); + } + + @Test + public void testSetNetworkTimeout() throws Exception { + h2DConnection.setNetworkTimeout(r -> {}, 1); + assertEquals(0, h2DConnection.getNetworkTimeout()); + } + + @Test + public void testSetSavepoint() throws Exception { + h2DConnection.setSavepoint(); + } + + @SuppressWarnings("javadoc") + @Test + public void testUnwrap() throws Exception { + assertNotNull(delegatingConnection.unwrap(delegatingConnection.getClass())); + assertNotNull(delegatingConnection.unwrap(delegatingConnection.getDelegate().getClass())); + assertThrows(SQLException.class, () -> delegatingConnection.unwrap(Integer.class)); + } + } From 26ab567709f739bf47d8588a25e0347ffe2de5b6 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:12:38 -0500 Subject: [PATCH 153/169] org.apache.commons.dbcp2.datasources.TestFactory is now a @ParameterizedTest --- .../dbcp2/datasources/TestFactory.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java index 610652fe58..1ac7463bff 100644 --- a/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java +++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java @@ -29,20 +29,29 @@ import javax.naming.StringRefAddr; import javax.naming.spi.ObjectFactory; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** + * Tests SharedPoolDataSourceFactory. */ public class TestFactory { - // Bugzilla Bug 24082: bug in InstanceKeyDataSourceFactory - // There's a fatal bug in InstanceKeyDataSourceFactory that means you can't - // instantiate more than one factory. - // https://issues.apache.org/bugzilla/show_bug.cgi?id=24082 - @Test - public void testJNDI2Pools() throws Exception { + /** + * Tests Bugzilla Bug 24082: bug in InstanceKeyDataSourceFactory. + * + * There's a fatal bug in InstanceKeyDataSourceFactory that means you can't instantiate more than one factory. + * https://issues.apache.org/bugzilla/show_bug.cgi?id=24082 + */ + @ParameterizedTest + @ValueSource(strings = { "dataSourceName", "description", "jndiEnvironment", "loginTimeout", "blockWhenExhausted", "evictionPolicyClassName", "lifo", + "maxIdlePerKey", "maxTotalPerKey", "maxWaitMillis", "minEvictableIdleTimeMillis", "minIdlePerKey", "numTestsPerEvictionRun", + "softMinEvictableIdleTimeMillis", "testOnCreate", "testOnBorrow", "testOnReturn", "testWhileIdle", "timeBetweenEvictionRunsMillis", + "validationQuery", "validationQueryTimeout", "rollbackAfterValidation", "maxConnLifetimeMillis", "defaultAutoCommit", "defaultTransactionIsolation", + "defaultReadOnly" }) + public void testJNDI2Pools(final String string) throws Exception { final Reference refObj = new Reference(SharedPoolDataSource.class.getName()); - refObj.add(new StringRefAddr("dataSourceName","java:comp/env/jdbc/bookstoreCPDS")); + refObj.add(new StringRefAddr(string, "TestValue")); final Context context = new InitialContext(); final Hashtable env = new Hashtable<>(); From 0d50e482a0c3e90ca848942b9e2bae1b4789b76a Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:19:14 -0500 Subject: [PATCH 154/169] Internal refactoring --- .../InstanceKeyDataSourceFactory.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java index afd5c8f241..ae8e6efbfa 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java @@ -146,7 +146,7 @@ public Object getObjectInstance(final Object refObj, final Name name, final Cont final Reference ref = (Reference) refObj; if (isCorrectClass(ref.getClassName())) { final RefAddr refAddr = ref.get("instanceKey"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { // object was bound to JNDI via Referenceable API. obj = INSTANCE_MAP.get(refAddr.getContent()); } else { @@ -172,6 +172,10 @@ public Object getObjectInstance(final Object refObj, final Name name, final Cont return obj; } + private boolean hasContent(final RefAddr refAddr) { + return refAddr != null && refAddr.getContent() != null; + } + /** * Tests if className is the value returned from getClass().getName().toString(). * @@ -198,139 +202,139 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc throws IOException, ClassNotFoundException { RefAddr refAddr = ref.get("dataSourceName"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDataSourceName(toString(refAddr)); } refAddr = ref.get("description"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDescription(toString(refAddr)); } refAddr = ref.get("jndiEnvironment"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { final byte[] serialized = (byte[]) refAddr.getContent(); ikds.setJndiEnvironment((Properties) deserialize(serialized)); } refAddr = ref.get("loginTimeout"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setLoginTimeout(Duration.ofSeconds(parseInt(refAddr))); } // Pool properties refAddr = ref.get("blockWhenExhausted"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultBlockWhenExhausted(parseBoolean(refAddr)); } refAddr = ref.get("evictionPolicyClassName"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultEvictionPolicyClassName(toString(refAddr)); } // Pool properties refAddr = ref.get("lifo"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultLifo(parseBoolean(refAddr)); } refAddr = ref.get("maxIdlePerKey"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultMaxIdle(parseInt(refAddr)); } refAddr = ref.get("maxTotalPerKey"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultMaxTotal(parseInt(refAddr)); } refAddr = ref.get("maxWaitMillis"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultMaxWait(Duration.ofMillis(parseLong(refAddr))); } refAddr = ref.get("minEvictableIdleTimeMillis"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultMinEvictableIdle(Duration.ofMillis(parseLong(refAddr))); } refAddr = ref.get("minIdlePerKey"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultMinIdle(parseInt(refAddr)); } refAddr = ref.get("numTestsPerEvictionRun"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultNumTestsPerEvictionRun(parseInt(refAddr)); } refAddr = ref.get("softMinEvictableIdleTimeMillis"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultSoftMinEvictableIdle(Duration.ofMillis(parseLong(refAddr))); } refAddr = ref.get("testOnCreate"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultTestOnCreate(parseBoolean(refAddr)); } refAddr = ref.get("testOnBorrow"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultTestOnBorrow(parseBoolean(refAddr)); } refAddr = ref.get("testOnReturn"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultTestOnReturn(parseBoolean(refAddr)); } refAddr = ref.get("testWhileIdle"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultTestWhileIdle(parseBoolean(refAddr)); } refAddr = ref.get("timeBetweenEvictionRunsMillis"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultDurationBetweenEvictionRuns(Duration.ofMillis(parseLong(refAddr))); } // Connection factory properties refAddr = ref.get("validationQuery"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setValidationQuery(toString(refAddr)); } refAddr = ref.get("validationQueryTimeout"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setValidationQueryTimeout(Duration.ofSeconds(parseInt(refAddr))); } refAddr = ref.get("rollbackAfterValidation"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setRollbackAfterValidation(parseBoolean(refAddr)); } refAddr = ref.get("maxConnLifetimeMillis"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setMaxConnLifetime(Duration.ofMillis(parseLong(refAddr))); } // Connection properties refAddr = ref.get("defaultAutoCommit"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultAutoCommit(Boolean.valueOf(toString(refAddr))); } refAddr = ref.get("defaultTransactionIsolation"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultTransactionIsolation(parseInt(refAddr)); } refAddr = ref.get("defaultReadOnly"); - if (refAddr != null && refAddr.getContent() != null) { + if (hasContent(refAddr)) { ikds.setDefaultReadOnly(Boolean.valueOf(toString(refAddr))); } } From f1e8e5364432c3f16d9fd12ce4c2dfcb0f6f1b4f Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:49:40 -0500 Subject: [PATCH 155/169] org.apache.commons.dbcp2.datasources.TestFactory is now a @ParameterizedTest --- .../dbcp2/datasources/TestFactory.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java index 1ac7463bff..9638b76902 100644 --- a/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java +++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java @@ -30,7 +30,7 @@ import javax.naming.spi.ObjectFactory; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.CsvSource; /** * Tests SharedPoolDataSourceFactory. @@ -44,14 +44,38 @@ public class TestFactory { * https://issues.apache.org/bugzilla/show_bug.cgi?id=24082 */ @ParameterizedTest - @ValueSource(strings = { "dataSourceName", "description", "jndiEnvironment", "loginTimeout", "blockWhenExhausted", "evictionPolicyClassName", "lifo", - "maxIdlePerKey", "maxTotalPerKey", "maxWaitMillis", "minEvictableIdleTimeMillis", "minIdlePerKey", "numTestsPerEvictionRun", - "softMinEvictableIdleTimeMillis", "testOnCreate", "testOnBorrow", "testOnReturn", "testWhileIdle", "timeBetweenEvictionRunsMillis", - "validationQuery", "validationQueryTimeout", "rollbackAfterValidation", "maxConnLifetimeMillis", "defaultAutoCommit", "defaultTransactionIsolation", - "defaultReadOnly" }) - public void testJNDI2Pools(final String string) throws Exception { + // @formatter:off + @CsvSource({ + "dataSourceName, java:comp/env/jdbc/bookstoreCPDS", + "description, This is a test.", + "jndiEnvironment, X", + "loginTimeout, 30000", + "blockWhenExhausted, false", + "evictionPolicyClassName, org.apache.commons.pool2.impl.DefaultEvictionPolicy", + "lifo, true", + "maxIdlePerKey, 4", + "maxTotalPerKey, 4", + "maxWaitMillis, 30001", + "minEvictableIdleTimeMillis, 30002", + "minIdlePerKey, 4", + "numTestsPerEvictionRun, 2", + "softMinEvictableIdleTimeMillis, 30003", + "testOnCreate, true", + "testOnBorrow, true", + "testOnReturn, true", + "testWhileIdle, true", + "timeBetweenEvictionRunsMillis, 30004", + "validationQuery, select 1", + "validationQueryTimeout, 30005", + "rollbackAfterValidation, false", + "maxConnLifetimeMillis, 60000", + "defaultAutoCommit, true", + "defaultTransactionIsolation, X", + "defaultReadOnly, true" }) + // @formatter:on + public void testJNDI2Pools(final String string, final String value) throws Exception { final Reference refObj = new Reference(SharedPoolDataSource.class.getName()); - refObj.add(new StringRefAddr(string, "TestValue")); + refObj.add(new StringRefAddr(string, value)); final Context context = new InitialContext(); final Hashtable env = new Hashtable<>(); From 39f907e31393327a215b2e52948818d921a40638 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:50:00 -0500 Subject: [PATCH 156/169] Javadoc --- .../commons/dbcp2/datasources/PerUserPoolDataSource.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 67e5c2369c..0901c81e67 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -36,6 +36,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.pool2.ObjectPool; +import org.apache.commons.pool2.impl.EvictionPolicy; import org.apache.commons.pool2.impl.GenericObjectPool; /** @@ -354,6 +355,9 @@ public Duration getPerUserDurationBetweenEvictionRuns(final String userName) { /** * Gets the user specific value for {@link GenericObjectPool#getEvictionPolicyClassName()} for the specified user's * pool or the default if no user specific value is defined. + *

    + * The class must implement {@link EvictionPolicy}. + *

    * * @param userName * The user name key. @@ -832,7 +836,9 @@ void setPerUserEvictionPolicyClassName(final Map newMap) { /** * Sets a user specific value for {@link GenericObjectPool#getEvictionPolicyClassName()} for the specified user's * pool. - * + *

    + * The class must implement {@link EvictionPolicy}. + *

    * @param userName * The user name key. * @param value From b0d29ce76ae36792880c708b31fda12b97e080f5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:50:09 -0500 Subject: [PATCH 157/169] Internal refactoring --- .../InstanceKeyDataSourceFactory.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java index ae8e6efbfa..a9f8c28082 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java @@ -118,6 +118,10 @@ static void removeInstance(final String key) { } } + private Boolean booleanValueOf(RefAddr refAddr) { + return Boolean.valueOf(toString(refAddr)); + } + /** * Creates an instance of the subclass and sets any properties contained in the Reference. * @@ -219,7 +223,7 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("loginTimeout"); if (hasContent(refAddr)) { - ikds.setLoginTimeout(Duration.ofSeconds(parseInt(refAddr))); + ikds.setLoginTimeout(toDurationFromSeconds(refAddr)); } // Pool properties @@ -251,12 +255,12 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("maxWaitMillis"); if (hasContent(refAddr)) { - ikds.setDefaultMaxWait(Duration.ofMillis(parseLong(refAddr))); + ikds.setDefaultMaxWait(toDurationFromMillis(refAddr)); } refAddr = ref.get("minEvictableIdleTimeMillis"); if (hasContent(refAddr)) { - ikds.setDefaultMinEvictableIdle(Duration.ofMillis(parseLong(refAddr))); + ikds.setDefaultMinEvictableIdle(toDurationFromMillis(refAddr)); } refAddr = ref.get("minIdlePerKey"); @@ -271,7 +275,7 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("softMinEvictableIdleTimeMillis"); if (hasContent(refAddr)) { - ikds.setDefaultSoftMinEvictableIdle(Duration.ofMillis(parseLong(refAddr))); + ikds.setDefaultSoftMinEvictableIdle(toDurationFromMillis(refAddr)); } refAddr = ref.get("testOnCreate"); @@ -296,7 +300,7 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("timeBetweenEvictionRunsMillis"); if (hasContent(refAddr)) { - ikds.setDefaultDurationBetweenEvictionRuns(Duration.ofMillis(parseLong(refAddr))); + ikds.setDefaultDurationBetweenEvictionRuns(toDurationFromMillis(refAddr)); } // Connection factory properties @@ -308,7 +312,7 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("validationQueryTimeout"); if (hasContent(refAddr)) { - ikds.setValidationQueryTimeout(Duration.ofSeconds(parseInt(refAddr))); + ikds.setValidationQueryTimeout(toDurationFromSeconds(refAddr)); } refAddr = ref.get("rollbackAfterValidation"); @@ -318,14 +322,14 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("maxConnLifetimeMillis"); if (hasContent(refAddr)) { - ikds.setMaxConnLifetime(Duration.ofMillis(parseLong(refAddr))); + ikds.setMaxConnLifetime(toDurationFromMillis(refAddr)); } // Connection properties refAddr = ref.get("defaultAutoCommit"); if (hasContent(refAddr)) { - ikds.setDefaultAutoCommit(Boolean.valueOf(toString(refAddr))); + ikds.setDefaultAutoCommit(booleanValueOf(refAddr)); } refAddr = ref.get("defaultTransactionIsolation"); @@ -335,10 +339,18 @@ private void setCommonProperties(final Reference ref, final InstanceKeyDataSourc refAddr = ref.get("defaultReadOnly"); if (hasContent(refAddr)) { - ikds.setDefaultReadOnly(Boolean.valueOf(toString(refAddr))); + ikds.setDefaultReadOnly(booleanValueOf(refAddr)); } } + private Duration toDurationFromMillis(RefAddr refAddr) { + return Duration.ofMillis(parseLong(refAddr)); + } + + private Duration toDurationFromSeconds(RefAddr refAddr) { + return Duration.ofSeconds(parseInt(refAddr)); + } + String toString(final RefAddr refAddr) { return refAddr.getContent().toString(); } From cf9cfb7c62b006f5700f9de4d33fd080713b8467 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:56:06 -0500 Subject: [PATCH 158/169] Use static import for Assertions --- .../apache/commons/dbcp2/TestPStmtKey.java | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java b/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java index c4f852fe4f..9a80ffc5e5 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java +++ b/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java @@ -16,7 +16,9 @@ */ package org.apache.commons.dbcp2; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -26,7 +28,6 @@ import java.util.Arrays; import org.apache.commons.dbcp2.PoolingConnection.StatementType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** @@ -39,35 +40,35 @@ public class TestPStmtKey { */ @Test public void testCtorDifferentCatalog() { - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog2", "schema1")); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog2", "schema1")); + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), new PStmtKey("sql", "catalog2", "schema1", 0)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), new PStmtKey("sql", "catalog2", "schema1", 0, 0)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), new PStmtKey("sql", "catalog2", "schema1", 0, 0, 0)); // - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT)); // - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", 0, 0, StatementType.PREPARED_STATEMENT)); // - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), new PStmtKey("sql", "catalog2", "schema1", (int[]) null)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), new PStmtKey("sql", "catalog2", "schema1", new int[1])); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), new PStmtKey("sql", "catalog2", "schema1", (String[]) null)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), new PStmtKey("sql", "catalog2", "schema1", new String[] {"A" })); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", StatementType.PREPARED_STATEMENT)); - Assertions.assertNotEquals( + assertNotEquals( new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE), new PStmtKey("sql", "catalog2", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE)); } @@ -77,35 +78,35 @@ public void testCtorDifferentCatalog() { */ @Test public void testCtorDifferentSchema() { - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema2")); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema2")); + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), new PStmtKey("sql", "catalog1", "schema2", 0)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), new PStmtKey("sql", "catalog1", "schema2", 0, 0)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), new PStmtKey("sql", "catalog1", "schema2", 0, 0, 0)); // - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", 0, 0, 0, StatementType.CALLABLE_STATEMENT)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", 0, 0, 0, StatementType.PREPARED_STATEMENT)); // - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", 0, 0, StatementType.CALLABLE_STATEMENT)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", 0, 0, StatementType.PREPARED_STATEMENT)); // - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), new PStmtKey("sql", "catalog1", "schema2", (int[]) null)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), new PStmtKey("sql", "catalog1", "schema2", new int[1])); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), new PStmtKey("sql", "catalog1", "schema2", (String[]) null)); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), new PStmtKey("sql", "catalog1", "schema2", new String[] {"A" })); - Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), + assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", StatementType.PREPARED_STATEMENT)); - Assertions.assertNotEquals( + assertNotEquals( new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE), new PStmtKey("sql", "catalog1", "schema2", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE)); } @@ -115,35 +116,35 @@ public void testCtorDifferentSchema() { */ @Test public void testCtorEquals() { - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema1")); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0), + assertEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema1")); + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0), new PStmtKey("sql", "catalog1", "schema1", 0)); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), new PStmtKey("sql", "catalog1", "schema1", 0, 0)); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0)); // - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.CALLABLE_STATEMENT)); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT)); // - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.CALLABLE_STATEMENT)); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT)); // - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), new PStmtKey("sql", "catalog1", "schema1", (int[]) null)); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), new PStmtKey("sql", "catalog1", "schema1", new int[1])); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), new PStmtKey("sql", "catalog1", "schema1", (String[]) null)); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" })); - Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), + assertEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT)); - Assertions.assertEquals( + assertEquals( new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE), new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE)); } @@ -157,10 +158,10 @@ public void testCtorEquals() { public void testCtorStringStringArrayOfInts() { final int[] input = {0, 0}; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assertions.assertArrayEquals(input, pStmtKey.getColumnIndexes()); + assertArrayEquals(input, pStmtKey.getColumnIndexes()); input[0] = 1; input[1] = 1; - Assertions.assertFalse(Arrays.equals(input, pStmtKey.getColumnIndexes())); + assertFalse(Arrays.equals(input, pStmtKey.getColumnIndexes())); } /** @@ -172,7 +173,7 @@ public void testCtorStringStringArrayOfInts() { public void testCtorStringStringArrayOfNullInts() { final int[] input = null; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assertions.assertArrayEquals(input, pStmtKey.getColumnIndexes()); + assertArrayEquals(input, pStmtKey.getColumnIndexes()); } /** @@ -184,7 +185,7 @@ public void testCtorStringStringArrayOfNullInts() { public void testCtorStringStringArrayOfNullStrings() { final String[] input = null; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assertions.assertArrayEquals(input, pStmtKey.getColumnNames()); + assertArrayEquals(input, pStmtKey.getColumnNames()); } /** @@ -196,10 +197,10 @@ public void testCtorStringStringArrayOfNullStrings() { public void testCtorStringStringArrayOfStrings() { final String[] input = {"A", "B"}; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assertions.assertArrayEquals(input, pStmtKey.getColumnNames()); + assertArrayEquals(input, pStmtKey.getColumnNames()); input[0] = "C"; input[1] = "D"; - Assertions.assertFalse(Arrays.equals(input, pStmtKey.getColumnNames())); + assertFalse(Arrays.equals(input, pStmtKey.getColumnNames())); } @Test From 092a0b0170e119c59352c27df48ac573a1ae821e Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 08:56:14 -0500 Subject: [PATCH 159/169] Javadoc --- .../org/apache/commons/dbcp2/cpdsadapter/PStmtKeyCPDS.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PStmtKeyCPDS.java b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PStmtKeyCPDS.java index 2fc938ed5b..9bb326f316 100644 --- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PStmtKeyCPDS.java +++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PStmtKeyCPDS.java @@ -16,10 +16,12 @@ */ package org.apache.commons.dbcp2.cpdsadapter; +import java.sql.PreparedStatement; + import org.apache.commons.dbcp2.PStmtKey; /** - * A key uniquely identifying a {@link java.sql.PreparedStatement PreparedStatement}. + * A key uniquely identifying a {@link PreparedStatement}. * * @since 2.0 * @deprecated Use {@link PStmtKey}. From 14cab25562c8cad9103ecb2011e832925cbd7c6a Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 15:11:12 -0500 Subject: [PATCH 160/169] Internal refactoring in DelegatingDatabaseMetaData --- .../dbcp2/DelegatingDatabaseMetaData.java | 1376 +++-------------- .../dbcp2/TestDelegatingDatabaseMetaData.java | 863 ++++++++--- 2 files changed, 882 insertions(+), 1357 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java index f19f3bbbc8..d77ab697de 100644 --- a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java +++ b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java @@ -22,14 +22,15 @@ import java.sql.RowIdLifetime; import java.sql.SQLException; import java.util.Objects; +import java.util.concurrent.Callable; /** *

    * A base delegating implementation of {@link DatabaseMetaData}. *

    *

    - * Methods that create {@link ResultSet} objects are wrapped to create {@link DelegatingResultSet} objects and the - * remaining methods simply call the corresponding method on the "delegate" provided in the constructor. + * Methods that create {@link ResultSet} objects are wrapped to create {@link DelegatingResultSet} objects and the remaining methods simply call the + * corresponding method on the "delegate" provided in the constructor. *

    * * @since 2.0 @@ -45,190 +46,115 @@ public class DelegatingDatabaseMetaData implements DatabaseMetaData { /** * Constructs a new instance for the given delegating connection and database meta data. * - * @param connection - * the delegating connection - * @param databaseMetaData - * the database meta data + * @param connection the delegating connection + * @param databaseMetaData the database meta data */ - public DelegatingDatabaseMetaData(final DelegatingConnection connection, - final DatabaseMetaData databaseMetaData) { + public DelegatingDatabaseMetaData(final DelegatingConnection connection, final DatabaseMetaData databaseMetaData) { this.connection = Objects.requireNonNull(connection, "connection"); this.databaseMetaData = Objects.requireNonNull(databaseMetaData, "databaseMetaData"); } @Override public boolean allProceduresAreCallable() throws SQLException { - try { - return databaseMetaData.allProceduresAreCallable(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::allProceduresAreCallable); } @Override public boolean allTablesAreSelectable() throws SQLException { - try { - return databaseMetaData.allTablesAreSelectable(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::allTablesAreSelectable); } @Override public boolean autoCommitFailureClosesAllResultSets() throws SQLException { - try { - return databaseMetaData.autoCommitFailureClosesAllResultSets(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::autoCommitFailureClosesAllResultSets); } @Override public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - try { - return databaseMetaData.dataDefinitionCausesTransactionCommit(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::dataDefinitionCausesTransactionCommit); } @Override public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - try { - return databaseMetaData.dataDefinitionIgnoredInTransactions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::dataDefinitionIgnoredInTransactions); } @Override public boolean deletesAreDetected(final int type) throws SQLException { - try { - return databaseMetaData.deletesAreDetected(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.deletesAreDetected(type)); } @Override public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - try { - return databaseMetaData.doesMaxRowSizeIncludeBlobs(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::doesMaxRowSizeIncludeBlobs); } @Override public boolean generatedKeyAlwaysReturned() throws SQLException { connection.checkOpen(); + return getB(() -> Jdbc41Bridge.generatedKeyAlwaysReturned(databaseMetaData)); + } + + private T get(final Callable s) throws SQLException { + return get(s, null); + } + + private T get(final Callable s, final T defaultValue) throws SQLException { try { - return Jdbc41Bridge.generatedKeyAlwaysReturned(databaseMetaData); - } catch (final SQLException e) { - handleException(e); - return false; + return s.call(); + } catch (final Exception e) { + if (e instanceof SQLException) { + handleException((SQLException) e); + } + return defaultValue; } } @Override - public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern, - final String attributeNamePattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getAttributes(catalog, schemaPattern, typeNamePattern, attributeNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern, final String attributeNamePattern) + throws SQLException { + return getRS(() -> databaseMetaData.getAttributes(catalog, schemaPattern, typeNamePattern, attributeNamePattern)); + } + + private boolean getB(final Callable s) throws SQLException { + return get(s, false); } @Override - public ResultSet getBestRowIdentifier(final String catalog, final String schema, final String table, - final int scope, final boolean nullable) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getBestRowIdentifier(catalog, schema, table, scope, nullable)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getBestRowIdentifier(final String catalog, final String schema, final String table, final int scope, final boolean nullable) + throws SQLException { + return getRS(() -> databaseMetaData.getBestRowIdentifier(catalog, schema, table, scope, nullable)); } @Override public ResultSet getCatalogs() throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getCatalogs()); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(databaseMetaData::getCatalogs); } @Override public String getCatalogSeparator() throws SQLException { - try { - return databaseMetaData.getCatalogSeparator(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getCatalogSeparator); } @Override public String getCatalogTerm() throws SQLException { - try { - return databaseMetaData.getCatalogTerm(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getCatalogTerm); } @Override public ResultSet getClientInfoProperties() throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getClientInfoProperties()); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(databaseMetaData::getClientInfoProperties); } @Override - public ResultSet getColumnPrivileges(final String catalog, final String schema, final String table, - final String columnNamePattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getColumnPrivileges(catalog, schema, table, columnNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getColumnPrivileges(final String catalog, final String schema, final String table, final String columnNamePattern) throws SQLException { + return getRS(() -> databaseMetaData.getColumnPrivileges(catalog, schema, table, columnNamePattern)); } @Override - public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern, - final String columnNamePattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern, final String columnNamePattern) + throws SQLException { + return getRS(() -> databaseMetaData.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern)); } @Override @@ -237,66 +163,34 @@ public Connection getConnection() throws SQLException { } @Override - public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, final String parentTable, - final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getCrossReference(parentCatalog, - parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, final String parentTable, final String foreignCatalog, + final String foreignSchema, final String foreignTable) throws SQLException { + return getRS(() -> databaseMetaData.getCrossReference(parentCatalog, parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable)); } @Override public int getDatabaseMajorVersion() throws SQLException { - try { - return databaseMetaData.getDatabaseMajorVersion(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getDatabaseMajorVersion); } @Override public int getDatabaseMinorVersion() throws SQLException { - try { - return databaseMetaData.getDatabaseMinorVersion(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getDatabaseMinorVersion); } @Override public String getDatabaseProductName() throws SQLException { - try { - return databaseMetaData.getDatabaseProductName(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getDatabaseProductName); } @Override public String getDatabaseProductVersion() throws SQLException { - try { - return databaseMetaData.getDatabaseProductVersion(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getDatabaseProductVersion); } @Override public int getDefaultTransactionIsolation() throws SQLException { - try { - return databaseMetaData.getDefaultTransactionIsolation(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getDefaultTransactionIsolation); } /** @@ -320,119 +214,63 @@ public int getDriverMinorVersion() { @Override public String getDriverName() throws SQLException { - try { - return databaseMetaData.getDriverName(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getDriverName); } @Override public String getDriverVersion() throws SQLException { - try { - return databaseMetaData.getDriverVersion(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getDriverVersion); } @Override - public ResultSet getExportedKeys(final String catalog, final String schema, final String table) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getExportedKeys(catalog, schema, table)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getExportedKeys(final String catalog, final String schema, final String table) throws SQLException { + return getRS(() -> databaseMetaData.getExportedKeys(catalog, schema, table)); } @Override public String getExtraNameCharacters() throws SQLException { - try { - return databaseMetaData.getExtraNameCharacters(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getExtraNameCharacters); } @Override - public ResultSet getFunctionColumns(final String catalog, final String schemaPattern, - final String functionNamePattern, final String columnNamePattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getFunctionColumns(catalog, - schemaPattern, functionNamePattern, columnNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getFunctionColumns(final String catalog, final String schemaPattern, final String functionNamePattern, final String columnNamePattern) + throws SQLException { + return getRS(() -> databaseMetaData.getFunctionColumns(catalog, schemaPattern, functionNamePattern, columnNamePattern)); } @Override - public ResultSet getFunctions(final String catalog, final String schemaPattern, final String functionNamePattern) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getFunctions(catalog, schemaPattern, functionNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getFunctions(final String catalog, final String schemaPattern, final String functionNamePattern) throws SQLException { + return getRS(() -> databaseMetaData.getFunctions(catalog, schemaPattern, functionNamePattern)); + } + + private int getI(final Callable s) throws SQLException { + return get(s, 0); } @Override public String getIdentifierQuoteString() throws SQLException { - try { - return databaseMetaData.getIdentifierQuoteString(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getIdentifierQuoteString); } @Override - public ResultSet getImportedKeys(final String catalog, final String schema, final String table) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getImportedKeys(catalog, schema, table)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getImportedKeys(final String catalog, final String schema, final String table) throws SQLException { + return getRS(() -> databaseMetaData.getImportedKeys(catalog, schema, table)); } @Override - public ResultSet getIndexInfo(final String catalog, final String schema, final String table, final boolean unique, - final boolean approximate) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getIndexInfo(catalog, schema, table, unique, approximate)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getIndexInfo(final String catalog, final String schema, final String table, final boolean unique, final boolean approximate) + throws SQLException { + return getRS(() -> databaseMetaData.getIndexInfo(catalog, schema, table, unique, approximate)); } /** - * If my underlying {@link ResultSet} is not a {@code DelegatingResultSet}, returns it, otherwise recursively - * invokes this method on my delegate. + * If my underlying {@link ResultSet} is not a {@code DelegatingResultSet}, returns it, otherwise recursively invokes this method on my delegate. *

    - * Hence this method will return the first delegate that is not a {@code DelegatingResultSet}, or {@code null} when - * no non-{@code DelegatingResultSet} delegate can be found by traversing this chain. + * Hence this method will return the first delegate that is not a {@code DelegatingResultSet}, or {@code null} when no non-{@code DelegatingResultSet} + * delegate can be found by traversing this chain. *

    *

    - * This method is useful when you may have nested {@code DelegatingResultSet}s, and you want to make sure to obtain - * a "genuine" {@link ResultSet}. + * This method is useful when you may have nested {@code DelegatingResultSet}s, and you want to make sure to obtain a "genuine" {@link ResultSet}. *

    * * @return the innermost database meta data. @@ -450,142 +288,76 @@ public DatabaseMetaData getInnermostDelegate() { @Override public int getJDBCMajorVersion() throws SQLException { - try { - return databaseMetaData.getJDBCMajorVersion(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getJDBCMajorVersion); } @Override public int getJDBCMinorVersion() throws SQLException { - try { - return databaseMetaData.getJDBCMinorVersion(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getJDBCMinorVersion); + } + + private long getL(final Callable s) throws SQLException { + return get(s, 0L); } @Override public int getMaxBinaryLiteralLength() throws SQLException { - try { - return databaseMetaData.getMaxBinaryLiteralLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxBinaryLiteralLength); } @Override public int getMaxCatalogNameLength() throws SQLException { - try { - return databaseMetaData.getMaxCatalogNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxCatalogNameLength); } @Override public int getMaxCharLiteralLength() throws SQLException { - try { - return databaseMetaData.getMaxCharLiteralLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxCharLiteralLength); } @Override public int getMaxColumnNameLength() throws SQLException { - try { - return databaseMetaData.getMaxColumnNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxColumnNameLength); } @Override public int getMaxColumnsInGroupBy() throws SQLException { - try { - return databaseMetaData.getMaxColumnsInGroupBy(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxColumnsInGroupBy); } @Override public int getMaxColumnsInIndex() throws SQLException { - try { - return databaseMetaData.getMaxColumnsInIndex(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxColumnsInIndex); } @Override public int getMaxColumnsInOrderBy() throws SQLException { - try { - return databaseMetaData.getMaxColumnsInOrderBy(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxColumnsInOrderBy); } @Override public int getMaxColumnsInSelect() throws SQLException { - try { - return databaseMetaData.getMaxColumnsInSelect(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxColumnsInSelect); } @Override public int getMaxColumnsInTable() throws SQLException { - try { - return databaseMetaData.getMaxColumnsInTable(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxColumnsInTable); } @Override public int getMaxConnections() throws SQLException { - try { - return databaseMetaData.getMaxConnections(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxConnections); } @Override public int getMaxCursorNameLength() throws SQLException { - try { - return databaseMetaData.getMaxCursorNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxCursorNameLength); } @Override public int getMaxIndexLength() throws SQLException { - try { - return databaseMetaData.getMaxIndexLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxIndexLength); } /** @@ -593,395 +365,190 @@ public int getMaxIndexLength() throws SQLException { */ @Override public long getMaxLogicalLobSize() throws SQLException { - try { - return databaseMetaData.getMaxLogicalLobSize(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getL(databaseMetaData::getMaxLogicalLobSize); } @Override public int getMaxProcedureNameLength() throws SQLException { - try { - return databaseMetaData.getMaxProcedureNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxProcedureNameLength); } @Override public int getMaxRowSize() throws SQLException { - try { - return databaseMetaData.getMaxRowSize(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxRowSize); } @Override public int getMaxSchemaNameLength() throws SQLException { - try { - return databaseMetaData.getMaxSchemaNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxSchemaNameLength); } @Override public int getMaxStatementLength() throws SQLException { - try { - return databaseMetaData.getMaxStatementLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxStatementLength); } @Override public int getMaxStatements() throws SQLException { - try { - return databaseMetaData.getMaxStatements(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxStatements); } @Override public int getMaxTableNameLength() throws SQLException { - try { - return databaseMetaData.getMaxTableNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxTableNameLength); } @Override public int getMaxTablesInSelect() throws SQLException { - try { - return databaseMetaData.getMaxTablesInSelect(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxTablesInSelect); } @Override public int getMaxUserNameLength() throws SQLException { - try { - return databaseMetaData.getMaxUserNameLength(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getMaxUserNameLength); } @Override public String getNumericFunctions() throws SQLException { - try { - return databaseMetaData.getNumericFunctions(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getNumericFunctions); } @Override public ResultSet getPrimaryKeys(final String catalog, final String schema, final String table) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getPrimaryKeys(catalog, schema, table)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(() -> databaseMetaData.getPrimaryKeys(catalog, schema, table)); } @Override - public ResultSet getProcedureColumns(final String catalog, final String schemaPattern, - final String procedureNamePattern, final String columnNamePattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getProcedureColumns(catalog, - schemaPattern, procedureNamePattern, columnNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getProcedureColumns(final String catalog, final String schemaPattern, final String procedureNamePattern, final String columnNamePattern) + throws SQLException { + return getRS(() -> databaseMetaData.getProcedureColumns(catalog, schemaPattern, procedureNamePattern, columnNamePattern)); } @Override - public ResultSet getProcedures(final String catalog, final String schemaPattern, final String procedureNamePattern) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getProcedures(catalog, schemaPattern, procedureNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getProcedures(final String catalog, final String schemaPattern, final String procedureNamePattern) throws SQLException { + return getRS(() -> databaseMetaData.getProcedures(catalog, schemaPattern, procedureNamePattern)); } @Override public String getProcedureTerm() throws SQLException { - try { - return databaseMetaData.getProcedureTerm(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getProcedureTerm); } @Override - public ResultSet getPseudoColumns(final String catalog, final String schemaPattern, final String tableNamePattern, - final String columnNamePattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, Jdbc41Bridge.getPseudoColumns(databaseMetaData, - catalog, schemaPattern, tableNamePattern, columnNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getPseudoColumns(final String catalog, final String schemaPattern, final String tableNamePattern, final String columnNamePattern) + throws SQLException { + return getRS(() -> Jdbc41Bridge.getPseudoColumns(databaseMetaData, catalog, schemaPattern, tableNamePattern, columnNamePattern)); } @Override public int getResultSetHoldability() throws SQLException { - try { - return databaseMetaData.getResultSetHoldability(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getResultSetHoldability); } @Override public RowIdLifetime getRowIdLifetime() throws SQLException { - try { - return databaseMetaData.getRowIdLifetime(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getRowIdLifetime); + } + + @SuppressWarnings("resource") + private ResultSet getRS(final Callable s) throws SQLException { + connection.checkOpen(); + return DelegatingResultSet.wrapResultSet(connection, get(s)); } @Override public ResultSet getSchemas() throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getSchemas()); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(databaseMetaData::getSchemas); } @Override public ResultSet getSchemas(final String catalog, final String schemaPattern) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getSchemas(catalog, schemaPattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(() -> databaseMetaData.getSchemas(catalog, schemaPattern)); } @Override public String getSchemaTerm() throws SQLException { - try { - return databaseMetaData.getSchemaTerm(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getSchemaTerm); } @Override public String getSearchStringEscape() throws SQLException { - try { - return databaseMetaData.getSearchStringEscape(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getSearchStringEscape); } @Override public String getSQLKeywords() throws SQLException { - try { - return databaseMetaData.getSQLKeywords(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getSQLKeywords); } @Override public int getSQLStateType() throws SQLException { - try { - return databaseMetaData.getSQLStateType(); - } catch (final SQLException e) { - handleException(e); - return 0; - } + return getI(databaseMetaData::getSQLStateType); } @Override public String getStringFunctions() throws SQLException { - try { - return databaseMetaData.getStringFunctions(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getStringFunctions); } @Override - public ResultSet getSuperTables(final String catalog, final String schemaPattern, final String tableNamePattern) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getSuperTables(catalog, schemaPattern, tableNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getSuperTables(final String catalog, final String schemaPattern, final String tableNamePattern) throws SQLException { + return getRS(() -> databaseMetaData.getSuperTables(catalog, schemaPattern, tableNamePattern)); } @Override - public ResultSet getSuperTypes(final String catalog, final String schemaPattern, final String typeNamePattern) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getSuperTypes(catalog, schemaPattern, typeNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getSuperTypes(final String catalog, final String schemaPattern, final String typeNamePattern) throws SQLException { + return getRS(() -> databaseMetaData.getSuperTypes(catalog, schemaPattern, typeNamePattern)); } @Override public String getSystemFunctions() throws SQLException { - try { - return databaseMetaData.getSystemFunctions(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getSystemFunctions); } @Override - public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, final String tableNamePattern) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getTablePrivileges(catalog, schemaPattern, tableNamePattern)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, final String tableNamePattern) throws SQLException { + return getRS(() -> databaseMetaData.getTablePrivileges(catalog, schemaPattern, tableNamePattern)); } @Override - public ResultSet getTables(final String catalog, final String schemaPattern, final String tableNamePattern, - final String[] types) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getTables(catalog, schemaPattern, tableNamePattern, types)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getTables(final String catalog, final String schemaPattern, final String tableNamePattern, final String[] types) throws SQLException { + return getRS(() -> databaseMetaData.getTables(catalog, schemaPattern, tableNamePattern, types)); } @Override public ResultSet getTableTypes() throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getTableTypes()); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(databaseMetaData::getTableTypes); } @Override public String getTimeDateFunctions() throws SQLException { - try { - return databaseMetaData.getTimeDateFunctions(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getTimeDateFunctions); } @Override public ResultSet getTypeInfo() throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getTypeInfo()); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return getRS(databaseMetaData::getTypeInfo); } @Override - public ResultSet getUDTs(final String catalog, final String schemaPattern, final String typeNamePattern, - final int[] types) throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getUDTs(catalog, schemaPattern, typeNamePattern, types)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getUDTs(final String catalog, final String schemaPattern, final String typeNamePattern, final int[] types) throws SQLException { + return getRS(() -> databaseMetaData.getUDTs(catalog, schemaPattern, typeNamePattern, types)); } @Override public String getURL() throws SQLException { - try { - return databaseMetaData.getURL(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getURL); } @Override public String getUserName() throws SQLException { - try { - return databaseMetaData.getUserName(); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + return get(databaseMetaData::getUserName); } @Override - public ResultSet getVersionColumns(final String catalog, final String schema, final String table) - throws SQLException { - connection.checkOpen(); - try { - return DelegatingResultSet.wrapResultSet(connection, - databaseMetaData.getVersionColumns(catalog, schema, table)); - } catch (final SQLException e) { - handleException(e); - throw new AssertionError(); - } + public ResultSet getVersionColumns(final String catalog, final String schema, final String table) throws SQLException { + return getRS(() -> databaseMetaData.getVersionColumns(catalog, schema, table)); } /** @@ -999,32 +566,17 @@ protected void handleException(final SQLException e) throws SQLException { @Override public boolean insertsAreDetected(final int type) throws SQLException { - try { - return databaseMetaData.insertsAreDetected(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.insertsAreDetected(type)); } @Override public boolean isCatalogAtStart() throws SQLException { - try { - return databaseMetaData.isCatalogAtStart(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::isCatalogAtStart); } @Override public boolean isReadOnly() throws SQLException { - try { - return databaseMetaData.isReadOnly(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::isReadOnly); } @Override @@ -1040,632 +592,318 @@ public boolean isWrapperFor(final Class iface) throws SQLException { @Override public boolean locatorsUpdateCopy() throws SQLException { - try { - return databaseMetaData.locatorsUpdateCopy(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::locatorsUpdateCopy); } @Override public boolean nullPlusNonNullIsNull() throws SQLException { - try { - return databaseMetaData.nullPlusNonNullIsNull(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::nullPlusNonNullIsNull); } @Override public boolean nullsAreSortedAtEnd() throws SQLException { - try { - return databaseMetaData.nullsAreSortedAtEnd(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::nullsAreSortedAtEnd); } @Override public boolean nullsAreSortedAtStart() throws SQLException { - try { - return databaseMetaData.nullsAreSortedAtStart(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::nullsAreSortedAtStart); } @Override public boolean nullsAreSortedHigh() throws SQLException { - try { - return databaseMetaData.nullsAreSortedHigh(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::nullsAreSortedHigh); } @Override public boolean nullsAreSortedLow() throws SQLException { - try { - return databaseMetaData.nullsAreSortedLow(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::nullsAreSortedLow); } @Override public boolean othersDeletesAreVisible(final int type) throws SQLException { - try { - return databaseMetaData.othersDeletesAreVisible(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.othersDeletesAreVisible(type)); } @Override public boolean othersInsertsAreVisible(final int type) throws SQLException { - try { - return databaseMetaData.othersInsertsAreVisible(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.othersInsertsAreVisible(type)); } @Override public boolean othersUpdatesAreVisible(final int type) throws SQLException { - try { - return databaseMetaData.othersUpdatesAreVisible(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.othersUpdatesAreVisible(type)); } @Override public boolean ownDeletesAreVisible(final int type) throws SQLException { - try { - return databaseMetaData.ownDeletesAreVisible(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.ownDeletesAreVisible(type)); } @Override public boolean ownInsertsAreVisible(final int type) throws SQLException { - try { - return databaseMetaData.ownInsertsAreVisible(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.ownInsertsAreVisible(type)); } @Override public boolean ownUpdatesAreVisible(final int type) throws SQLException { - try { - return databaseMetaData.ownUpdatesAreVisible(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.ownUpdatesAreVisible(type)); } @Override public boolean storesLowerCaseIdentifiers() throws SQLException { - try { - return databaseMetaData.storesLowerCaseIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::storesLowerCaseIdentifiers); } @Override public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - try { - return databaseMetaData.storesLowerCaseQuotedIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::storesLowerCaseQuotedIdentifiers); } @Override public boolean storesMixedCaseIdentifiers() throws SQLException { - try { - return databaseMetaData.storesMixedCaseIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::storesMixedCaseIdentifiers); } @Override public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - try { - return databaseMetaData.storesMixedCaseQuotedIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::storesMixedCaseQuotedIdentifiers); } @Override public boolean storesUpperCaseIdentifiers() throws SQLException { - try { - return databaseMetaData.storesUpperCaseIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::storesUpperCaseIdentifiers); + } @Override public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - try { - return databaseMetaData.storesUpperCaseQuotedIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::storesUpperCaseQuotedIdentifiers); } @Override public boolean supportsAlterTableWithAddColumn() throws SQLException { - try { - return databaseMetaData.supportsAlterTableWithAddColumn(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsAlterTableWithAddColumn); } @Override public boolean supportsAlterTableWithDropColumn() throws SQLException { - try { - return databaseMetaData.supportsAlterTableWithDropColumn(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsAlterTableWithDropColumn); } @Override public boolean supportsANSI92EntryLevelSQL() throws SQLException { - try { - return databaseMetaData.supportsANSI92EntryLevelSQL(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsANSI92EntryLevelSQL); } @Override public boolean supportsANSI92FullSQL() throws SQLException { - try { - return databaseMetaData.supportsANSI92FullSQL(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsANSI92FullSQL); } @Override public boolean supportsANSI92IntermediateSQL() throws SQLException { - try { - return databaseMetaData.supportsANSI92IntermediateSQL(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsANSI92IntermediateSQL); } @Override public boolean supportsBatchUpdates() throws SQLException { - try { - return databaseMetaData.supportsBatchUpdates(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsBatchUpdates); } @Override public boolean supportsCatalogsInDataManipulation() throws SQLException { - try { - return databaseMetaData.supportsCatalogsInDataManipulation(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCatalogsInDataManipulation); } @Override public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - try { - return databaseMetaData.supportsCatalogsInIndexDefinitions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCatalogsInIndexDefinitions); } @Override public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - try { - return databaseMetaData.supportsCatalogsInPrivilegeDefinitions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCatalogsInPrivilegeDefinitions); } @Override public boolean supportsCatalogsInProcedureCalls() throws SQLException { - try { - return databaseMetaData.supportsCatalogsInProcedureCalls(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCatalogsInProcedureCalls); } @Override public boolean supportsCatalogsInTableDefinitions() throws SQLException { - try { - return databaseMetaData.supportsCatalogsInTableDefinitions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCatalogsInTableDefinitions); } @Override public boolean supportsColumnAliasing() throws SQLException { - try { - return databaseMetaData.supportsColumnAliasing(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsColumnAliasing); } @Override public boolean supportsConvert() throws SQLException { - try { - return databaseMetaData.supportsConvert(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsConvert); } @Override public boolean supportsConvert(final int fromType, final int toType) throws SQLException { - try { - return databaseMetaData.supportsConvert(fromType, toType); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.supportsConvert(fromType, toType)); } @Override public boolean supportsCoreSQLGrammar() throws SQLException { - try { - return databaseMetaData.supportsCoreSQLGrammar(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCoreSQLGrammar); } @Override public boolean supportsCorrelatedSubqueries() throws SQLException { - try { - return databaseMetaData.supportsCorrelatedSubqueries(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsCorrelatedSubqueries); } @Override public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { - try { - return databaseMetaData.supportsDataDefinitionAndDataManipulationTransactions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsDataDefinitionAndDataManipulationTransactions); } @Override public boolean supportsDataManipulationTransactionsOnly() throws SQLException { - try { - return databaseMetaData.supportsDataManipulationTransactionsOnly(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsDataManipulationTransactionsOnly); } @Override public boolean supportsDifferentTableCorrelationNames() throws SQLException { - try { - return databaseMetaData.supportsDifferentTableCorrelationNames(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsDifferentTableCorrelationNames); } @Override public boolean supportsExpressionsInOrderBy() throws SQLException { - try { - return databaseMetaData.supportsExpressionsInOrderBy(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsExpressionsInOrderBy); } @Override public boolean supportsExtendedSQLGrammar() throws SQLException { - try { - return databaseMetaData.supportsExtendedSQLGrammar(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsExtendedSQLGrammar); } @Override public boolean supportsFullOuterJoins() throws SQLException { - try { - return databaseMetaData.supportsFullOuterJoins(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsFullOuterJoins); } @Override public boolean supportsGetGeneratedKeys() throws SQLException { - try { - return databaseMetaData.supportsGetGeneratedKeys(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsGetGeneratedKeys); } @Override public boolean supportsGroupBy() throws SQLException { - try { - return databaseMetaData.supportsGroupBy(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsGroupBy); } @Override public boolean supportsGroupByBeyondSelect() throws SQLException { - try { - return databaseMetaData.supportsGroupByBeyondSelect(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsGroupByBeyondSelect); } @Override public boolean supportsGroupByUnrelated() throws SQLException { - try { - return databaseMetaData.supportsGroupByUnrelated(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsGroupByUnrelated); } @Override public boolean supportsIntegrityEnhancementFacility() throws SQLException { - try { - return databaseMetaData.supportsIntegrityEnhancementFacility(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsIntegrityEnhancementFacility); } @Override public boolean supportsLikeEscapeClause() throws SQLException { - try { - return databaseMetaData.supportsLikeEscapeClause(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsLikeEscapeClause); } @Override public boolean supportsLimitedOuterJoins() throws SQLException { - try { - return databaseMetaData.supportsLimitedOuterJoins(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsLimitedOuterJoins); } @Override public boolean supportsMinimumSQLGrammar() throws SQLException { - try { - return databaseMetaData.supportsMinimumSQLGrammar(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsMinimumSQLGrammar); } @Override public boolean supportsMixedCaseIdentifiers() throws SQLException { - try { - return databaseMetaData.supportsMixedCaseIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsMixedCaseIdentifiers); } @Override public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - try { - return databaseMetaData.supportsMixedCaseQuotedIdentifiers(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsMixedCaseQuotedIdentifiers); } @Override public boolean supportsMultipleOpenResults() throws SQLException { - try { - return databaseMetaData.supportsMultipleOpenResults(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsMultipleOpenResults); } @Override public boolean supportsMultipleResultSets() throws SQLException { - try { - return databaseMetaData.supportsMultipleResultSets(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsMultipleResultSets); } @Override public boolean supportsMultipleTransactions() throws SQLException { - try { - return databaseMetaData.supportsMultipleTransactions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsMultipleTransactions); } @Override public boolean supportsNamedParameters() throws SQLException { - try { - return databaseMetaData.supportsNamedParameters(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsNamedParameters); } @Override public boolean supportsNonNullableColumns() throws SQLException { - try { - return databaseMetaData.supportsNonNullableColumns(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsNonNullableColumns); } @Override public boolean supportsOpenCursorsAcrossCommit() throws SQLException { - try { - return databaseMetaData.supportsOpenCursorsAcrossCommit(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsOpenCursorsAcrossCommit); } @Override public boolean supportsOpenCursorsAcrossRollback() throws SQLException { - try { - return databaseMetaData.supportsOpenCursorsAcrossRollback(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsOpenCursorsAcrossRollback); } @Override public boolean supportsOpenStatementsAcrossCommit() throws SQLException { - try { - return databaseMetaData.supportsOpenStatementsAcrossCommit(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsOpenStatementsAcrossCommit); } @Override public boolean supportsOpenStatementsAcrossRollback() throws SQLException { - try { - return databaseMetaData.supportsOpenStatementsAcrossRollback(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsOpenStatementsAcrossRollback); } @Override public boolean supportsOrderByUnrelated() throws SQLException { - try { - return databaseMetaData.supportsOrderByUnrelated(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsOrderByUnrelated); } @Override public boolean supportsOuterJoins() throws SQLException { - try { - return databaseMetaData.supportsOuterJoins(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsOuterJoins); } @Override public boolean supportsPositionedDelete() throws SQLException { - try { - return databaseMetaData.supportsPositionedDelete(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsPositionedDelete); } @Override public boolean supportsPositionedUpdate() throws SQLException { - try { - return databaseMetaData.supportsPositionedUpdate(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsPositionedUpdate); } /** @@ -1673,232 +911,117 @@ public boolean supportsPositionedUpdate() throws SQLException { */ @Override public boolean supportsRefCursors() throws SQLException { - try { - return databaseMetaData.supportsRefCursors(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsRefCursors); } @Override public boolean supportsResultSetConcurrency(final int type, final int concurrency) throws SQLException { - try { - return databaseMetaData.supportsResultSetConcurrency(type, concurrency); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.supportsResultSetConcurrency(type, concurrency)); } @Override public boolean supportsResultSetHoldability(final int holdability) throws SQLException { - try { - return databaseMetaData.supportsResultSetHoldability(holdability); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.supportsResultSetHoldability(holdability)); } @Override public boolean supportsResultSetType(final int type) throws SQLException { - try { - return databaseMetaData.supportsResultSetType(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.supportsResultSetType(type)); } @Override public boolean supportsSavepoints() throws SQLException { - try { - return databaseMetaData.supportsSavepoints(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSavepoints); } @Override public boolean supportsSchemasInDataManipulation() throws SQLException { - try { - return databaseMetaData.supportsSchemasInDataManipulation(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSchemasInDataManipulation); } @Override public boolean supportsSchemasInIndexDefinitions() throws SQLException { - try { - return databaseMetaData.supportsSchemasInIndexDefinitions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSchemasInIndexDefinitions); } @Override public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - try { - return databaseMetaData.supportsSchemasInPrivilegeDefinitions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSchemasInPrivilegeDefinitions); } @Override public boolean supportsSchemasInProcedureCalls() throws SQLException { - try { - return databaseMetaData.supportsSchemasInProcedureCalls(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSchemasInProcedureCalls); } @Override public boolean supportsSchemasInTableDefinitions() throws SQLException { - try { - return databaseMetaData.supportsSchemasInTableDefinitions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSchemasInTableDefinitions); } @Override public boolean supportsSelectForUpdate() throws SQLException { - try { - return databaseMetaData.supportsSelectForUpdate(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSelectForUpdate); } @Override public boolean supportsStatementPooling() throws SQLException { - try { - return databaseMetaData.supportsStatementPooling(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsStatementPooling); } @Override public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - try { - return databaseMetaData.supportsStoredFunctionsUsingCallSyntax(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsStoredFunctionsUsingCallSyntax); } @Override public boolean supportsStoredProcedures() throws SQLException { - try { - return databaseMetaData.supportsStoredProcedures(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsStoredProcedures); } @Override public boolean supportsSubqueriesInComparisons() throws SQLException { - try { - return databaseMetaData.supportsSubqueriesInComparisons(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSubqueriesInComparisons); } @Override public boolean supportsSubqueriesInExists() throws SQLException { - try { - return databaseMetaData.supportsSubqueriesInExists(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSubqueriesInExists); } @Override public boolean supportsSubqueriesInIns() throws SQLException { - try { - return databaseMetaData.supportsSubqueriesInIns(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSubqueriesInIns); } @Override public boolean supportsSubqueriesInQuantifieds() throws SQLException { - try { - return databaseMetaData.supportsSubqueriesInQuantifieds(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsSubqueriesInQuantifieds); } @Override public boolean supportsTableCorrelationNames() throws SQLException { - try { - return databaseMetaData.supportsTableCorrelationNames(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsTableCorrelationNames); } @Override public boolean supportsTransactionIsolationLevel(final int level) throws SQLException { - try { - return databaseMetaData.supportsTransactionIsolationLevel(level); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.supportsTransactionIsolationLevel(level)); } @Override public boolean supportsTransactions() throws SQLException { - try { - return databaseMetaData.supportsTransactions(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsTransactions); } @Override public boolean supportsUnion() throws SQLException { - try { - return databaseMetaData.supportsUnion(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsUnion); } @Override public boolean supportsUnionAll() throws SQLException { - try { - return databaseMetaData.supportsUnionAll(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::supportsUnionAll); } @Override @@ -1914,31 +1037,16 @@ public T unwrap(final Class iface) throws SQLException { @Override public boolean updatesAreDetected(final int type) throws SQLException { - try { - return databaseMetaData.updatesAreDetected(type); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(() -> databaseMetaData.updatesAreDetected(type)); } @Override public boolean usesLocalFilePerTable() throws SQLException { - try { - return databaseMetaData.usesLocalFilePerTable(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::usesLocalFilePerTable); } @Override public boolean usesLocalFiles() throws SQLException { - try { - return databaseMetaData.usesLocalFiles(); - } catch (final SQLException e) { - handleException(e); - return false; - } + return getB(databaseMetaData::usesLocalFiles); } } diff --git a/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java b/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java index 05fed11441..4ede9de2ef 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java +++ b/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -32,6 +33,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; /** * Test suite for {@link DelegatingDatabaseMetaData}. @@ -41,6 +43,7 @@ public class TestDelegatingDatabaseMetaData { private TesterConnection testConn; private DelegatingConnection conn; private DelegatingDatabaseMetaData delegate; + private DelegatingDatabaseMetaData delegateSpy; private DatabaseMetaData obj; @BeforeEach @@ -49,30 +52,49 @@ public void setUp() throws Exception { testConn = new TesterConnection("test", "test"); conn = new DelegatingConnection<>(testConn); delegate = new DelegatingDatabaseMetaData(conn, obj); + delegateSpy = Mockito.spy(delegate); } @Test public void testAllProceduresAreCallable() throws Exception { try { delegate.allProceduresAreCallable(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).allProceduresAreCallable(); + // SQLException + Mockito.when(obj.allProceduresAreCallable()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::allProceduresAreCallable); } @Test public void testAllTablesAreSelectable() throws Exception { try { delegate.allTablesAreSelectable(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).allTablesAreSelectable(); + // SQLException + Mockito.when(obj.allTablesAreSelectable()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::allTablesAreSelectable); } @Test public void testAutoCommitFailureClosesAllResultSets() throws Exception { try { delegate.autoCommitFailureClosesAllResultSets(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).autoCommitFailureClosesAllResultSets(); + // SQLException + Mockito.when(obj.autoCommitFailureClosesAllResultSets()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::autoCommitFailureClosesAllResultSets); } @Test @@ -88,156 +110,242 @@ public void testCheckOpen() throws Exception { public void testDataDefinitionCausesTransactionCommit() throws Exception { try { delegate.dataDefinitionCausesTransactionCommit(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).dataDefinitionCausesTransactionCommit(); + // SQLException + Mockito.when(obj.dataDefinitionCausesTransactionCommit()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::dataDefinitionCausesTransactionCommit); } @Test public void testDataDefinitionIgnoredInTransactions() throws Exception { try { delegate.dataDefinitionIgnoredInTransactions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).dataDefinitionIgnoredInTransactions(); + // SQLException + Mockito.when(obj.dataDefinitionIgnoredInTransactions()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::dataDefinitionIgnoredInTransactions); } @Test public void testDeletesAreDetectedInteger() throws Exception { try { delegate.deletesAreDetected(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).deletesAreDetected(1); + // SQLException + Mockito.when(obj.deletesAreDetected(1)).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, () -> delegate.deletesAreDetected(1)); } @Test public void testDoesMaxRowSizeIncludeBlobs() throws Exception { try { delegate.doesMaxRowSizeIncludeBlobs(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).doesMaxRowSizeIncludeBlobs(); + // SQLException + Mockito.when(obj.doesMaxRowSizeIncludeBlobs()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::doesMaxRowSizeIncludeBlobs); } @Test public void testGeneratedKeyAlwaysReturned() throws Exception { try { delegate.generatedKeyAlwaysReturned(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).generatedKeyAlwaysReturned(); + // SQLException + Mockito.when(obj.generatedKeyAlwaysReturned()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::generatedKeyAlwaysReturned); } @Test public void testGetAttributesStringStringStringString() throws Exception { try { - delegate.getAttributes("foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getAttributes("foo","foo","foo","foo"); + delegate.getAttributes("foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getAttributes("foo", "foo", "foo", "foo"); } @Test public void testGetBestRowIdentifierStringStringStringIntegerBoolean() throws Exception { try { - delegate.getBestRowIdentifier("foo","foo","foo",1,Boolean.TRUE); - } catch (final SQLException e) {} - verify(obj, times(1)).getBestRowIdentifier("foo","foo","foo",1,Boolean.TRUE); + delegate.getBestRowIdentifier("foo", "foo", "foo", 1, Boolean.TRUE); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getBestRowIdentifier("foo", "foo", "foo", 1, Boolean.TRUE); } @Test public void testGetCatalogs() throws Exception { try { delegate.getCatalogs(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getCatalogs(); + // SQLException + Mockito.when(obj.getCatalogs()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getCatalogs); } @Test public void testGetCatalogSeparator() throws Exception { try { delegate.getCatalogSeparator(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getCatalogSeparator(); + // SQLException + Mockito.when(obj.getCatalogSeparator()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getCatalogSeparator); } @Test public void testGetCatalogTerm() throws Exception { try { delegate.getCatalogTerm(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getCatalogTerm(); + // SQLException + Mockito.when(obj.getCatalogTerm()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getCatalogTerm); } @Test public void testGetClientInfoProperties() throws Exception { try { delegate.getClientInfoProperties(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getClientInfoProperties(); + // SQLException + Mockito.when(obj.getClientInfoProperties()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getClientInfoProperties); } @Test public void testGetColumnPrivilegesStringStringStringString() throws Exception { try { - delegate.getColumnPrivileges("foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getColumnPrivileges("foo","foo","foo","foo"); + delegate.getColumnPrivileges("foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getColumnPrivileges("foo", "foo", "foo", "foo"); } @Test public void testGetColumnsStringStringStringString() throws Exception { try { - delegate.getColumns("foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getColumns("foo","foo","foo","foo"); + delegate.getColumns("foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getColumns("foo", "foo", "foo", "foo"); } /** - * This method is a bit special, and doesn't call the method on the wrapped object, - * instead returning the connection from the delegate object itself. + * This method is a bit special, and doesn't call the method on the wrapped object, instead returning the connection from the delegate object itself. + * * @throws Exception */ @Test public void testGetConnection() throws Exception { try { delegate.getConnection(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(0)).getConnection(); } @Test public void testGetCrossReferenceStringStringStringStringStringString() throws Exception { try { - delegate.getCrossReference("foo","foo","foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getCrossReference("foo","foo","foo","foo","foo","foo"); + delegate.getCrossReference("foo", "foo", "foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getCrossReference("foo", "foo", "foo", "foo", "foo", "foo"); } @Test public void testGetDatabaseMajorVersion() throws Exception { try { delegate.getDatabaseMajorVersion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDatabaseMajorVersion(); + // SQLException + Mockito.when(obj.getDatabaseMajorVersion()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getDatabaseMajorVersion); } @Test public void testGetDatabaseMinorVersion() throws Exception { try { delegate.getDatabaseMinorVersion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDatabaseMinorVersion(); + // SQLException + Mockito.when(obj.getDatabaseMinorVersion()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getDatabaseMinorVersion); } @Test public void testGetDatabaseProductName() throws Exception { try { delegate.getDatabaseProductName(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDatabaseProductName(); + // SQLException + Mockito.when(obj.getDatabaseProductName()).thenThrow(SQLException.class); + // The default handler rethrows + assertThrows(SQLException.class, delegate::getDatabaseProductName); } @Test public void testGetDatabaseProductVersion() throws Exception { try { delegate.getDatabaseProductVersion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDatabaseProductVersion(); } @@ -245,13 +353,15 @@ public void testGetDatabaseProductVersion() throws Exception { public void testGetDefaultTransactionIsolation() throws Exception { try { delegate.getDefaultTransactionIsolation(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDefaultTransactionIsolation(); } @Test public void testGetDelegate() throws Exception { - assertEquals(obj ,delegate.getDelegate()); + assertEquals(obj, delegate.getDelegate()); } @Test @@ -270,7 +380,9 @@ public void testGetDriverMinorVersion() throws Exception { public void testGetDriverName() throws Exception { try { delegate.getDriverName(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDriverName(); } @@ -278,71 +390,94 @@ public void testGetDriverName() throws Exception { public void testGetDriverVersion() throws Exception { try { delegate.getDriverVersion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getDriverVersion(); } @Test public void testGetExportedKeysStringStringString() throws Exception { try { - delegate.getExportedKeys("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getExportedKeys("foo","foo","foo"); + delegate.getExportedKeys("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getExportedKeys("foo", "foo", "foo"); } @Test public void testGetExtraNameCharacters() throws Exception { try { delegate.getExtraNameCharacters(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getExtraNameCharacters(); } @Test public void testGetFunctionColumnsStringStringStringString() throws Exception { try { - delegate.getFunctionColumns("foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getFunctionColumns("foo","foo","foo","foo"); + delegate.getFunctionColumns("foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getFunctionColumns("foo", "foo", "foo", "foo"); } @Test public void testGetFunctionsStringStringString() throws Exception { try { - delegate.getFunctions("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getFunctions("foo","foo","foo"); + delegate.getFunctions("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getFunctions("foo", "foo", "foo"); } @Test public void testGetIdentifierQuoteString() throws Exception { try { delegate.getIdentifierQuoteString(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getIdentifierQuoteString(); } @Test public void testGetImportedKeysStringStringString() throws Exception { try { - delegate.getImportedKeys("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getImportedKeys("foo","foo","foo"); + delegate.getImportedKeys("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getImportedKeys("foo", "foo", "foo"); } @Test public void testGetIndexInfoStringStringStringBooleanBoolean() throws Exception { try { - delegate.getIndexInfo("foo","foo","foo",Boolean.TRUE,Boolean.TRUE); - } catch (final SQLException e) {} - verify(obj, times(1)).getIndexInfo("foo","foo","foo",Boolean.TRUE,Boolean.TRUE); + delegate.getIndexInfo("foo", "foo", "foo", Boolean.TRUE, Boolean.TRUE); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getIndexInfo("foo", "foo", "foo", Boolean.TRUE, Boolean.TRUE); + } + + @Test + public void testGetInnermostDelegate() { + assertNotNull(delegate.getInnermostDelegate()); } @Test public void testGetJDBCMajorVersion() throws Exception { try { delegate.getJDBCMajorVersion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getJDBCMajorVersion(); } @@ -350,7 +485,9 @@ public void testGetJDBCMajorVersion() throws Exception { public void testGetJDBCMinorVersion() throws Exception { try { delegate.getJDBCMinorVersion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getJDBCMinorVersion(); } @@ -358,7 +495,9 @@ public void testGetJDBCMinorVersion() throws Exception { public void testGetMaxBinaryLiteralLength() throws Exception { try { delegate.getMaxBinaryLiteralLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxBinaryLiteralLength(); } @@ -366,7 +505,9 @@ public void testGetMaxBinaryLiteralLength() throws Exception { public void testGetMaxCatalogNameLength() throws Exception { try { delegate.getMaxCatalogNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxCatalogNameLength(); } @@ -374,7 +515,9 @@ public void testGetMaxCatalogNameLength() throws Exception { public void testGetMaxCharLiteralLength() throws Exception { try { delegate.getMaxCharLiteralLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxCharLiteralLength(); } @@ -382,7 +525,9 @@ public void testGetMaxCharLiteralLength() throws Exception { public void testGetMaxColumnNameLength() throws Exception { try { delegate.getMaxColumnNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxColumnNameLength(); } @@ -390,7 +535,9 @@ public void testGetMaxColumnNameLength() throws Exception { public void testGetMaxColumnsInGroupBy() throws Exception { try { delegate.getMaxColumnsInGroupBy(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxColumnsInGroupBy(); } @@ -398,7 +545,9 @@ public void testGetMaxColumnsInGroupBy() throws Exception { public void testGetMaxColumnsInIndex() throws Exception { try { delegate.getMaxColumnsInIndex(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxColumnsInIndex(); } @@ -406,7 +555,9 @@ public void testGetMaxColumnsInIndex() throws Exception { public void testGetMaxColumnsInOrderBy() throws Exception { try { delegate.getMaxColumnsInOrderBy(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxColumnsInOrderBy(); } @@ -414,7 +565,9 @@ public void testGetMaxColumnsInOrderBy() throws Exception { public void testGetMaxColumnsInSelect() throws Exception { try { delegate.getMaxColumnsInSelect(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxColumnsInSelect(); } @@ -422,7 +575,9 @@ public void testGetMaxColumnsInSelect() throws Exception { public void testGetMaxColumnsInTable() throws Exception { try { delegate.getMaxColumnsInTable(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxColumnsInTable(); } @@ -430,7 +585,9 @@ public void testGetMaxColumnsInTable() throws Exception { public void testGetMaxConnections() throws Exception { try { delegate.getMaxConnections(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxConnections(); } @@ -438,7 +595,9 @@ public void testGetMaxConnections() throws Exception { public void testGetMaxCursorNameLength() throws Exception { try { delegate.getMaxCursorNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxCursorNameLength(); } @@ -446,7 +605,9 @@ public void testGetMaxCursorNameLength() throws Exception { public void testGetMaxIndexLength() throws Exception { try { delegate.getMaxIndexLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxIndexLength(); } @@ -454,7 +615,9 @@ public void testGetMaxIndexLength() throws Exception { public void testGetMaxLogicalLobSize() throws Exception { try { delegate.getMaxLogicalLobSize(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxLogicalLobSize(); } @@ -462,7 +625,9 @@ public void testGetMaxLogicalLobSize() throws Exception { public void testGetMaxProcedureNameLength() throws Exception { try { delegate.getMaxProcedureNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxProcedureNameLength(); } @@ -470,7 +635,9 @@ public void testGetMaxProcedureNameLength() throws Exception { public void testGetMaxRowSize() throws Exception { try { delegate.getMaxRowSize(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxRowSize(); } @@ -478,7 +645,9 @@ public void testGetMaxRowSize() throws Exception { public void testGetMaxSchemaNameLength() throws Exception { try { delegate.getMaxSchemaNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxSchemaNameLength(); } @@ -486,7 +655,9 @@ public void testGetMaxSchemaNameLength() throws Exception { public void testGetMaxStatementLength() throws Exception { try { delegate.getMaxStatementLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxStatementLength(); } @@ -494,7 +665,9 @@ public void testGetMaxStatementLength() throws Exception { public void testGetMaxStatements() throws Exception { try { delegate.getMaxStatements(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxStatements(); } @@ -502,7 +675,9 @@ public void testGetMaxStatements() throws Exception { public void testGetMaxTableNameLength() throws Exception { try { delegate.getMaxTableNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxTableNameLength(); } @@ -510,7 +685,9 @@ public void testGetMaxTableNameLength() throws Exception { public void testGetMaxTablesInSelect() throws Exception { try { delegate.getMaxTablesInSelect(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxTablesInSelect(); } @@ -518,7 +695,9 @@ public void testGetMaxTablesInSelect() throws Exception { public void testGetMaxUserNameLength() throws Exception { try { delegate.getMaxUserNameLength(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getMaxUserNameLength(); } @@ -526,55 +705,69 @@ public void testGetMaxUserNameLength() throws Exception { public void testGetNumericFunctions() throws Exception { try { delegate.getNumericFunctions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getNumericFunctions(); } @Test public void testGetPrimaryKeysStringStringString() throws Exception { try { - delegate.getPrimaryKeys("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getPrimaryKeys("foo","foo","foo"); + delegate.getPrimaryKeys("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getPrimaryKeys("foo", "foo", "foo"); } @Test public void testGetProcedureColumnsStringStringStringString() throws Exception { try { - delegate.getProcedureColumns("foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getProcedureColumns("foo","foo","foo","foo"); + delegate.getProcedureColumns("foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getProcedureColumns("foo", "foo", "foo", "foo"); } @Test public void testGetProceduresStringStringString() throws Exception { try { - delegate.getProcedures("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getProcedures("foo","foo","foo"); + delegate.getProcedures("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getProcedures("foo", "foo", "foo"); } @Test public void testGetProcedureTerm() throws Exception { try { delegate.getProcedureTerm(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getProcedureTerm(); } @Test public void testGetPseudoColumnsStringStringStringString() throws Exception { try { - delegate.getPseudoColumns("foo","foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getPseudoColumns("foo","foo","foo","foo"); + delegate.getPseudoColumns("foo", "foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getPseudoColumns("foo", "foo", "foo", "foo"); } @Test public void testGetResultSetHoldability() throws Exception { try { delegate.getResultSetHoldability(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getResultSetHoldability(); } @@ -582,7 +775,9 @@ public void testGetResultSetHoldability() throws Exception { public void testGetRowIdLifetime() throws Exception { try { delegate.getRowIdLifetime(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getRowIdLifetime(); } @@ -590,23 +785,29 @@ public void testGetRowIdLifetime() throws Exception { public void testGetSchemas() throws Exception { try { delegate.getSchemas(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getSchemas(); } @Test public void testGetSchemasStringString() throws Exception { try { - delegate.getSchemas("foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getSchemas("foo","foo"); + delegate.getSchemas("foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getSchemas("foo", "foo"); } @Test public void testGetSchemaTerm() throws Exception { try { delegate.getSchemaTerm(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getSchemaTerm(); } @@ -614,7 +815,9 @@ public void testGetSchemaTerm() throws Exception { public void testGetSearchStringEscape() throws Exception { try { delegate.getSearchStringEscape(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getSearchStringEscape(); } @@ -622,7 +825,9 @@ public void testGetSearchStringEscape() throws Exception { public void testGetSQLKeywords() throws Exception { try { delegate.getSQLKeywords(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getSQLKeywords(); } @@ -630,7 +835,9 @@ public void testGetSQLKeywords() throws Exception { public void testGetSQLStateType() throws Exception { try { delegate.getSQLStateType(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getSQLStateType(); } @@ -638,55 +845,69 @@ public void testGetSQLStateType() throws Exception { public void testGetStringFunctions() throws Exception { try { delegate.getStringFunctions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getStringFunctions(); } @Test public void testGetSuperTablesStringStringString() throws Exception { try { - delegate.getSuperTables("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getSuperTables("foo","foo","foo"); + delegate.getSuperTables("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getSuperTables("foo", "foo", "foo"); } @Test public void testGetSuperTypesStringStringString() throws Exception { try { - delegate.getSuperTypes("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getSuperTypes("foo","foo","foo"); + delegate.getSuperTypes("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getSuperTypes("foo", "foo", "foo"); } @Test public void testGetSystemFunctions() throws Exception { try { delegate.getSystemFunctions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getSystemFunctions(); } @Test public void testGetTablePrivilegesStringStringString() throws Exception { try { - delegate.getTablePrivileges("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getTablePrivileges("foo","foo","foo"); + delegate.getTablePrivileges("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getTablePrivileges("foo", "foo", "foo"); } @Test public void testGetTablesStringStringStringStringArray() throws Exception { try { - delegate.getTables("foo","foo","foo",(String[]) null); - } catch (final SQLException e) {} - verify(obj, times(1)).getTables("foo","foo","foo",(String[]) null); + delegate.getTables("foo", "foo", "foo", (String[]) null); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getTables("foo", "foo", "foo", (String[]) null); } @Test public void testGetTableTypes() throws Exception { try { delegate.getTableTypes(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getTableTypes(); } @@ -694,7 +915,9 @@ public void testGetTableTypes() throws Exception { public void testGetTimeDateFunctions() throws Exception { try { delegate.getTimeDateFunctions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getTimeDateFunctions(); } @@ -702,23 +925,29 @@ public void testGetTimeDateFunctions() throws Exception { public void testGetTypeInfo() throws Exception { try { delegate.getTypeInfo(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getTypeInfo(); } @Test public void testGetUDTsStringStringStringIntegerArray() throws Exception { try { - delegate.getUDTs("foo","foo","foo",(int[]) null); - } catch (final SQLException e) {} - verify(obj, times(1)).getUDTs("foo","foo","foo",(int[]) null); + delegate.getUDTs("foo", "foo", "foo", (int[]) null); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getUDTs("foo", "foo", "foo", (int[]) null); } @Test public void testGetURL() throws Exception { try { delegate.getURL(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getURL(); } @@ -726,23 +955,29 @@ public void testGetURL() throws Exception { public void testGetUserName() throws Exception { try { delegate.getUserName(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).getUserName(); } @Test public void testGetVersionColumnsStringStringString() throws Exception { try { - delegate.getVersionColumns("foo","foo","foo"); - } catch (final SQLException e) {} - verify(obj, times(1)).getVersionColumns("foo","foo","foo"); + delegate.getVersionColumns("foo", "foo", "foo"); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).getVersionColumns("foo", "foo", "foo"); } @Test public void testInsertsAreDetectedInteger() throws Exception { try { delegate.insertsAreDetected(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).insertsAreDetected(1); } @@ -750,7 +985,9 @@ public void testInsertsAreDetectedInteger() throws Exception { public void testIsCatalogAtStart() throws Exception { try { delegate.isCatalogAtStart(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).isCatalogAtStart(); } @@ -758,7 +995,9 @@ public void testIsCatalogAtStart() throws Exception { public void testIsReadOnly() throws Exception { try { delegate.isReadOnly(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).isReadOnly(); } @@ -766,7 +1005,9 @@ public void testIsReadOnly() throws Exception { public void testLocatorsUpdateCopy() throws Exception { try { delegate.locatorsUpdateCopy(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).locatorsUpdateCopy(); } @@ -780,7 +1021,9 @@ public void testNullArguments() throws Exception { public void testNullPlusNonNullIsNull() throws Exception { try { delegate.nullPlusNonNullIsNull(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).nullPlusNonNullIsNull(); } @@ -788,7 +1031,9 @@ public void testNullPlusNonNullIsNull() throws Exception { public void testNullsAreSortedAtEnd() throws Exception { try { delegate.nullsAreSortedAtEnd(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).nullsAreSortedAtEnd(); } @@ -796,7 +1041,9 @@ public void testNullsAreSortedAtEnd() throws Exception { public void testNullsAreSortedAtStart() throws Exception { try { delegate.nullsAreSortedAtStart(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).nullsAreSortedAtStart(); } @@ -804,7 +1051,9 @@ public void testNullsAreSortedAtStart() throws Exception { public void testNullsAreSortedHigh() throws Exception { try { delegate.nullsAreSortedHigh(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).nullsAreSortedHigh(); } @@ -812,7 +1061,9 @@ public void testNullsAreSortedHigh() throws Exception { public void testNullsAreSortedLow() throws Exception { try { delegate.nullsAreSortedLow(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).nullsAreSortedLow(); } @@ -820,7 +1071,9 @@ public void testNullsAreSortedLow() throws Exception { public void testOthersDeletesAreVisibleInteger() throws Exception { try { delegate.othersDeletesAreVisible(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).othersDeletesAreVisible(1); } @@ -828,7 +1081,9 @@ public void testOthersDeletesAreVisibleInteger() throws Exception { public void testOthersInsertsAreVisibleInteger() throws Exception { try { delegate.othersInsertsAreVisible(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).othersInsertsAreVisible(1); } @@ -836,7 +1091,9 @@ public void testOthersInsertsAreVisibleInteger() throws Exception { public void testOthersUpdatesAreVisibleInteger() throws Exception { try { delegate.othersUpdatesAreVisible(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).othersUpdatesAreVisible(1); } @@ -844,7 +1101,9 @@ public void testOthersUpdatesAreVisibleInteger() throws Exception { public void testOwnDeletesAreVisibleInteger() throws Exception { try { delegate.ownDeletesAreVisible(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).ownDeletesAreVisible(1); } @@ -852,7 +1111,9 @@ public void testOwnDeletesAreVisibleInteger() throws Exception { public void testOwnInsertsAreVisibleInteger() throws Exception { try { delegate.ownInsertsAreVisible(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).ownInsertsAreVisible(1); } @@ -860,7 +1121,9 @@ public void testOwnInsertsAreVisibleInteger() throws Exception { public void testOwnUpdatesAreVisibleInteger() throws Exception { try { delegate.ownUpdatesAreVisible(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).ownUpdatesAreVisible(1); } @@ -868,7 +1131,9 @@ public void testOwnUpdatesAreVisibleInteger() throws Exception { public void testStoresLowerCaseIdentifiers() throws Exception { try { delegate.storesLowerCaseIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).storesLowerCaseIdentifiers(); } @@ -876,7 +1141,9 @@ public void testStoresLowerCaseIdentifiers() throws Exception { public void testStoresLowerCaseQuotedIdentifiers() throws Exception { try { delegate.storesLowerCaseQuotedIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).storesLowerCaseQuotedIdentifiers(); } @@ -884,7 +1151,9 @@ public void testStoresLowerCaseQuotedIdentifiers() throws Exception { public void testStoresMixedCaseIdentifiers() throws Exception { try { delegate.storesMixedCaseIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).storesMixedCaseIdentifiers(); } @@ -892,7 +1161,9 @@ public void testStoresMixedCaseIdentifiers() throws Exception { public void testStoresMixedCaseQuotedIdentifiers() throws Exception { try { delegate.storesMixedCaseQuotedIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).storesMixedCaseQuotedIdentifiers(); } @@ -900,7 +1171,9 @@ public void testStoresMixedCaseQuotedIdentifiers() throws Exception { public void testStoresUpperCaseIdentifiers() throws Exception { try { delegate.storesUpperCaseIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).storesUpperCaseIdentifiers(); } @@ -908,7 +1181,9 @@ public void testStoresUpperCaseIdentifiers() throws Exception { public void testStoresUpperCaseQuotedIdentifiers() throws Exception { try { delegate.storesUpperCaseQuotedIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).storesUpperCaseQuotedIdentifiers(); } @@ -916,7 +1191,9 @@ public void testStoresUpperCaseQuotedIdentifiers() throws Exception { public void testSupportsAlterTableWithAddColumn() throws Exception { try { delegate.supportsAlterTableWithAddColumn(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsAlterTableWithAddColumn(); } @@ -924,7 +1201,9 @@ public void testSupportsAlterTableWithAddColumn() throws Exception { public void testSupportsAlterTableWithDropColumn() throws Exception { try { delegate.supportsAlterTableWithDropColumn(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsAlterTableWithDropColumn(); } @@ -932,7 +1211,9 @@ public void testSupportsAlterTableWithDropColumn() throws Exception { public void testSupportsANSI92EntryLevelSQL() throws Exception { try { delegate.supportsANSI92EntryLevelSQL(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsANSI92EntryLevelSQL(); } @@ -940,7 +1221,9 @@ public void testSupportsANSI92EntryLevelSQL() throws Exception { public void testSupportsANSI92FullSQL() throws Exception { try { delegate.supportsANSI92FullSQL(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsANSI92FullSQL(); } @@ -948,7 +1231,9 @@ public void testSupportsANSI92FullSQL() throws Exception { public void testSupportsANSI92IntermediateSQL() throws Exception { try { delegate.supportsANSI92IntermediateSQL(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsANSI92IntermediateSQL(); } @@ -956,7 +1241,9 @@ public void testSupportsANSI92IntermediateSQL() throws Exception { public void testSupportsBatchUpdates() throws Exception { try { delegate.supportsBatchUpdates(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsBatchUpdates(); } @@ -964,7 +1251,9 @@ public void testSupportsBatchUpdates() throws Exception { public void testSupportsCatalogsInDataManipulation() throws Exception { try { delegate.supportsCatalogsInDataManipulation(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCatalogsInDataManipulation(); } @@ -972,7 +1261,9 @@ public void testSupportsCatalogsInDataManipulation() throws Exception { public void testSupportsCatalogsInIndexDefinitions() throws Exception { try { delegate.supportsCatalogsInIndexDefinitions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCatalogsInIndexDefinitions(); } @@ -980,7 +1271,9 @@ public void testSupportsCatalogsInIndexDefinitions() throws Exception { public void testSupportsCatalogsInPrivilegeDefinitions() throws Exception { try { delegate.supportsCatalogsInPrivilegeDefinitions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCatalogsInPrivilegeDefinitions(); } @@ -988,7 +1281,9 @@ public void testSupportsCatalogsInPrivilegeDefinitions() throws Exception { public void testSupportsCatalogsInProcedureCalls() throws Exception { try { delegate.supportsCatalogsInProcedureCalls(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCatalogsInProcedureCalls(); } @@ -996,7 +1291,9 @@ public void testSupportsCatalogsInProcedureCalls() throws Exception { public void testSupportsCatalogsInTableDefinitions() throws Exception { try { delegate.supportsCatalogsInTableDefinitions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCatalogsInTableDefinitions(); } @@ -1004,7 +1301,9 @@ public void testSupportsCatalogsInTableDefinitions() throws Exception { public void testSupportsColumnAliasing() throws Exception { try { delegate.supportsColumnAliasing(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsColumnAliasing(); } @@ -1012,23 +1311,29 @@ public void testSupportsColumnAliasing() throws Exception { public void testSupportsConvert() throws Exception { try { delegate.supportsConvert(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsConvert(); } @Test public void testSupportsConvertIntegerInteger() throws Exception { try { - delegate.supportsConvert(1,1); - } catch (final SQLException e) {} - verify(obj, times(1)).supportsConvert(1,1); + delegate.supportsConvert(1, 1); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).supportsConvert(1, 1); } @Test public void testSupportsCoreSQLGrammar() throws Exception { try { delegate.supportsCoreSQLGrammar(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCoreSQLGrammar(); } @@ -1036,7 +1341,9 @@ public void testSupportsCoreSQLGrammar() throws Exception { public void testSupportsCorrelatedSubqueries() throws Exception { try { delegate.supportsCorrelatedSubqueries(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsCorrelatedSubqueries(); } @@ -1044,7 +1351,9 @@ public void testSupportsCorrelatedSubqueries() throws Exception { public void testSupportsDataDefinitionAndDataManipulationTransactions() throws Exception { try { delegate.supportsDataDefinitionAndDataManipulationTransactions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsDataDefinitionAndDataManipulationTransactions(); } @@ -1052,7 +1361,9 @@ public void testSupportsDataDefinitionAndDataManipulationTransactions() throws E public void testSupportsDataManipulationTransactionsOnly() throws Exception { try { delegate.supportsDataManipulationTransactionsOnly(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsDataManipulationTransactionsOnly(); } @@ -1060,7 +1371,9 @@ public void testSupportsDataManipulationTransactionsOnly() throws Exception { public void testSupportsDifferentTableCorrelationNames() throws Exception { try { delegate.supportsDifferentTableCorrelationNames(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsDifferentTableCorrelationNames(); } @@ -1068,7 +1381,9 @@ public void testSupportsDifferentTableCorrelationNames() throws Exception { public void testSupportsExpressionsInOrderBy() throws Exception { try { delegate.supportsExpressionsInOrderBy(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsExpressionsInOrderBy(); } @@ -1076,7 +1391,9 @@ public void testSupportsExpressionsInOrderBy() throws Exception { public void testSupportsExtendedSQLGrammar() throws Exception { try { delegate.supportsExtendedSQLGrammar(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsExtendedSQLGrammar(); } @@ -1084,7 +1401,9 @@ public void testSupportsExtendedSQLGrammar() throws Exception { public void testSupportsFullOuterJoins() throws Exception { try { delegate.supportsFullOuterJoins(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsFullOuterJoins(); } @@ -1092,7 +1411,9 @@ public void testSupportsFullOuterJoins() throws Exception { public void testSupportsGetGeneratedKeys() throws Exception { try { delegate.supportsGetGeneratedKeys(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsGetGeneratedKeys(); } @@ -1100,7 +1421,9 @@ public void testSupportsGetGeneratedKeys() throws Exception { public void testSupportsGroupBy() throws Exception { try { delegate.supportsGroupBy(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsGroupBy(); } @@ -1108,7 +1431,9 @@ public void testSupportsGroupBy() throws Exception { public void testSupportsGroupByBeyondSelect() throws Exception { try { delegate.supportsGroupByBeyondSelect(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsGroupByBeyondSelect(); } @@ -1116,7 +1441,9 @@ public void testSupportsGroupByBeyondSelect() throws Exception { public void testSupportsGroupByUnrelated() throws Exception { try { delegate.supportsGroupByUnrelated(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsGroupByUnrelated(); } @@ -1124,7 +1451,9 @@ public void testSupportsGroupByUnrelated() throws Exception { public void testSupportsIntegrityEnhancementFacility() throws Exception { try { delegate.supportsIntegrityEnhancementFacility(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsIntegrityEnhancementFacility(); } @@ -1132,7 +1461,9 @@ public void testSupportsIntegrityEnhancementFacility() throws Exception { public void testSupportsLikeEscapeClause() throws Exception { try { delegate.supportsLikeEscapeClause(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsLikeEscapeClause(); } @@ -1140,7 +1471,9 @@ public void testSupportsLikeEscapeClause() throws Exception { public void testSupportsLimitedOuterJoins() throws Exception { try { delegate.supportsLimitedOuterJoins(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsLimitedOuterJoins(); } @@ -1148,7 +1481,9 @@ public void testSupportsLimitedOuterJoins() throws Exception { public void testSupportsMinimumSQLGrammar() throws Exception { try { delegate.supportsMinimumSQLGrammar(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsMinimumSQLGrammar(); } @@ -1156,7 +1491,9 @@ public void testSupportsMinimumSQLGrammar() throws Exception { public void testSupportsMixedCaseIdentifiers() throws Exception { try { delegate.supportsMixedCaseIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsMixedCaseIdentifiers(); } @@ -1164,7 +1501,9 @@ public void testSupportsMixedCaseIdentifiers() throws Exception { public void testSupportsMixedCaseQuotedIdentifiers() throws Exception { try { delegate.supportsMixedCaseQuotedIdentifiers(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsMixedCaseQuotedIdentifiers(); } @@ -1172,7 +1511,9 @@ public void testSupportsMixedCaseQuotedIdentifiers() throws Exception { public void testSupportsMultipleOpenResults() throws Exception { try { delegate.supportsMultipleOpenResults(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsMultipleOpenResults(); } @@ -1180,7 +1521,9 @@ public void testSupportsMultipleOpenResults() throws Exception { public void testSupportsMultipleResultSets() throws Exception { try { delegate.supportsMultipleResultSets(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsMultipleResultSets(); } @@ -1188,7 +1531,9 @@ public void testSupportsMultipleResultSets() throws Exception { public void testSupportsMultipleTransactions() throws Exception { try { delegate.supportsMultipleTransactions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsMultipleTransactions(); } @@ -1196,7 +1541,9 @@ public void testSupportsMultipleTransactions() throws Exception { public void testSupportsNamedParameters() throws Exception { try { delegate.supportsNamedParameters(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsNamedParameters(); } @@ -1204,7 +1551,9 @@ public void testSupportsNamedParameters() throws Exception { public void testSupportsNonNullableColumns() throws Exception { try { delegate.supportsNonNullableColumns(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsNonNullableColumns(); } @@ -1212,7 +1561,9 @@ public void testSupportsNonNullableColumns() throws Exception { public void testSupportsOpenCursorsAcrossCommit() throws Exception { try { delegate.supportsOpenCursorsAcrossCommit(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsOpenCursorsAcrossCommit(); } @@ -1220,7 +1571,9 @@ public void testSupportsOpenCursorsAcrossCommit() throws Exception { public void testSupportsOpenCursorsAcrossRollback() throws Exception { try { delegate.supportsOpenCursorsAcrossRollback(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsOpenCursorsAcrossRollback(); } @@ -1228,7 +1581,9 @@ public void testSupportsOpenCursorsAcrossRollback() throws Exception { public void testSupportsOpenStatementsAcrossCommit() throws Exception { try { delegate.supportsOpenStatementsAcrossCommit(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsOpenStatementsAcrossCommit(); } @@ -1236,7 +1591,9 @@ public void testSupportsOpenStatementsAcrossCommit() throws Exception { public void testSupportsOpenStatementsAcrossRollback() throws Exception { try { delegate.supportsOpenStatementsAcrossRollback(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsOpenStatementsAcrossRollback(); } @@ -1244,7 +1601,9 @@ public void testSupportsOpenStatementsAcrossRollback() throws Exception { public void testSupportsOrderByUnrelated() throws Exception { try { delegate.supportsOrderByUnrelated(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsOrderByUnrelated(); } @@ -1252,7 +1611,9 @@ public void testSupportsOrderByUnrelated() throws Exception { public void testSupportsOuterJoins() throws Exception { try { delegate.supportsOuterJoins(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsOuterJoins(); } @@ -1260,7 +1621,9 @@ public void testSupportsOuterJoins() throws Exception { public void testSupportsPositionedDelete() throws Exception { try { delegate.supportsPositionedDelete(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsPositionedDelete(); } @@ -1268,7 +1631,9 @@ public void testSupportsPositionedDelete() throws Exception { public void testSupportsPositionedUpdate() throws Exception { try { delegate.supportsPositionedUpdate(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsPositionedUpdate(); } @@ -1276,23 +1641,29 @@ public void testSupportsPositionedUpdate() throws Exception { public void testSupportsRefCursors() throws Exception { try { delegate.supportsRefCursors(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsRefCursors(); } @Test public void testSupportsResultSetConcurrencyIntegerInteger() throws Exception { try { - delegate.supportsResultSetConcurrency(1,1); - } catch (final SQLException e) {} - verify(obj, times(1)).supportsResultSetConcurrency(1,1); + delegate.supportsResultSetConcurrency(1, 1); + } catch (final SQLException e) { + // ignore + } + verify(obj, times(1)).supportsResultSetConcurrency(1, 1); } @Test public void testSupportsResultSetHoldabilityInteger() throws Exception { try { delegate.supportsResultSetHoldability(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsResultSetHoldability(1); } @@ -1300,7 +1671,9 @@ public void testSupportsResultSetHoldabilityInteger() throws Exception { public void testSupportsResultSetTypeInteger() throws Exception { try { delegate.supportsResultSetType(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsResultSetType(1); } @@ -1308,7 +1681,9 @@ public void testSupportsResultSetTypeInteger() throws Exception { public void testSupportsSavepoints() throws Exception { try { delegate.supportsSavepoints(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSavepoints(); } @@ -1316,7 +1691,9 @@ public void testSupportsSavepoints() throws Exception { public void testSupportsSchemasInDataManipulation() throws Exception { try { delegate.supportsSchemasInDataManipulation(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSchemasInDataManipulation(); } @@ -1324,7 +1701,9 @@ public void testSupportsSchemasInDataManipulation() throws Exception { public void testSupportsSchemasInIndexDefinitions() throws Exception { try { delegate.supportsSchemasInIndexDefinitions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSchemasInIndexDefinitions(); } @@ -1332,7 +1711,9 @@ public void testSupportsSchemasInIndexDefinitions() throws Exception { public void testSupportsSchemasInPrivilegeDefinitions() throws Exception { try { delegate.supportsSchemasInPrivilegeDefinitions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSchemasInPrivilegeDefinitions(); } @@ -1340,7 +1721,9 @@ public void testSupportsSchemasInPrivilegeDefinitions() throws Exception { public void testSupportsSchemasInProcedureCalls() throws Exception { try { delegate.supportsSchemasInProcedureCalls(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSchemasInProcedureCalls(); } @@ -1348,7 +1731,9 @@ public void testSupportsSchemasInProcedureCalls() throws Exception { public void testSupportsSchemasInTableDefinitions() throws Exception { try { delegate.supportsSchemasInTableDefinitions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSchemasInTableDefinitions(); } @@ -1356,7 +1741,9 @@ public void testSupportsSchemasInTableDefinitions() throws Exception { public void testSupportsSelectForUpdate() throws Exception { try { delegate.supportsSelectForUpdate(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSelectForUpdate(); } @@ -1364,7 +1751,9 @@ public void testSupportsSelectForUpdate() throws Exception { public void testSupportsStatementPooling() throws Exception { try { delegate.supportsStatementPooling(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsStatementPooling(); } @@ -1372,7 +1761,9 @@ public void testSupportsStatementPooling() throws Exception { public void testSupportsStoredFunctionsUsingCallSyntax() throws Exception { try { delegate.supportsStoredFunctionsUsingCallSyntax(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsStoredFunctionsUsingCallSyntax(); } @@ -1380,7 +1771,9 @@ public void testSupportsStoredFunctionsUsingCallSyntax() throws Exception { public void testSupportsStoredProcedures() throws Exception { try { delegate.supportsStoredProcedures(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsStoredProcedures(); } @@ -1388,7 +1781,9 @@ public void testSupportsStoredProcedures() throws Exception { public void testSupportsSubqueriesInComparisons() throws Exception { try { delegate.supportsSubqueriesInComparisons(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSubqueriesInComparisons(); } @@ -1396,7 +1791,9 @@ public void testSupportsSubqueriesInComparisons() throws Exception { public void testSupportsSubqueriesInExists() throws Exception { try { delegate.supportsSubqueriesInExists(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSubqueriesInExists(); } @@ -1404,7 +1801,9 @@ public void testSupportsSubqueriesInExists() throws Exception { public void testSupportsSubqueriesInIns() throws Exception { try { delegate.supportsSubqueriesInIns(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSubqueriesInIns(); } @@ -1412,7 +1811,9 @@ public void testSupportsSubqueriesInIns() throws Exception { public void testSupportsSubqueriesInQuantifieds() throws Exception { try { delegate.supportsSubqueriesInQuantifieds(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsSubqueriesInQuantifieds(); } @@ -1420,7 +1821,9 @@ public void testSupportsSubqueriesInQuantifieds() throws Exception { public void testSupportsTableCorrelationNames() throws Exception { try { delegate.supportsTableCorrelationNames(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsTableCorrelationNames(); } @@ -1428,7 +1831,9 @@ public void testSupportsTableCorrelationNames() throws Exception { public void testSupportsTransactionIsolationLevelInteger() throws Exception { try { delegate.supportsTransactionIsolationLevel(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsTransactionIsolationLevel(1); } @@ -1436,7 +1841,9 @@ public void testSupportsTransactionIsolationLevelInteger() throws Exception { public void testSupportsTransactions() throws Exception { try { delegate.supportsTransactions(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsTransactions(); } @@ -1444,7 +1851,9 @@ public void testSupportsTransactions() throws Exception { public void testSupportsUnion() throws Exception { try { delegate.supportsUnion(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsUnion(); } @@ -1452,7 +1861,9 @@ public void testSupportsUnion() throws Exception { public void testSupportsUnionAll() throws Exception { try { delegate.supportsUnionAll(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).supportsUnionAll(); } @@ -1460,7 +1871,9 @@ public void testSupportsUnionAll() throws Exception { public void testUpdatesAreDetectedInteger() throws Exception { try { delegate.updatesAreDetected(1); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).updatesAreDetected(1); } @@ -1468,7 +1881,9 @@ public void testUpdatesAreDetectedInteger() throws Exception { public void testUsesLocalFilePerTable() throws Exception { try { delegate.usesLocalFilePerTable(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).usesLocalFilePerTable(); } @@ -1476,7 +1891,9 @@ public void testUsesLocalFilePerTable() throws Exception { public void testUsesLocalFiles() throws Exception { try { delegate.usesLocalFiles(); - } catch (final SQLException e) {} + } catch (final SQLException e) { + // ignore + } verify(obj, times(1)).usesLocalFiles(); } From 0ae9acca205524f0119671c1a1b2a983b1bfd511 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 15:19:34 -0500 Subject: [PATCH 161/169] Raise the bar for JaCoCo checks --- pom.xml | 7 ++++--- src/changes/changes.xml | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d1fcf22b6c..1959f0de22 100644 --- a/pom.xml +++ b/pom.xml @@ -196,12 +196,13 @@ true + 0.98 - 0.68 - 0.87 + 0.74 + 0.89 0.66 0.62 - 0.76 + 0.79
    clean verify apache-rat:check japicmp:cmp checkstyle:check spotbugs:check pmd:check pmd:cpd-check javadoc:javadoc diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7e87d3d690..b562293cb7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -79,6 +79,7 @@ The type attribute can be add,update,fix,remove. Add support for ignoring non-fatal SQL state codes #421. Add @FunctionalInterface to SwallowedExceptionListener. Add missing Javadoc comments and descriptions. + Add tests, raise the bar for JaCoCo checks. Bump org.apache.commons:commons-parent from 66 to 78 #360, #371, #395, #420, #426, #436, #441, #449. Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. From 5cf904c9538bfb8059f40788a8e6a78d3d6815c0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 15:19:47 -0500 Subject: [PATCH 162/169] Javadoc --- .../commons/dbcp2/datasources/PerUserPoolDataSource.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 0901c81e67..f89fb44359 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -240,7 +240,7 @@ protected PooledConnectionManager getConnectionManager(final UserPassKey upKey) } /** - * Gets the underlying pool but does NOT allocate it. + * Gets the underlying pre-allocated pool (does NOT allocate). * * @param manager A CPDSConnectionFactory. * @return the underlying pool. @@ -583,8 +583,7 @@ private ObjectPool getPool(final PoolKey poolKey) { } @Override - protected PooledConnectionAndInfo getPooledConnectionAndInfo(final String userName, final String password) - throws SQLException { + protected PooledConnectionAndInfo getPooledConnectionAndInfo(final String userName, final String password) throws SQLException { final PoolKey key = getPoolKey(userName); ObjectPool pool; PooledConnectionManager manager; @@ -600,7 +599,6 @@ protected PooledConnectionAndInfo getPooledConnectionAndInfo(final String userNa } pool = getCPDSConnectionFactoryPool(manager); } - PooledConnectionAndInfo info = null; try { info = pool.borrowObject(); From 35c72f62371631637f077aa6f3c16ea7110ee345 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 15:21:07 -0500 Subject: [PATCH 163/169] Add and document @SuppressWarnings --- .../apache/commons/dbcp2/datasources/PerUserPoolDataSource.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index f89fb44359..95194c2a7e 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -176,6 +176,7 @@ public PerUserPoolDataSource() { * @see org.apache.commons.pool2.ObjectPool#clear() * @since 2.3.0 */ + @SuppressWarnings("resource") // does not allocate a pool public void clear() { managers.values().forEach(manager -> { try { @@ -582,6 +583,7 @@ private ObjectPool getPool(final PoolKey poolKey) { return mgr == null ? null : mgr.getPool(); } + @SuppressWarnings("resource") // does not allocate a pool @Override protected PooledConnectionAndInfo getPooledConnectionAndInfo(final String userName, final String password) throws SQLException { final PoolKey key = getPoolKey(userName); From c7273d94dcf54e2cbd39b459fb06af110d909503 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 15:32:44 -0500 Subject: [PATCH 164/169] Adjust the bar for JaCoCo checks on Java 24-ea on GitHub --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1959f0de22..72f2533457 100644 --- a/pom.xml +++ b/pom.xml @@ -202,7 +202,7 @@ 0.89 0.66 0.62 - 0.79 + 0.78 clean verify apache-rat:check japicmp:cmp checkstyle:check spotbugs:check pmd:check pmd:cpd-check javadoc:javadoc From 9ab70dba21d796d162f246e6d5fd4dc641ac08c9 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 16:38:34 -0500 Subject: [PATCH 165/169] PerUserPoolDataSource.registerPool() incorrectly replacing a CPDSConnectionFactory into managers map before throwing an IllegalStateException --- src/changes/changes.xml | 1 + .../datasources/PerUserPoolDataSource.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b562293cb7..18d83a0c95 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -68,6 +68,7 @@ The type attribute can be add,update,fix,remove. PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Fix possible NullPointerException in PoolingConnection.close(). + PerUserPoolDataSource.registerPool() incorrectly replacing a CPDSConnectionFactory into managers map before throwing an IllegalStateException. Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. Fix PMD UnnecessaryFullyQualifiedName in PoolablePreparedStatement. diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java index 95194c2a7e..7d5344ab44 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java @@ -683,19 +683,16 @@ private PerUserPoolDataSource readObjectImpl() throws IOException, ClassNotFound } } - private synchronized void registerPool(final String userName, final String password) - throws NamingException, SQLException { - + private synchronized void registerPool(final String userName, final String password) throws NamingException, SQLException { final ConnectionPoolDataSource cpds = testCPDS(userName, password); - // Set up the factory we will use (passing the pool associates // the factory with the pool, so we do not have to do so // explicitly) final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeoutDuration(), - isRollbackAfterValidation(), userName, password); + isRollbackAfterValidation(), userName, password); factory.setMaxConn(getMaxConnDuration()); - // Create an object pool to contain our PooledConnections + @SuppressWarnings("resource") final GenericObjectPool pool = new GenericObjectPool<>(factory); factory.setPool(pool); pool.setBlockWhenExhausted(getPerUserBlockWhenExhausted(userName)); @@ -713,13 +710,13 @@ private synchronized void registerPool(final String userName, final String passw pool.setTestOnReturn(getPerUserTestOnReturn(userName)); pool.setTestWhileIdle(getPerUserTestWhileIdle(userName)); pool.setDurationBetweenEvictionRuns(getPerUserDurationBetweenEvictionRuns(userName)); - pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log)); - - final PooledConnectionManager old = managers.put(getPoolKey(userName), factory); - if (old != null) { + final PoolKey poolKey = getPoolKey(userName); + if (managers.containsKey(poolKey)) { + pool.close(); throw new IllegalStateException("Pool already contains an entry for this user/password: " + userName); } + managers.put(poolKey, factory); } private Map replaceAll(final Map currentMap, final Map newMap) { From d368426bd061621ff93a88cc5a8ec18661b82b1d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 16:40:45 -0500 Subject: [PATCH 166/169] Javadoc --- .../org/apache/commons/dbcp2/PoolingDriver.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java b/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java index f553740fb7..eec6a0e095 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java @@ -87,14 +87,24 @@ public Connection getInnermostDelegate() { /** The map of registered pools. */ protected static final HashMap> pools = new HashMap<>(); - /** My URL prefix */ + /** + * The Apache Commons connection string prefix {@value}. + */ public static final String URL_PREFIX = "jdbc:apache:commons:dbcp:"; + /** + * The length of {@Link #URL_PREFIX}. + */ protected static final int URL_PREFIX_LEN = URL_PREFIX.length(); - // version numbers + /** + * Major version number. + */ protected static final int MAJOR_VERSION = 1; + /** + * Minor version number. + */ protected static final int MINOR_VERSION = 0; /** Controls access to the underlying connection */ @@ -147,7 +157,6 @@ public synchronized void closePool(final String name) throws SQLException { public Connection connect(final String url, final Properties info) throws SQLException { if (acceptsURL(url)) { final ObjectPool pool = getConnectionPool(url.substring(URL_PREFIX_LEN)); - try { final Connection conn = pool.borrowObject(); if (conn == null) { From 4157240c1aa560eaec3b22bd7a95ede5f1adfa1d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 17:17:22 -0500 Subject: [PATCH 167/169] Add missing Javadoc and missing Javadoc elements --- .../commons/dbcp2/DelegatingConnection.java | 19 ++- .../commons/dbcp2/PoolableConnection.java | 6 +- .../dbcp2/PoolableConnectionFactory.java | 58 ++++++-- .../dbcp2/PoolableConnectionMXBean.java | 124 ++++++++++++++++++ .../commons/dbcp2/PoolingDataSource.java | 5 + .../apache/commons/dbcp2/PoolingDriver.java | 4 +- .../commons/dbcp2/datasources/PoolKey.java | 2 + .../SharedPoolDataSourceFactory.java | 8 ++ .../PoolableManagedConnectionFactory.java | 2 + 9 files changed, 209 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java index 4484ac83a8..996d31f2b4 100644 --- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java @@ -325,7 +325,13 @@ public boolean getAutoCommit() throws SQLException { } /** - * Returns the state caching flag. + * Gets whether to cache properties. The cached properties are: + *
      + *
    • auto-commit
    • + *
    • catalog
    • + *
    • schema
    • + *
    • read-only
    • + *
    * * @return the state caching flag */ @@ -844,10 +850,15 @@ public void setAutoCommit(final boolean autoCommit) throws SQLException { } /** - * Sets the state caching flag. + * Sets whether to cache properties. The cached properties are: + *
      + *
    • auto-commit
    • + *
    • catalog
    • + *
    • schema
    • + *
    • read-only
    • + *
    * - * @param cacheState - * The new value for the state caching flag + * @param cacheState The new value for the state caching flag */ public void setCacheState(final boolean cacheState) { this.cacheState = cacheState; diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java index 01ce941deb..7a8dca461c 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java @@ -174,7 +174,7 @@ public void abort(final Executor executor) throws SQLException { } /** - * Returns me to my pool. + * Returns this instance to my containing pool. */ @Override public void close() throws SQLException { @@ -247,7 +247,7 @@ public Collection getDisconnectionSqlCodes() { } /** - * Expose the {@link #toString()} method via a bean getter, so it can be read as a property via JMX. + * Gets the value of the {@link #toString()} method via a bean getter, so it can be read as a property via JMX. */ @Override public String getToString() { @@ -356,7 +356,7 @@ protected void passivate() throws SQLException { } /** - * Actually close my underlying {@link Connection}. + * Closes the underlying {@link Connection}. */ @Override public void reallyClose() throws SQLException { diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java index 532e857879..0b7cdf6868 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java @@ -175,11 +175,18 @@ public ConnectionFactory getConnectionFactory() { return connectionFactory; } + /** + * Gets how many connections were created in {@link #makeObject()}. + * + * @return the connection count. + */ protected AtomicLong getConnectionIndex() { return connectionIndex; } /** + * Gets the collection of initialization SQL statements. + * * @return The collection of initialization SQL statements. * @since 2.6.0 */ @@ -188,7 +195,9 @@ public Collection getConnectionInitSqls() { } /** - * @return The data source JMX ObjectName + * Gets data source JMX ObjectName. + * + * @return The data source JMX ObjectName. * @since 2.6.0. */ public ObjectName getDataSourceJmxName() { @@ -196,7 +205,9 @@ public ObjectName getDataSourceJmxName() { } /** - * @return The data source JMS ObjectName. + * Gets the data source JMX ObjectName. + * + * @return The data source JMX ObjectName. * @since 2.6.0 */ public ObjectName getDataSourceJmxObjectName() { @@ -204,7 +215,9 @@ public ObjectName getDataSourceJmxObjectName() { } /** - * @return Default auto-commit value. + * Gets the Default auto-commit value. + * + * @return The default auto-commit value. * @since 2.6.0 */ public Boolean getDefaultAutoCommit() { @@ -212,7 +225,9 @@ public Boolean getDefaultAutoCommit() { } /** - * @return Default catalog. + * Gets the default catalog. + * + * @return The default catalog. * @since 2.6.0 */ public String getDefaultCatalog() { @@ -220,7 +235,9 @@ public String getDefaultCatalog() { } /** - * @return Default query timeout in seconds. + * Gets the default query timeout in seconds. + * + * @return The default query timeout in seconds. * @deprecated Use {@link #getDefaultQueryTimeoutDuration()}. */ @Deprecated @@ -231,7 +248,7 @@ public Integer getDefaultQueryTimeout() { /** * Gets the default query timeout Duration. * - * @return Default query timeout Duration. + * @return The default query timeout Duration. * @since 2.10.0 */ public Duration getDefaultQueryTimeoutDuration() { @@ -239,7 +256,9 @@ public Duration getDefaultQueryTimeoutDuration() { } /** - * @return Default query timeout in seconds. + * Gets the default query timeout in seconds. + * + * @return The default query timeout in seconds. * @since 2.6.0 * @deprecated Use {@link #getDefaultQueryTimeoutDuration()}. */ @@ -249,7 +268,9 @@ public Integer getDefaultQueryTimeoutSeconds() { } /** - * @return Default read-only-value. + * Gets the default read-only-value. + * + * @return The default read-only-value. * @since 2.6.0 */ public Boolean getDefaultReadOnly() { @@ -257,7 +278,9 @@ public Boolean getDefaultReadOnly() { } /** - * @return Default schema. + * Gets the default schema. + * + * @return The default schema. * @since 2.6.0 */ public String getDefaultSchema() { @@ -265,7 +288,9 @@ public String getDefaultSchema() { } /** - * @return Default transaction isolation. + * Gets the default transaction isolation. + * + * @return The default transaction isolation. * @since 2.6.0 */ public int getDefaultTransactionIsolation() { @@ -327,9 +352,15 @@ public long getMaxConnLifetimeMillis() { return maxConnDuration.toMillis(); } + /** + * Gets the maximum number of open prepared statements. + * + * @return The maximum number of open prepared statements. + */ protected int getMaxOpenPreparedStatements() { return maxOpenPreparedStatements; } + /** * Returns the {@link ObjectPool} in which {@link Connection}s are pooled. * @@ -381,6 +412,13 @@ public int getValidationQueryTimeoutSeconds() { return (int) validationQueryTimeoutDuration.getSeconds(); } + /** + * Initializes the given connection with the collection of SQL statements set in {@link #setConnectionInitSql(Collection)}. + * + * @param conn the connection to initialize. + * @throws SQLException if a database access error occurs or this method is called on a closed connection. + * @see #setConnectionInitSql(Collection) + */ protected void initializeConnection(final Connection conn) throws SQLException { final Collection sqls = connectionInitSqls; if (conn.isClosed()) { diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java index b23365080e..a31b3f3716 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionMXBean.java @@ -16,6 +16,7 @@ */ package org.apache.commons.dbcp2; +import java.sql.Connection; import java.sql.SQLException; /** @@ -25,43 +26,166 @@ */ public interface PoolableConnectionMXBean { + /** + * Clears the cached state. Call when you know that the underlying connection may have been accessed directly. + */ void clearCachedState(); + /** + * See {@link Connection#clearWarnings()}. + * + * @throws SQLException See {@link Connection#clearWarnings()}. + */ void clearWarnings() throws SQLException; + /** + * Returns this instance to my containing pool. + * + * @throws SQLException Throw if this instance cannot be returned. + */ void close() throws SQLException; + /** + * See {@link Connection#getAutoCommit()}. + * + * @return See {@link Connection#getAutoCommit()}. + * @throws SQLException See {@link Connection#getAutoCommit()}. + */ boolean getAutoCommit() throws SQLException; + /** + * Gets whether to cache properties. The cached properties are: + *
      + *
    • auto-commit
    • + *
    • catalog
    • + *
    • schema
    • + *
    • read-only
    • + *
    + * + * @return The value for the state caching flag. + */ boolean getCacheState(); + /** + * See {@link Connection#getCatalog()}. + * + * @return See {@link Connection#getCatalog()}. + * @throws SQLException See {@link Connection#getCatalog()}. + */ String getCatalog() throws SQLException; + /** + * See {@link Connection#getHoldability()}. + * + * @return See {@link Connection#getHoldability()}. + * @throws SQLException See {@link Connection#getHoldability()}. + */ int getHoldability() throws SQLException; + /** + * See {@link Connection#getSchema()}. + * + * @return See {@link Connection#getSchema()}. + * @throws SQLException See {@link Connection#getSchema()}. + */ String getSchema() throws SQLException; + /** + * Gets the value of the {@link Object#toString()} method via a bean getter, so it can be read as a property via JMX. + * + * @return the value of the {@link Object#toString()}. + */ String getToString(); + /** + * See {@link Connection#getTransactionIsolation()}. + * + * @return See {@link Connection#getTransactionIsolation()}. + * @throws SQLException See {@link Connection#getTransactionIsolation()}. + */ int getTransactionIsolation() throws SQLException; + /** + * See {@link Connection#isClosed()}. + * + * @return See {@link Connection#isClosed()}. + * @throws SQLException See {@link Connection#isClosed()}. + */ boolean isClosed() throws SQLException; + /** + * See {@link Connection#isReadOnly()}. + * + * @return See {@link Connection#isReadOnly()}. + * @throws SQLException See {@link Connection#isReadOnly()}. + */ boolean isReadOnly() throws SQLException; + /** + * Closes the underlying {@link Connection}. + * + * @throws SQLException Thrown if the connection can be closed. + */ void reallyClose() throws SQLException; + /** + * See {@link Connection#setAutoCommit(boolean)}. + * + * @param autoCommit See {@link Connection#setAutoCommit(boolean)}. + * @throws SQLException See {@link Connection#setAutoCommit(boolean)}. + */ void setAutoCommit(boolean autoCommit) throws SQLException; + /** + * Sets whether to cache properties. The cached properties are: + *
      + *
    • auto-commit
    • + *
    • catalog
    • + *
    • schema
    • + *
    • read-only
    • + *
    + * + * @param cacheState The new value for the state caching flag + */ void setCacheState(boolean cacheState); + /** + * See {@link Connection#setCatalog(String)}. + * + * @param catalog See {@link Connection#setCatalog(String)}. + * @throws SQLException See {@link Connection#setCatalog(String)}. + */ void setCatalog(String catalog) throws SQLException; + /** + * See {@link Connection#setHoldability(int)}. + * + * @param holdability {@link Connection#setHoldability(int)}. + * @throws SQLException See {@link Connection#setHoldability(int)}. + */ void setHoldability(int holdability) throws SQLException; + /** + * See {@link Connection#setReadOnly(boolean)}. + * + * @param readOnly See {@link Connection#setReadOnly(boolean)}. + * @throws SQLException See {@link Connection#setReadOnly(boolean)}. + */ void setReadOnly(boolean readOnly) throws SQLException; + /** + * See {@link Connection#setSchema(String)}. + * + * @param schema See {@link Connection#setSchema(String)}. + * @throws SQLException See {@link Connection#setSchema(String)}. + */ void setSchema(String schema) throws SQLException; + /** + * See {@link Connection#setTransactionIsolation(int)}. + * + * @param level See {@link Connection#setTransactionIsolation(int)}. + * @throws SQLException See {@link Connection#setTransactionIsolation(int)}. + */ void setTransactionIsolation(int level) throws SQLException; } diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java b/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java index 4762107e45..fe019b959d 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java @@ -192,6 +192,11 @@ public Logger getParentLogger() throws SQLFeatureNotSupportedException { throw new SQLFeatureNotSupportedException(); } + /** + * Gets the backing object pool. + * + * @return the backing object pool. + */ protected ObjectPool getPool() { return pool; } diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java b/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java index eec6a0e095..d1aacd288c 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java @@ -87,13 +87,13 @@ public Connection getInnermostDelegate() { /** The map of registered pools. */ protected static final HashMap> pools = new HashMap<>(); - /** + /** * The Apache Commons connection string prefix {@value}. */ public static final String URL_PREFIX = "jdbc:apache:commons:dbcp:"; /** - * The length of {@Link #URL_PREFIX}. + * The String length of {@link #URL_PREFIX}. */ protected static final int URL_PREFIX_LEN = URL_PREFIX.length(); diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/PoolKey.java b/src/main/java/org/apache/commons/dbcp2/datasources/PoolKey.java index 01d8675a94..31be5411fb 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/PoolKey.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/PoolKey.java @@ -20,6 +20,8 @@ import java.util.Objects; /** + * The key type for entries in a {@link PerUserPoolDataSource}. + * * @since 2.0 */ final class PoolKey implements Serializable { diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java index 937ccd1f1d..b2014365c3 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSourceFactory.java @@ -25,8 +25,16 @@ * @since 2.0 */ public class SharedPoolDataSourceFactory extends InstanceKeyDataSourceFactory { + private static final String SHARED_POOL_CLASSNAME = SharedPoolDataSource.class.getName(); + /** + * Constructs a new instance. + */ + public SharedPoolDataSourceFactory() { + // empty + } + @Override protected InstanceKeyDataSource getNewInstance(final Reference ref) { final SharedPoolDataSource spds = new SharedPoolDataSource(); diff --git a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java index 92db944f65..9dc80ccb29 100644 --- a/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java @@ -58,6 +58,8 @@ public PoolableManagedConnectionFactory(final XAConnectionFactory connFactory, f } /** + * Gets the transaction registry. + * * @return The transaction registry. * @since 2.6.0 */ From 2b75ac70b325c167d458b4818b8dcf321dd0687e Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 22:27:20 +0000 Subject: [PATCH 168/169] Prepare for the next release candidate --- CONTRIBUTING.md | 9 +- NOTICE.txt | 10 +- README.md | 12 +- RELEASE-NOTES.txt | 52 +++++ src/changes/changes.xml | 2 +- src/site/xdoc/download_dbcp.xml | 372 +++++++++++++++---------------- src/site/xdoc/issue-tracking.xml | 204 ++++++++--------- 7 files changed, 357 insertions(+), 304 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cf9b8149fd..5f23f94fbe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,9 +41,8 @@ Contributing to Apache Commons DBCP ====================== -You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to -the open source community. Before you dig right into the code there are a few guidelines that we need contributors to -follow so that we can have a chance of keeping on top of things. +Have you found a bug or have an idea for a cool new feature? Contributing code is a great way to give something back to the open-source community. +Before you dig right into the code, we need contributors to follow a few guidelines to have a chance of keeping on top of things. Getting Started --------------- @@ -62,7 +61,7 @@ Making Changes + Create a _topic branch_ for your isolated work. * Usually you should base your branch on the `master` branch. - * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `DBCP-123-InputStream`. + * A good topic branch name can be the JIRA bug ID plus a keyword, e.g. `DBCP-123-InputStream`. * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests. + Make commits of logical units. * Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue. @@ -72,7 +71,7 @@ Making Changes + Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first. + Check for unnecessary whitespace with `git diff` -- check before committing. + Make sure you have added the necessary tests for your changes, typically in `src/test/java`. -+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken. ++ Run all the tests with `mvn clean verify` to ensure nothing else was accidentally broken. Making Trivial Changes ---------------------- diff --git a/NOTICE.txt b/NOTICE.txt index d4901a2c38..75a281ea6c 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,5 +1,5 @@ -Apache Commons DBCP -Copyright 2001-2024 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (https://www.apache.org/). +Apache Commons DBCP +Copyright 2001-2024 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (https://www.apache.org/). diff --git a/README.md b/README.md index 4f40191be5..a1f9ac0113 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Apache Commons DBCP [![Java CI](https://github.com/apache/commons-dbcp/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/maven.yml) [![Maven Central](https://img.shields.io/maven-central/v/org.apache.commons/commons-dbcp2?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.commons/commons-dbcp2) -[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.12.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.12.0) +[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.13.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.13.0) [![CodeQL](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-dbcp/actions/workflows/codeql-analysis.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-dbcp) @@ -62,20 +62,20 @@ Getting the latest release -------------------------- You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi). -Alternatively, you can pull it from the central Maven repositories: +Alternatively, you can pull it from the central Maven repositories: ```xml org.apache.commons commons-dbcp2 - 2.12.0 + 2.13.0 ``` Building -------- -Building requires a Java JDK and [Apache Maven](https://maven.apache.org/). +Building requires a Java JDK and [Apache Maven](https://maven.apache.org/). The required Java version is found in the `pom.xml` as the `maven.compiler.source` property. From a command shell, run `mvn` without arguments to invoke the default Maven goal to run all tests and checks. @@ -88,7 +88,9 @@ There are some guidelines which will make applying PRs easier for us: + No tabs! Please use spaces for indentation. + Respect the existing code style for each file. + Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. -+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn```. ++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running `mvn`. ++ Before you pushing a PR, run `mvn` (by itself), this runs the default goal, which contains all build checks. ++ To see the code coverage report, regardless of coverage failures, run `mvn clean site -Dcommons.jacoco.haltOnFailure=false` If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 9bee95bd41..642e0405ac 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,4 +1,56 @@ Apache Commons DBCP +Version 2.13.0 +RELEASE NOTES + +The Apache Commons DBCP team is pleased to announce the release of Apache Commons DBCP 2.13.0. + +Apache Commons DBCP software implements Database Connection Pooling. + +This is a minor release, including bug fixes and enhancements. + +Changes +------- +New features: +* Add support for ignoring non-fatal SQL state codes #421. Thanks to Johno Crawford, Gary Gregory. +* Add @FunctionalInterface to SwallowedExceptionListener. Thanks to Johno Crawford, Gary Gregory. +* Add missing Javadoc comments and descriptions. Thanks to Gary Gregory. +* Add tests, raise the bar for JaCoCo checks. Thanks to Gary Gregory. + +Fixed Bugs +---------- +* Avoid object creation when invoking isDisconnectionSqlException #422. Thanks to Johno Crawford. +* DBCP-599: PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge Thanks to denixx baykin, Phil Steitz, Gary Gregory. +* DelegatingConnection.setSchema(String) should delegate to Jdbc41Bridge. Thanks to Gary Gregory. +* Fix possible NullPointerException in PoolingConnection.close(). Thanks to Gary Gregory. +* PerUserPoolDataSource.registerPool() incorrectly replacing a CPDSConnectionFactory into managers map before throwing an IllegalStateException. Thanks to Gary Gregory. +* Fix PMD UnnecessaryFullyQualifiedName in AbandonedTrace. Thanks to Gary Gregory. +* Fix PMD UnnecessaryFullyQualifiedName in PoolableCallableStatement. Thanks to Gary Gregory. +* Fix PMD UnnecessaryFullyQualifiedName in PoolablePreparedStatement. Thanks to Gary Gregory. +* Fix PMD UnnecessaryFullyQualifiedName in Utils. Thanks to Gary Gregory. +* Fix PMD UnnecessaryFullyQualifiedName in LocalXAConnectionFactory. Thanks to Gary Gregory. +* Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in PerUserPoolDataSource. Thanks to Gary Gregory. +* Fix SpotBugs MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT in SharedPoolDataSource. Thanks to Gary Gregory. + +Changes +------- +* Bump org.apache.commons:commons-parent from 66 to 78 #360, #371, #395, #420, #426, #436, #441, #449. Thanks to Gary Gregory. +* Bump commons-logging:commons-logging from 1.3.0 to 1.3.4 #368, #399, #423. Thanks to Gary Gregory, Dependabot. +* Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #404, #412, #427. Thanks to Gary Gregory, Dependabot. +* Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410. Thanks to Gary Gregory, Dependabot. +* Bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.16 #413, #418. Thanks to Gary Gregory, Dependabot. + + +The list of changes is here: https://commons.apache.org/proper/commons-dbcp/changes-report.html + +For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, +patches, or suggestions for improvement, see the Apache Commons DBCP website: + +https://commons.apache.org/proper/commons-dbcp/ + +Download page: https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi + +----------------------------------------------------------------------------- +Apache Commons DBCP Version 2.12.0 RELEASE NOTES diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 18d83a0c95..f005fccec6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -62,7 +62,7 @@ The type attribute can be add,update,fix,remove. EvictionTimer --> - + Avoid object creation when invoking isDisconnectionSqlException #422. PoolableConnectionFactory.destroyObject() method behaves incorrectly on ABANDONED connection, issue with unhandled AbstractMethodError. DelegatingConnection.abort(Executor) should delegate to Jdbc41Bridge diff --git a/src/site/xdoc/download_dbcp.xml b/src/site/xdoc/download_dbcp.xml index 6488e7a615..175bee975f 100644 --- a/src/site/xdoc/download_dbcp.xml +++ b/src/site/xdoc/download_dbcp.xml @@ -1,186 +1,186 @@ - - - - - - Download Apache Commons DBCP - Apache Commons Documentation Team - - -
    - -

    - We recommend you use a mirror to download our release - builds, but you must verify the integrity of - the downloaded files using signatures downloaded from our main - distribution directories. Recent releases (48 hours) may not yet - be available from all the mirrors. -

    - -

    - You are currently using [preferred]. If you - encounter a problem with this mirror, please select another - mirror. If all mirrors are failing, there are backup - mirrors (at the end of the mirrors list) that should be - available. -

    - [if-any logo][end] -

    - -
    -

    - Other mirrors: - - -

    -
    - -

    - It is essential that you - verify the integrity - of downloaded files, preferably using the PGP signature (*.asc files); - failing that using the SHA512 hash (*.sha512 checksum files). -

    -

    - The KEYS - file contains the public PGP keys used by Apache Commons developers - to sign releases. -

    -
    -
    -
    - - - - - - - - - - - - -
    commons-dbcp2-2.12.0-bin.tar.gzsha512pgp
    commons-dbcp2-2.12.0-bin.zipsha512pgp
    -
    - - - - - - - - - - - - -
    commons-dbcp2-2.12.0-src.tar.gzsha512pgp
    commons-dbcp2-2.12.0-src.zipsha512pgp
    -
    -
    -
    - - - - - - - - - - - - -
    commons-dbcp2-2.4.0-bin.tar.gzsha256pgp
    commons-dbcp2-2.4.0-bin.zipsha256pgp
    -
    - - - - - - - - - - - - -
    commons-dbcp2-2.4.0-src.tar.gzsha256pgp
    commons-dbcp2-2.4.0-src.zipsha256pgp
    -
    -
    -
    -

    - Older releases can be obtained from the archives. -

    - -
    - -
    + + + + + + Download Apache Commons DBCP + Apache Commons Documentation Team + + +
    + +

    + We recommend you use a mirror to download our release + builds, but you must verify the integrity of + the downloaded files using signatures downloaded from our main + distribution directories. Recent releases (48 hours) may not yet + be available from all the mirrors. +

    + +

    + You are currently using [preferred]. If you + encounter a problem with this mirror, please select another + mirror. If all mirrors are failing, there are backup + mirrors (at the end of the mirrors list) that should be + available. +

    + [if-any logo][end] +

    + +
    +

    + Other mirrors: + + +

    +
    + +

    + It is essential that you + verify the integrity + of downloaded files, preferably using the PGP signature (*.asc files); + failing that using the SHA512 hash (*.sha512 checksum files). +

    +

    + The KEYS + file contains the public PGP keys used by Apache Commons developers + to sign releases. +

    +
    +
    +
    + + + + + + + + + + + + +
    commons-dbcp2-2.13.0-bin.tar.gzsha512pgp
    commons-dbcp2-2.13.0-bin.zipsha512pgp
    +
    + + + + + + + + + + + + +
    commons-dbcp2-2.13.0-src.tar.gzsha512pgp
    commons-dbcp2-2.13.0-src.zipsha512pgp
    +
    +
    +
    + + + + + + + + + + + + +
    commons-dbcp2-2.4.0-bin.tar.gzsha256pgp
    commons-dbcp2-2.4.0-bin.zipsha256pgp
    +
    + + + + + + + + + + + + +
    commons-dbcp2-2.4.0-src.tar.gzsha256pgp
    commons-dbcp2-2.4.0-src.zipsha256pgp
    +
    +
    +
    +

    + Older releases can be obtained from the archives. +

    + +
    + +
    diff --git a/src/site/xdoc/issue-tracking.xml b/src/site/xdoc/issue-tracking.xml index eefb84c44a..64bb739fde 100644 --- a/src/site/xdoc/issue-tracking.xml +++ b/src/site/xdoc/issue-tracking.xml @@ -1,102 +1,102 @@ - - - - - - Apache Commons DBCP Issue tracking - Apache Commons Documentation Team - - - -
    -

    - Apache Commons DBCP uses ASF JIRA for tracking issues. - See the Apache Commons DBCP JIRA project page. -

    - -

    - To use JIRA you may need to create an account - (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically - created and you can use the Forgot Password - page to get a new password). -

    - -

    - If you would like to report a bug, or raise an enhancement request with - Apache Commons DBCP please do the following: -

      -
    1. Search existing open bugs. - If you find your issue listed then please add a comment with your details.
    2. -
    3. Search the mailing list archive(s). - You may find your issue or idea has already been discussed.
    4. -
    5. Decide if your issue is a bug or an enhancement.
    6. -
    7. Submit either a bug report - or enhancement request.
    8. -
    -

    - -

    - Please also remember these points: -

      -
    • the more information you provide, the better we can help you
    • -
    • test cases are vital, particularly for any proposed enhancements
    • -
    • the developers of Apache Commons DBCP are all unpaid volunteers
    • -
    -

    - -

    - For more information on creating patches see the - Apache Contributors Guide. -

    - -

    - You may also find these links useful: -

    -

    -
    - -
    + + + + + + Apache Commons DBCP Issue tracking + Apache Commons Documentation Team + + + +
    +

    + Apache Commons DBCP uses ASF JIRA for tracking issues. + See the Apache Commons DBCP JIRA project page. +

    + +

    + To use JIRA you may need to create an account + (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically + created and you can use the Forgot Password + page to get a new password). +

    + +

    + If you would like to report a bug, or raise an enhancement request with + Apache Commons DBCP please do the following: +

      +
    1. Search existing open bugs. + If you find your issue listed then please add a comment with your details.
    2. +
    3. Search the mailing list archive(s). + You may find your issue or idea has already been discussed.
    4. +
    5. Decide if your issue is a bug or an enhancement.
    6. +
    7. Submit either a bug report + or enhancement request.
    8. +
    +

    + +

    + Please also remember these points: +

      +
    • the more information you provide, the better we can help you
    • +
    • test cases are vital, particularly for any proposed enhancements
    • +
    • the developers of Apache Commons DBCP are all unpaid volunteers
    • +
    +

    + +

    + For more information on creating patches see the + Apache Contributors Guide. +

    + +

    + You may also find these links useful: +

    +

    +
    + +
    From 3cccba8e127cf55a4a30c5056e0bb9ec09446fd7 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 23 Nov 2024 22:29:03 +0000 Subject: [PATCH 169/169] Prepare for the next release candidate --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 72f2533457..31c4d857f8 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 commons-dbcp2 - 2.13.0-SNAPSHOT + 2.13.0 Apache Commons DBCP 2001 @@ -160,7 +160,7 @@ UTF-8 UTF-8 - 2024-03-04T01:42:34Z + 2024-11-23T22:28:37Z 1.8 1.8 dbcp