fix: handle potential null pointer in test case reindex (#17100)

This commit is contained in:
Teddy 2024-07-19 13:07:48 +02:00 committed by GitHub
parent b1abb7cced
commit b568444d5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -26,8 +26,10 @@ public record TestCaseIndex(TestCase testCase) implements SearchIndex {
public void removeNonIndexableFields(Map<String, Object> esDoc) {
SearchIndex.super.removeNonIndexableFields(esDoc);
List<Map<String, Object>> testSuites = (List<Map<String, Object>>) esDoc.get("testSuites");
for (Map<String, Object> testSuite : testSuites) {
SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields);
if (testSuites != null) {
for (Map<String, Object> testSuite : testSuites) {
SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields);
}
}
}

View File

@ -2049,6 +2049,12 @@ public class TestCaseResourceTest extends EntityResourceTest<TestCase, CreateTes
assertNull(doc.get("changeDescription"));
List<Map<String, Object>> testSuites = (List<Map<String, Object>>) 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<String, String> authHeaders)