diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandler.java index ea13444d66..e4d42fbfbe 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandler.java @@ -11,6 +11,7 @@ package org.eclipse.jdt.ls.core.internal.handlers; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.apache.commons.lang3.StringUtils; @@ -45,7 +46,7 @@ public List definition(TextDocumentPositionParams position, location = computeDefinitionNavigation(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor); } - return location == null ? null : Arrays.asList(location); + return location == null ? Collections.emptyList : Arrays.asList(location); } private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java index d1a4f3134d..ed00330ec1 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/NavigateToDefinitionHandlerTest.java @@ -12,7 +12,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @@ -52,7 +51,8 @@ public void setUp() throws Exception { public void testGetEmptyDefinition() throws Exception { List definitions = handler.definition( new TextDocumentPositionParams(new TextDocumentIdentifier("/foo/bar"), new Position(1, 1)), monitor); - assertNull(definitions); + assertNotNull(definitions); + assertEquals(0, definitions.size()); } @Test @@ -66,7 +66,8 @@ public void testNoClassContentSupport() throws Exception { String uri = ClassFileUtil.getURI(project, "org.apache.commons.lang3.StringUtils"); when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(false); List definitions = handler.definition(new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(20, 26)), monitor); - assertNull(definitions); + assertNotNull(definitions); + assertEquals(0, definitions.size()); } @Test