From b568444d5ef7f87307d2997ba7c2025bee8cf194 Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 19 Jul 2024 13:07:48 +0200 Subject: [PATCH] fix: handle potential null pointer in test case reindex (#17100) --- .../openmetadata/service/search/indexes/TestCaseIndex.java | 6 ++++-- .../service/resources/dqtests/TestCaseResourceTest.java | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java index d37149a872e..73caff3955d 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/TestCaseIndex.java @@ -26,8 +26,10 @@ public record TestCaseIndex(TestCase testCase) implements SearchIndex { public void removeNonIndexableFields(Map esDoc) { SearchIndex.super.removeNonIndexableFields(esDoc); List> testSuites = (List>) esDoc.get("testSuites"); - for (Map testSuite : testSuites) { - SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields); + if (testSuites != null) { + for (Map testSuite : testSuites) { + SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields); + } } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java index af6e6da9ed3..803727ec113 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java @@ -2049,6 +2049,12 @@ public class TestCaseResourceTest extends EntityResourceTest> testSuites = (List>) doc.get("testSuites"); assertNull(testSuites.get(0).get("changeDescription")); + + // Remove changeDescription logic handles null testSuites + testCase.setTestSuites(null); + doc = JsonUtils.convertValue(testCase, Map.class); + testCaseIndex = new TestCaseIndex(testCase); + testCaseIndex.removeNonIndexableFields(doc); } public void deleteTestCaseResult(String fqn, Long timestamp, Map authHeaders)