fix an npe when generating samples

Fix an NPE when generating samples. (https://github.com/dart-lang/chromedeveditor/issues/3741)