exceptionfactory commented on code in PR #10039:
URL: https://github.com/apache/nifi/pull/10039#discussion_r2288223673
##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java:
##########
@@ -205,6 +211,41 @@ public void testGetDataSourceProperties() throws
SQLException {
service.getDataSource().close();
}
+ @Test
+ public void testInvalidDirverH2() throws URISyntaxException {
+ final URL driverURL = org.h2.Driver.class
+ .getProtectionDomain()
+ .getCodeSource()
+ .getLocation();
Review Comment:
For testing purposes, using the Derby JDBC Driver looks like it would avoid
this reference to H2, which otherwise appears to be unused.
##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java:
##########
@@ -205,6 +211,41 @@ public void testGetDataSourceProperties() throws
SQLException {
service.getDataSource().close();
}
+ @Test
+ public void testInvalidDirverH2() throws URISyntaxException {
Review Comment:
```suggestion
public void testInvalidDriverH2() throws URISyntaxException {
```
##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java:
##########
@@ -203,7 +207,33 @@ protected Driver getDriver(final String driverName, final
String url) {
try {
clazz = Class.forName(driverName);
} catch (final ClassNotFoundException e) {
- throw new ProcessException("Driver class " + driverName + " is not
found", e);
+ // Enhanced error message with discovery
+ ResourceReferences driverResources = null;
+ try {
+ // Try to get driver resources from current context if
available
+ if (getConfigurationContext() != null) {
+ driverResources =
getConfigurationContext().getProperty(DB_DRIVER_LOCATION).evaluateAttributeExpressions().asResources();
+ }
+ } catch (Exception ignored) {
+ // Context might not be available, continue without it
+ }
+
+ final List<String> availableDrivers = (driverResources != null &&
driverResources.getCount() != 0) ?
DriverUtils.discoverDriverClasses(driverResources) : List.of();
+
+ StringBuilder errorMessage = new StringBuilder(String.format("JDBC
driver class '%s' not found.", driverName));
+
+ if (!availableDrivers.isEmpty()) {
+ errorMessage.append(String.format(" Available driver classes
found in resources: %s.", String.join(", ", availableDrivers)));
Review Comment:
Minor note, but using `" Available driver classes...".formatted()` instead
of `String.format()` would reduce some of the nesting, making this a bit easier
to read.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]