Skip to content

Commit

Permalink
Retain default behaviour when we cannot determine conflict (#4464)
Browse files Browse the repository at this point in the history
Co-authored-by: Laurens Westerlaken <[email protected]>
  • Loading branch information
Laurens-W and Laurens-W authored Sep 3, 2024
1 parent 458a35a commit 1f4564c
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public J visitIdentifier(J.Identifier ident, ExecutionContext ctx) {
.withType(null)
.withPrefix(ident.getPrefix()));
} else {
if (sf != null && hasNoConflictingImport(sf)) {
if (hasNoConflictingImport(sf)) {
ident = ident.withSimpleName(((JavaType.FullyQualified) targetType).getClassName());
} else {
ident = ident.withSimpleName(((JavaType.FullyQualified) targetType).getFullyQualifiedName());
Expand Down Expand Up @@ -508,11 +508,11 @@ private boolean isTargetFullyQualifiedType(JavaType.@Nullable FullyQualified fq)
return fq != null && TypeUtils.isOfClassType(fq, originalType.getFullyQualifiedName()) && targetType instanceof JavaType.FullyQualified;
}

private boolean hasNoConflictingImport(JavaSourceFile sf) {
private boolean hasNoConflictingImport(@Nullable JavaSourceFile sf) {
JavaType.FullyQualified oldType = TypeUtils.asFullyQualified(originalType);
JavaType.FullyQualified newType = TypeUtils.asFullyQualified(targetType);
if (oldType == null || newType == null) {
return false; // No way to be sure
if (sf == null || oldType == null || newType == null) {
return true; // No way to be sure so we retain previous behaviour
}
for (J.Import anImport : sf.getImports()) {
JavaType.FullyQualified currType = TypeUtils.asFullyQualified(anImport.getQualid().getType());
Expand Down

0 comments on commit 1f4564c

Please sign in to comment.