eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

AddMissingMethodDeclarationFixCore makes unsafe call to getFunctionalInterfaceMethod() - NPE

Open
#2,771 2 comments 0 reactions 1 assignee Claimed by @jjohnstn View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
21h 41m
Merged PRs (30d)
31

Description

QuickAssistProcessorUtil has the following code,calling `getFunctionalInterfaceMethod` but checking the result for null:

```
public static IMethodBinding getFunctionalMethodForMethodReference(MethodReference methodReference) {
ITypeBinding targetTypeBinding= ASTNodes.getTargetType(methodReference);
if (targetTypeBinding == null)
return null;

IMethodBinding functionalMethod= targetTypeBinding.getFunctionalInterfaceMethod();
if (functionalMethod != null && functionalMethod.isSynthetic()) {
functionalMethod= Bindings.findOverriddenMethodInType(functionalMethod.getDeclaringClass(), functionalMethod);
}
return functionalMethod;
}
```

However similar code in `AddMissingMethodDeclarationFixCore` does not proceed in a null-safe fashion:

```
ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
ITypeBinding[] typeArguments= methodBinding.getTypeArguments();
ITypeBinding[] parameterTypesFunctionalInterface= parameterTypes[index].getFunctionalInterfaceMethod().getParameterTypes();
ITypeBinding returnTypeBindingFunctionalInterface= parameterTypes[index].getFunctionalInterfaceMethod().getReturnType();

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.