Skip to content

Commit

Permalink
Fix possible NPE when create AzureArtifact from file, AB#1946705
Browse files Browse the repository at this point in the history
  • Loading branch information
Flanker32 committed May 30, 2022
1 parent e2825bc commit 65caf14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import com.microsoft.intellij.util.MavenUtils;
import icons.GradleIcons;
import icons.MavenIcons;
import org.apache.groovy.parser.antlr4.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.project.MavenProject;

import javax.annotation.Nullable;
import javax.swing.*;
import java.nio.file.Paths;
import java.util.Objects;
Expand All @@ -31,7 +33,11 @@ private AzureArtifact(final AzureArtifactType type, final String name, Object ob
this.referencedObject = obj;
}

public static AzureArtifact createFromFile(@NotNull String path) {
@Nullable
public static AzureArtifact createFromFile(@Nullable String path) {
if (StringUtils.isEmpty(path)) {
return null;
}
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
return createFromFile(virtualFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public String getFileForDeployment(AzureArtifact artifact) {
}
}

@Nullable
public AzureArtifact getAzureArtifactById(String artifactId) {
return getAllSupportedAzureArtifacts().stream().filter(artifact -> StringUtils.equals(getArtifactIdentifier(
artifact), artifactId)).findFirst().orElse(null);
}

@Nullable
public AzureArtifact getAzureArtifactById(AzureArtifactType azureArtifactType, String artifactId) {
return azureArtifactType == File ? AzureArtifact.createFromFile(artifactId) :
getAllSupportedAzureArtifacts().stream().filter(artifact -> StringUtils.equals(getArtifactIdentifier(
artifact), artifactId)).findFirst().orElse(null);
return azureArtifactType == File ? AzureArtifact.createFromFile(artifactId) : getAzureArtifactById(artifactId);
}

public String getPackaging(AzureArtifact artifact) {
Expand Down

0 comments on commit 65caf14

Please sign in to comment.