This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 031d178acd PostgreSQL and MySQL bulk loader checks throw a 
NullPointerException when the connection doesn't exist, fixes #9386 (#9390)
031d178acd is described below

commit 031d178acdfb01d6147a52d4cbdc60ca493eb6c4
Author: Bart Maertens <[email protected]>
AuthorDate: Wed Nov 11 13:25:17 2026 +0100

    PostgreSQL and MySQL bulk loader checks throw a NullPointerException when 
the connection doesn't exist, fixes #9386 (#9390)
---
 .../mysqlbulkloader/MySqlBulkLoaderMeta.java       | 10 ++--
 .../mysqlbulkloader/MySqlBulkLoaderMetaTest.java   | 55 ++++++++++++++++++++++
 .../transforms/pgbulkloader/PGBulkLoaderMeta.java  |  7 +--
 .../pgbulkloader/PGBulkLoaderMetaTest.java         | 47 ++++++++++++++++++
 4 files changed, 112 insertions(+), 7 deletions(-)

diff --git 
a/plugins/databases/mysql/src/main/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMeta.java
 
b/plugins/databases/mysql/src/main/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMeta.java
index b291c53bc5..354bbf2ec4 100644
--- 
a/plugins/databases/mysql/src/main/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMeta.java
+++ 
b/plugins/databases/mysql/src/main/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMeta.java
@@ -146,10 +146,12 @@ public class MySqlBulkLoaderMeta extends 
BaseTransformMeta<MySqlBulkLoader, MySq
     CheckResult cr;
     StringBuilder errorMessage = new StringBuilder();
 
