gctoolkit
gctoolkit copied to clipboard
Issue #359: fix NPE when parsing gc log file without any events
trafficstars
Intended to fix #359.
About the fix:
- Introduced a null guard. When
getClock()is initially null, it means there is no event in the file. Therefore, we throw an exception to terminate the remaining process.
public void diary(Diary diary) {
this.diary = diary;
this.clock = diary.getTimeOfFirstEvent();
if (this.clock == null) {
LOGGER.log(Level.SEVERE, "Time of first event is null, are there any events presented in the log file?");
throw new IllegalStateException("Missing log events");
}
}
- Added 2 test cases, which reproduces this issue and validate the fix (Test data files will be provided in another PR to the test data repo, once this PR is finalized).
Discussion:
- Is termination through a RuntimeException the best way to end the process.
- Probably a null guard in GCLogParser is not the best position, but I cannot find a better position to check for null. In the current context, IMO, only parser knows if there is any events present in the file.
I am not very familar with the project. Any advice is welcome and will be highly valued.