Merge pull request #47 from jlefever/fix-to-file-null

fix NullPointerException in DependencyGenerator
This commit is contained in:
Zhang Gang 2023-04-13 07:30:49 +08:00 committed by GitHub
commit 5e19539d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -150,6 +150,9 @@ public abstract class DependencyGenerator {
Entity fromFile = fromEntity.getAncestorOfType(FileEntity.class);
Entity toFile = toEntity.getAncestorOfType(FileEntity.class);
// If the toEntity is above the file level (e.g. a package), then toFile will be null.
if (toFile == null) return null;
return new DependencyDetail(
new LocationInfo(stripper.stripFilename(fromObject),typeOf(fromEntity),stripper.stripFilename(fromFile.getQualifiedName()),fromLineNumber),
new LocationInfo(stripper.stripFilename(toObject),typeOf(toEntity),stripper.stripFilename(toFile.getQualifiedName()),toEntity.getLine()));