-    if (connection != null) {
-      DatabaseMeta databaseMeta =
-          
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection, 
variables);
-      try (Database db = new Database(loggingObject, variables, databaseMeta); 
) {
+    DatabaseMeta databaseMeta = pipelineMeta.findDatabase(connection, 
variables);
+
+    // A connection that is not in the metadata is reported here and by the 
referenced connection
+    // check. Opening a Database on a null DatabaseMeta throws and aborts the 
whole pipeline check.
+    if (databaseMeta != null) {
+      try (Database db = new Database(loggingObject, variables, databaseMeta)) 
{
         db.connect();
 
         if (!Utils.isEmpty(tableName)) {
diff --git 
a/plugins/databases/mysql/src/test/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMetaTest.java
 
b/plugins/databases/mysql/src/test/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMetaTest.java
index 583be1ff2d..a6947ca6f8 100644
--- 
a/plugins/databases/mysql/src/test/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMetaTest.java
+++ 
b/plugins/databases/mysql/src/test/java/org/apache/hop/pipeline/transforms/mysqlbulkloader/MySqlBulkLoaderMetaTest.java
@@ -17,14 +17,69 @@
 
 package org.apache.hop.pipeline.transforms.mysqlbulkloader;
 
+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.assertTrue;
 
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hop.core.HopEnvironment;
+import org.apache.hop.core.ICheckResult;
+import org.apache.hop.core.plugins.PluginRegistry;
+import org.apache.hop.core.plugins.TransformPluginType;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.junit.rules.RestoreHopEngineEnvironmentExtension;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.metadata.validation.ReferencedDatabaseConnectionChecker;
+import org.apache.hop.pipeline.PipelineMeta;
+import org.apache.hop.pipeline.transform.TransformMeta;
 import org.apache.hop.pipeline.transform.TransformSerializationTestUtil;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 class MySqlBulkLoaderMetaTest {
+  @RegisterExtension
+  static RestoreHopEngineEnvironmentExtension env = new 
RestoreHopEngineEnvironmentExtension();
+
+  @Test
+  void testCheckWithMissingConnectionDoesNotAbortPipelineCheck() throws 
Exception {
+    // Regression for #9386: a connection name that is not in the metadata 
used to throw a
+    // NullPointerException from check(), which failed the whole pipeline 
check.
+    HopEnvironment.init();
+    MemoryMetadataProvider metadataProvider = new MemoryMetadataProvider();
+    PipelineMeta pipelineMeta = new PipelineMeta();
+    pipelineMeta.setName("missing-connection");
+    pipelineMeta.setMetadataProvider(metadataProvider);
+
+    MySqlBulkLoaderMeta meta = new MySqlBulkLoaderMeta();
+    meta.setConnection("mysql");
+    meta.setTableName("target");
+    String pluginId = 
PluginRegistry.getInstance().getPluginId(TransformPluginType.class, meta);
+    pipelineMeta.addTransform(new TransformMeta(pluginId, "loader", meta));
+
+    List<ICheckResult> remarks = new ArrayList<>();
+    assertDoesNotThrow(
+        () ->
+            pipelineMeta.checkTransforms(remarks, false, null, new 
Variables(), metadataProvider));
+
+    assertTrue(
+        remarks.stream()
+            .anyMatch(
+                r ->
+                    
ReferencedDatabaseConnectionChecker.ERROR_DOES_NOT_EXIST.equals(
+                        r.getErrorCode())));
+    assertTrue(
+        remarks.stream()
+            .anyMatch(
+                r ->
+                    r.getType() == ICheckResult.TYPE_RESULT_ERROR
+                        && BaseMessages.getString(
+                                MySqlBulkLoaderMeta.class,
+                                
"MySqlBulkLoaderMeta.CheckResult.InvalidConnection")
+                            .equals(r.getText())));
+  }
 
   @Test
   void testMissingFieldFormatDefaultsToOk() {
diff --git 
a/plugins/databases/postgresql/src/main/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMeta.java
 
b/plugins/databases/postgresql/src/main/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMeta.java
index f27c9c41ca..ec8c5e3dbd 100644
--- 
a/plugins/databases/postgresql/src/main/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMeta.java
+++ 
b/plugins/databases/postgresql/src/main/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMeta.java
@@ -181,10 +181,11 @@ public class PGBulkLoaderMeta extends 
BaseTransformMeta<PGBulkLoader, PGBulkLoad
     CheckResult cr;
     String errorMessage = "";
 
-    DatabaseMeta databaseMeta =
-        
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection, 
variables);
+    DatabaseMeta databaseMeta = pipelineMeta.findDatabase(connection, 
variables);
 
-    if (connection != null) {
+    // A connection that is not in the metadata is reported here and by the 
referenced connection
+    // check. Opening a Database on a null DatabaseMeta throws and aborts the 
whole pipeline check.
+    if (databaseMeta != null) {
       Database db = new Database(loggingObject, variables, databaseMeta);
       try {
         db.connect();
diff --git 
a/plugins/databases/postgresql/src/test/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMetaTest.java
 
b/plugins/databases/postgresql/src/test/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMetaTest.java
index c2aec2e145..27e0861120 100644
--- 
a/plugins/databases/postgresql/src/test/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMetaTest.java
+++ 
b/plugins/databases/postgresql/src/test/java/org/apache/hop/pipeline/transforms/pgbulkloader/PGBulkLoaderMetaTest.java
@@ -17,12 +17,22 @@
 
 package org.apache.hop.pipeline.transforms.pgbulkloader;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 import org.apache.hop.core.HopEnvironment;
+import org.apache.hop.core.ICheckResult;
 import org.apache.hop.core.plugins.PluginRegistry;
 import org.apache.hop.core.plugins.TransformPluginType;
 import org.apache.hop.core.row.value.ValueMetaPluginType;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.junit.rules.RestoreHopEngineEnvironmentExtension;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.metadata.validation.ReferencedDatabaseConnectionChecker;
 import org.apache.hop.pipeline.Pipeline;
 import org.apache.hop.pipeline.PipelineMeta;
 import org.apache.hop.pipeline.engines.local.LocalPipelineEngine;
@@ -88,6 +98,43 @@ class PGBulkLoaderMetaTest {
     loader = new PGBulkLoader(transformMeta, lm, ld, 1, pipelineMeta, 
pipeline);
   }
 
+  @Test
+  void testCheckWithMissingConnectionDoesNotAbortPipelineCheck() {
+    // Regression for #9386: a connection name that is not in the metadata 
used to throw a
+    // NullPointerException from check(), which failed the whole pipeline 
check.
+    MemoryMetadataProvider metadataProvider = new MemoryMetadataProvider();
+    PipelineMeta pipelineMeta = new PipelineMeta();
+    pipelineMeta.setName("missing-connection");
+    pipelineMeta.setMetadataProvider(metadataProvider);
+
+    PGBulkLoaderMeta meta = new PGBulkLoaderMeta();
+    meta.setConnection("postgresql");
+    meta.setTableName("target");
+    String pluginId = 
PluginRegistry.getInstance().getPluginId(TransformPluginType.class, meta);
+    pipelineMeta.addTransform(new TransformMeta(pluginId, "loader", meta));
+
+    List<ICheckResult> remarks = new ArrayList<>();
+    assertDoesNotThrow(
+        () ->
+            pipelineMeta.checkTransforms(remarks, false, null, new 
Variables(), metadataProvider));
+
+    assertTrue(
+        remarks.stream()
+            .anyMatch(
+                r ->
+                    
ReferencedDatabaseConnectionChecker.ERROR_DOES_NOT_EXIST.equals(
+                        r.getErrorCode())));
+    assertTrue(
+        remarks.stream()
+            .anyMatch(
+                r ->
+                    r.getType() == ICheckResult.TYPE_RESULT_ERROR
+                        && BaseMessages.getString(
+                                PGBulkLoaderMeta.class,
+                                
"GPBulkLoaderMeta.CheckResult.InvalidConnection")
+                            .equals(r.getText())));
+  }
+
   public static final class PGBulkLoaderMappingMetaValidator
       implements IFieldLoadSaveValidator<PGBulkLoaderMappingMeta> {
 

Reply via email to