From 32fb13bb4cf4924967f5a353bf556489489a2054 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Fri, 13 May 2022 03:43:58 +0200 Subject: [PATCH] Should explicitly report the fatal settings error Signed-off-by: Snjezana Peco --- .../managers/StandardProjectsManager.java | 14 ++++++++----- .../internal/handlers/InitHandlerTest.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) 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")); }