gctoolkit icon indicating copy to clipboard operation
gctoolkit copied to clipboard

Issue #359: fix NPE when parsing gc log file without any events

Open Lmh-java opened this issue 10 months ago • 10 comments
trafficstars

Intended to fix #359.

About the fix:

  1. 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");
      }
  }

View Code

  1. 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:

  1. Is termination through a RuntimeException the best way to end the process.
  2. 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.

Lmh-java avatar Jan 06 '25 02:01 Lmh-java