diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java index 094c981f85..05669bef25 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java @@ -542,12 +542,16 @@ private List getURIs(String url) { private void addWatcher(URI uri, Set sources) { if (uri != null && "file".equals(uri.getScheme())) { - File file = new File(uri); - if (file != null) { - IPath path = new Path(file.getAbsolutePath()); - if (!isContainedIn(path, sources)) { - sources.add(path); + try { + File file = new File(uri); + if (file != null) { + IPath path = new Path(file.getAbsolutePath()); + if (!isContainedIn(path, sources)) { + sources.add(path); + } } + } catch (Exception e) { + JavaLanguageServerPlugin.logException(e.getMessage(), e); } } } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java index 7812fa17ee..aca87fd074 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -374,6 +375,26 @@ public int compare(FileSystemWatcher o1, FileSystemWatcher o2) { assertEquals(newWatchers, watchers); } + // https://github.com/redhat-developer/vscode-java/issues/2429 + @Test + public void testSettingsWatchers() throws Exception { + ClientPreferences mockCapabilies = mock(ClientPreferences.class); + when(mockCapabilies.isWorkspaceChangeWatchedFilesDynamicRegistered()).thenReturn(Boolean.TRUE); + when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); + try { + preferences.setFormatterUrl("file:c:invalid"); + String settingsUrl = "../../formatter/settings.prefs"; + preferences.setSettingsUrl(settingsUrl); + List watchers = projectsManager.registerWatchers(); + assertEquals("Unexpected watchers:\n" + toString(watchers), 10, watchers.size()); + } catch (Exception e) { + fail(e.getMessage()); + } finally { + preferences.setFormatterUrl(null); + preferences.setSettingsUrl(null); + } + } + private String toString(List watchers) { return watchers.stream().map(FileSystemWatcher::getGlobPattern).collect(Collectors.joining("\n")); }