Skip to content

Commit 65caf14

Browse files
committed
Fix possible NPE when create AzureArtifact from file, AB#1946705
1 parent e2825bc commit 65caf14

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/AzureArtifact.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import com.microsoft.intellij.util.MavenUtils;
1414
import icons.GradleIcons;
1515
import icons.MavenIcons;
16+
import org.apache.groovy.parser.antlr4.util.StringUtils;
1617
import org.jetbrains.annotations.NotNull;
1718
import org.jetbrains.idea.maven.project.MavenProject;
1819

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

34-
public static AzureArtifact createFromFile(@NotNull String path) {
36+
@Nullable
37+
public static AzureArtifact createFromFile(@Nullable String path) {
38+
if (StringUtils.isEmpty(path)) {
39+
return null;
40+
}
3541
final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
3642
return createFromFile(virtualFile);
3743
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/AzureArtifactManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public String getFileForDeployment(AzureArtifact artifact) {
8989
}
9090
}
9191

92+
@Nullable
9293
public AzureArtifact getAzureArtifactById(String artifactId) {
9394
return getAllSupportedAzureArtifacts().stream().filter(artifact -> StringUtils.equals(getArtifactIdentifier(
9495
artifact), artifactId)).findFirst().orElse(null);
9596
}
9697

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

103103
public String getPackaging(AzureArtifact artifact) {

0 commit comments

Comments
 (0)