You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/03/03 15:17:30 UTC
(commons-configuration) branch master updated: DatabaseConfiguration.AbstractJdbcOperation.execute() throws NullPointerException when no data source is set
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
The following commit(s) were added to refs/heads/master by this push:
new 7777c15c DatabaseConfiguration.AbstractJdbcOperation.execute() throws NullPointerException when no data source is set
7777c15c is described below
commit 7777c15c095bfe519a9eb7f537113e3af36bce16
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 3 10:17:26 2024 -0500
DatabaseConfiguration.AbstractJdbcOperation.execute() throws
NullPointerException when no data source is set
A different implementation for #368
---
src/changes/changes.xml | 1 +
.../configuration2/DatabaseConfiguration.java | 20 +++++++++++---------
.../configuration2/TestDatabaseConfiguration.java | 6 ++++++
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2f2c4d6e..51b9e1b4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,6 +30,7 @@
<action dev="ggregory" type="fix" due-to="KeijoB, Gary Gregory">Take prefix delimiter into account when SubsetConfiguration.getKeysInternal() is called #300.</action>
<action dev="ggregory" type="fix" due-to="Heewon Lee, Gary Gregory">Guard ConfigurationMap against null configuration #355.</action>
<action dev="ggregory" type="fix" issue="CONFIGURATION-838" due-to="Ian Lynagh">Properties parser stack overflows on large single-key inputs #369.</action>
+ <action dev="ggregory" type="fix" due-to="Heewon Lee, Gary Gregory">DatabaseConfiguration.AbstractJdbcOperation.execute() throws NullPointerException when no data source is set #368.</action>
<!-- ADD -->
<action dev="ggregory" type="add" due-to="KeijoB, Gary Gregory">Add AbstractConfiguration.getKeysInternal(String, String) #300.</action>
<action dev="ggregory" type="add" due-to="KeijoB, Gary Gregory">Add ImmutableConfiguration.getKeys(String, String) #300.</action>
diff --git a/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java b/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java
index 28e16cee..bb90256c 100644
--- a/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.java
@@ -611,17 +611,19 @@ public class DatabaseConfiguration extends AbstractConfiguration {
public T execute() {
T result = null;
- try {
- conn = getDatasource().getConnection();
- result = performOperation();
+ if (getDatasource() != null) {
+ try {
+ conn = getDatasource().getConnection();
+ result = performOperation();
- if (isAutoCommit()) {
- conn.commit();
+ if (isAutoCommit()) {
+ conn.commit();
+ }
+ } catch (final SQLException e) {
+ fireError(errorEventType, operationEventType, errorPropertyName, errorPropertyValue, e);
+ } finally {
+ close(conn, pstmt, resultSet);
}
- } catch (final SQLException e) {
- fireError(errorEventType, operationEventType, errorPropertyName, errorPropertyValue, e);
- } finally {
- close(conn, pstmt, resultSet);
}
return result;
diff --git a/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java b/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java
index 6289d930..74de7b6f 100644
--- a/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java
+++ b/src/test/java/org/apache/commons/configuration2/TestDatabaseConfiguration.java
@@ -392,6 +392,11 @@ public class TestDatabaseConfiguration {
assertFalse(it.hasNext());
}
+ @Test
+ public void testGetKeysInternalNoDatasource() throws Exception {
+ ConfigurationUtils.toString(new DatabaseConfiguration());
+ }
+
@Test
public void testGetKeysMultiple() throws ConfigurationException {
final Configuration config = helper.setUpMultiConfig();
@@ -509,4 +514,5 @@ public class TestDatabaseConfiguration {
final String[] values = config.getStringArray("keyList");
assertArrayEquals(new String[] {"1", "2", "3"}, values);
}
+
}