Skip to content

Commit 8925de3

Browse files
committed
fix: fix npe
1 parent f58194b commit 8925de3

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

hugegraph-loader/src/main/java/org/apache/hugegraph/loader/reader/file/FileLineFetcher.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,14 @@ public Line fetch() throws IOException {
168168
if (this.needSkipLine(rawLine) || this.checkMatchHeader(rawLine)) {
169169
continue;
170170
}
171-
return this.parser.parse(this.source().header(), rawLine);
171+
String[] header = this.source().header();
172+
if (header == null) {
173+
throw new LoadException("Header is null when parsing line at offset %s, " +
174+
"this indicates a concurrency issue or initialization failure",
175+
this.offset());
176+
}
177+
178+
return this.parser.parse(header, rawLine);
172179
}
173180
}
174181

@@ -230,9 +237,15 @@ private boolean checkMatchHeader(String line) {
230237
return false;
231238
}
232239

233-
assert this.source().header() != null;
240+
String[] header = this.source().header();
241+
if (header == null) {
242+
LOG.warn("Header is null when checking match for line at offset {}, " +
243+
"this should not happen in normal cases", this.offset());
244+
return false;
245+
}
246+
234247
String[] columns = this.parser.split(line);
235-
return Arrays.equals(this.source().header(), columns);
248+
return Arrays.equals(header, columns);
236249
}
237250

238251
private static BufferedReader createBufferedReader(InputStream stream,

hugegraph-loader/src/main/java/org/apache/hugegraph/loader/reader/file/FileReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public List<InputReader> split() {
104104

105105
this.fetcher = this.createLineFetcher();
106106
this.fetcher.readHeaderIfNeeded(readableList);
107+
if (this.source().format().needHeader() && this.source().header() == null) {
108+
throw new InitException("Failed to initialize header for file source '%s'. " +
109+
"Header is required but was not read successfully.",
110+
this.source);
111+
}
107112

108113
this.readables = readableList.iterator();
109114
List<InputReader> readers = new ArrayList<>();

hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,9 +1197,7 @@ public void testMultiFilesHaveHeader() {
11971197
"-s", configPath("multi_files_have_header/schema.groovy"),
11981198
"-g", GRAPH,
11991199
"-h", SERVER,
1200-
"--test-mode", "true",
1201-
// FIXME: Set parser-threads to 1 because values > 1 currently trigger a NullPointerException (NPE).
1202-
"--parser-threads", "1"
1200+
"--test-mode", "true"
12031201
};
12041202
loadWithAuth(args);
12051203

@@ -1632,9 +1630,7 @@ public void testFilterPathBySuffix() {
16321630
"-s", configPath("filter_path_by_suffix/schema.groovy"),
16331631
"-g", GRAPH,
16341632
"-h", SERVER,
1635-
"--test-mode", "true",
1636-
// FIXME: Set parser-threads to 1 because values > 1 currently trigger a NullPointerException (NPE).
1637-
"--parser-threads", "1"
1633+
"--test-mode", "true"
16381634
};
16391635
loadWithAuth(args);
16401636

0 commit comments

Comments
 (0)