Skip to content

fix: Only catch expected Exceptions in LSPEclipseUtils.getFileName(URI)#1535

Merged
rubenporras merged 1 commit into
eclipse-lsp4e:mainfrom
FlorianKroiss:dont-catch-exception
May 19, 2026
Merged

fix: Only catch expected Exceptions in LSPEclipseUtils.getFileName(URI)#1535
rubenporras merged 1 commit into
eclipse-lsp4e:mainfrom
FlorianKroiss:dont-catch-exception

Conversation

@FlorianKroiss
Copy link
Copy Markdown
Contributor

@FlorianKroiss FlorianKroiss commented May 16, 2026

LSPEclipseUtils.getFileName(URI) catches Exception, which includes a NullPointerException when Path.getFileName() returns null:

   06:46:31 WARNING [org.eclipse.lsp4e] Status WARNING: org.eclipse.lsp4e code=0 Failed to parse file name from URI file:/// java.lang.NullPointerException: Cannot invoke "java.nio.file.Path.toString()" because the return value of "java.nio.file.Path.getFileName()" is null 
  java.lang.NullPointerException: Cannot invoke "java.nio.file.Path.toString()" because the return value of "java.nio.file.Path.getFileName()" is null
  	at org.eclipse.lsp4e.LSPEclipseUtils.getFileName(LSPEclipseUtils.java:436)
  	at org.eclipse.lsp4e.test.edit.LSPEclipseUtilsTest.lambda$0(LSPEclipseUtilsTest.java:652)
  	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:76)
  	at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:61)
  	at org.junit.jupiter.api.Assertions.assertDoesNotThrow(Assertions.java:3355)
  	at org.eclipse.lsp4e.test.edit.LSPEclipseUtilsTest.testReadingFileNameFromUri(LSPEclipseUtilsTest.java:652)

Catching NPEs is usually not good practice, so instead, we handle the null case explicitly. Also, we only catch expected exceptions

@FlorianKroiss FlorianKroiss force-pushed the dont-catch-exception branch from c70aa8d to 38ca7a6 Compare May 16, 2026 12:13
@rubenporras rubenporras merged commit 5a15e47 into eclipse-lsp4e:main May 19, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants