Skip to content

Commit e2e83de

Browse files
committed
Bug fix/handle possible null methodId (#478)
1 parent b3f37c6 commit e2e83de

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

java/src/main/java/org/digma/intellij/plugin/idea/psi/java/JavaLanguageService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class JavaLanguageService implements LanguageService {
4848
private final JaxrsFramework jaxrsFramework;
4949
private final GrpcFramework grpcFramework;
5050
private final SpringBootFramework springBootFramework;
51-
private List<IEndpointDiscovery> endpointDiscoveryList;
51+
private final List<IEndpointDiscovery> endpointDiscoveryList;
5252

5353

5454
/*
@@ -62,7 +62,7 @@ public JavaLanguageService(Project project) {
6262
this.jaxrsFramework = new JaxrsFramework(project);
6363
this.grpcFramework = new GrpcFramework(project);
6464
this.springBootFramework = new SpringBootFramework(project);
65-
endpointDiscoveryList = List.of(micronautFramework, jaxrsFramework, grpcFramework, springBootFramework);
65+
this.endpointDiscoveryList = List.of(micronautFramework, jaxrsFramework, grpcFramework, springBootFramework);
6666
}
6767

6868

@@ -141,15 +141,16 @@ public MethodUnderCaret detectMethodUnderCaret(@NotNull Project project, @NotNul
141141
return new MethodUnderCaret("", "", "", PsiUtils.psiFileToUri(psiFile), true);
142142
}
143143

144-
public CanInstrumentMethodResult canInstrumentMethod(@NotNull Project project, String methodId){
144+
@NotNull
145+
public CanInstrumentMethodResult canInstrumentMethod(@NotNull Project project, @Nullable String methodId){
145146

146147
var psiMethod = findPsiMethodByMethodCodeObjectId(methodId);
147148
if (psiMethod == null) {
148149
Log.log(LOGGER::warn, "Failed to get PsiMethod from method id '{}'", methodId);
149150
return CanInstrumentMethodResult.Failure();
150151
}
151152

152-
var psiFile = psiMethod.getContainingFile();
153+
var psiFile = psiMethod.getContainingFile();
153154
if (!(psiFile instanceof PsiJavaFile psiJavaFile)) {
154155
Log.log(LOGGER::warn, "PsiMethod's file is not java file (methodId: {})", methodId);
155156
return CanInstrumentMethodResult.Failure();
@@ -328,7 +329,9 @@ public Map<String, Pair<String, Integer>> findWorkspaceUrisForMethodCodeObjectId
328329
return workspaceUrls;
329330
}
330331

331-
private @Nullable PsiMethod findPsiMethodByMethodCodeObjectId(String methodId){
332+
private @Nullable PsiMethod findPsiMethodByMethodCodeObjectId(@Nullable String methodId) {
333+
if (methodId == null) return null;
334+
332335
if (methodId.contains("$_$")) {
333336
var className = methodId.substring(0, methodId.indexOf("$_$"));
334337

0 commit comments

Comments
 (0)