Skip to content

Commit

Permalink
SLLS-75 Fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Apr 13, 2022
1 parent 1c3a509 commit 4360f5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class WorkspaceFolderBranchManager implements WorkspaceFolderLifecycleLis
private final ExecutorService executorService;

public WorkspaceFolderBranchManager(SonarLintExtendedLanguageClient client, ProjectBindingManager bindingManager) {
this(client, bindingManager, Executors.newSingleThreadExecutor());
this(client, bindingManager, Executors.newSingleThreadExecutor(Utils.threadFactory("SonarLint Language Server Branch Manager", false)));
}

WorkspaceFolderBranchManager(SonarLintExtendedLanguageClient client, ProjectBindingManager bindingManager, ExecutorService executorService) {
Expand Down Expand Up @@ -97,7 +97,7 @@ public void didBranchNameChange(URI folderUri, @Nullable String branchName) {
public String getReferenceBranchNameForFolder(URI folderUri) {
try {
var uriWithoutTrailingSlash = StringUtils.removeEnd(folderUri.toString(), "/");
return referenceBranchNameByFolderUri.get(new URI(uriWithoutTrailingSlash)).orElse(null);
return referenceBranchNameByFolderUri.getOrDefault(new URI(uriWithoutTrailingSlash), Optional.empty()).orElse(null);
} catch (URISyntaxException e) {
LOG.error(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@

class WorkspaceFolderBranchManagerTests {

@Test
void projectNotUnderScm() throws Exception {
var client = mock(SonarLintExtendedLanguageClient.class);
var bindingManager = mock(ProjectBindingManager.class);
var underTest = new WorkspaceFolderBranchManager(client, bindingManager, new ImmediateExecutorService());

var folderUri = new URI("file:///some_dir");

assertThat(underTest.getReferenceBranchNameForFolder(folderUri)).isNull();
}

@Test
void didBranchNameChangeNoBinding() throws Exception {
var client = mock(SonarLintExtendedLanguageClient.class);
Expand Down

0 comments on commit 4360f5e

Please sign in to comment.