Skip to content

Commit

Permalink
Fix NPE occuring when a call hierarchy item may not support class files.
Browse files Browse the repository at this point in the history
- When classFileContentsSupport set to false, call hierarchy item's URI
  will be null, so we should handle this for clients

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Jul 26, 2024
1 parent 33be746 commit dd982b6
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -80,7 +81,8 @@ public List<CallHierarchyItem> prepareCallHierarchy(CallHierarchyPrepareParams p
return null;
}
checkMonitor(monitor);
return Arrays.asList(toCallHierarchyItem(candidate));
CallHierarchyItem symbol = toCallHierarchyItem(candidate);
return symbol != null ? Arrays.asList(symbol) : Collections.emptyList();
} catch (OperationCanceledException e) {
// do nothing
} catch (JavaModelException e) {
Expand Down Expand Up @@ -213,9 +215,11 @@ private List<CallHierarchyIncomingCall> getIncomingCallItemsAt(String uri, int l
IOpenable openable = getOpenable(location);
Range callRange = getRange(openable, location);
CallHierarchyItem symbol = toCallHierarchyItem(call.getMember());
symbol.setSelectionRange(callRange);
List<Range> ranges = toCallRanges(callLocations);
result.add(new CallHierarchyIncomingCall(symbol, ranges));
if (symbol != null) {
symbol.setSelectionRange(callRange);
List<Range> ranges = toCallRanges(callLocations);
result.add(new CallHierarchyIncomingCall(symbol, ranges));
}
}
}
IMember member = call.getMember();
Expand Down Expand Up @@ -268,7 +272,9 @@ private List<CallHierarchyOutgoingCall> getOutgoingCallItemsAt(String uri, int l
List<Range> ranges = toCallRanges(callLocations);
for (int i = 0; i < callLocations.size(); i++) {
CallHierarchyItem symbol = toCallHierarchyItem(call.getMember());
result.add(new CallHierarchyOutgoingCall(symbol, ranges));
if (symbol != null) {
result.add(new CallHierarchyOutgoingCall(symbol, ranges));
}
}
}
IMember member = call.getMember();
Expand Down Expand Up @@ -306,6 +312,9 @@ private MethodWrapper getCallRoot(IMember member, boolean isIncomingCall) {

private CallHierarchyItem toCallHierarchyItem(IMember member) throws JavaModelException {
Location fullLocation = getLocation(member, LocationType.FULL_RANGE);
if (fullLocation == null) {
return null;
}
Range range = fullLocation.getRange();
String uri = fullLocation.getUri();
CallHierarchyItem item = new CallHierarchyItem();
Expand Down

0 comments on commit dd982b6

Please sign in to comment.