> java.lang.NullPointerException: Property must not be null: uri
>
> at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29)
>
> at org.eclipse.lsp4j.TextDocumentIdentifier.(TextDocumentIdentifier.java:34)
>
> at org.wso2.lsp4intellij.editor.EditorEventManager.(EditorEventManager.java:156)
>
> at org.wso2.lsp4intellij.client.languageserver.wrapper.LanguageServerWrapper.lambda$connect$3(LanguageServerWrapper.java:374)
Root Cause Analysis:
File paths can have special characters like [, ] etc. The URL returned by calling VirtualFile.getPath() is not RFC-compliant.
Quoting the VirtualFile.getPath() documentation:
Please note these URLs are intended for use withing VFS - meaning they are not necessarily RFC-compliant.
Calling toURI() on a URL that does not conform to RFC2396 will result in URISyntaxException and a NullPointerException later on.
FileUtils.VFSToURI() should account for special characters in file path and sanitize the path correctly.
Description:
URISyntaxException
inVFSToURI(VirtualFile file)
method in FileUtils.java causesNullPointerException
.https://github.com/ballerina-platform/lsp4intellij/blob/6e892fa9bd17be481cf46abeb512bf540dee69fe/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java#L202
VFSToURI
> public static String VFSToURI(VirtualFile file) { > try { > return sanitizeURI(new URL(file.getUrl().replace(" ", SPACE_ENCODED)).toURI().toString()); > } catch (MalformedURLException | URISyntaxException e) { > LOG.warn(e); > return null; > } > }
Stack Trace
> java.lang.NullPointerException: Property must not be null: uri > > at org.eclipse.lsp4j.util.Preconditions.checkNotNull(Preconditions.java:29) > > at org.eclipse.lsp4j.TextDocumentIdentifier.(TextDocumentIdentifier.java:34)
>
> at org.wso2.lsp4intellij.editor.EditorEventManager.(EditorEventManager.java:156)
>
> at org.wso2.lsp4intellij.client.languageserver.wrapper.LanguageServerWrapper.lambda$connect$3(LanguageServerWrapper.java:374)
Root Cause Analysis: File paths can have special characters like
[
,]
etc. The URL returned by callingVirtualFile.getPath()
is not RFC-compliant.Quoting the
VirtualFile.getPath()
documentation:Calling
toURI()
on a URL that does not conform toRFC2396
will result inURISyntaxException
and aNullPointerException
later on.FileUtils.VFSToURI()
should account for special characters in file path and sanitize the path correctly.