From c6d33effa03f7d726ffb663d3440b4a713e0f286 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Mon, 12 Nov 2018 16:50:15 +0000 Subject: [PATCH] [ML] Fix find_file_structure NPE with should_trim_fields The NPE would occur if should_trim_field was overridden to true and any field value was completely blank. This change defends against this situation. Fixes #35462 --- .../ml/filestructurefinder/DelimitedFileStructureFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/DelimitedFileStructureFinder.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/DelimitedFileStructureFinder.java index de938d0a9518c..93d440b79d434 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/DelimitedFileStructureFinder.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/filestructurefinder/DelimitedFileStructureFinder.java @@ -82,7 +82,7 @@ static DelimitedFileStructureFinder makeDelimitedFileStructureFinder(List sampleRecord = new LinkedHashMap<>(); Util.filterListToMap(sampleRecord, columnNames, - trimFields ? row.stream().map(String::trim).collect(Collectors.toList()) : row); + trimFields ? row.stream().map(field -> (field == null) ? null : field.trim()).collect(Collectors.toList()) : row); sampleRecords.add(sampleRecord); sampleMessages.add( sampleLines.subList(prevMessageEndLineNumber + 1, lineNumbers.get(index)).stream().collect(Collectors.joining("\n")));