From f2f33f0b809a2935be467b32fa6cb9cea2042a66 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Sat, 4 Sep 2021 13:50:02 +0200 Subject: [PATCH] Don't unnecessarily parse server handle as URI It seems ServerHandle.uri is only used for logging purposes, no need to parse it as a java.net.URI. When using Windows named pipes (like bloop bsp --protocol local --pipe \\.\pipe\foo), ServerHandle.WindowsLocal.uri crashes because of the back-slashes when trying to parse it as a URI. --- frontend/src/main/scala/bloop/io/ServerHandle.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/main/scala/bloop/io/ServerHandle.scala b/frontend/src/main/scala/bloop/io/ServerHandle.scala index da82b44552..f9830de3e2 100644 --- a/frontend/src/main/scala/bloop/io/ServerHandle.scala +++ b/frontend/src/main/scala/bloop/io/ServerHandle.scala @@ -1,30 +1,31 @@ package bloop.io -import java.net.{InetAddress, InetSocketAddress, ServerSocket, URI} +import java.net.{InetAddress, InetSocketAddress, ServerSocket} import bloop.sockets.{UnixDomainServerSocket, Win32NamedPipeServerSocket} sealed trait ServerHandle { - def uri: URI + def uri: String def server: ServerSocket } object ServerHandle { final case class WindowsLocal(pipeName: String) extends ServerHandle { val server: ServerSocket = new Win32NamedPipeServerSocket(pipeName) - def uri: URI = URI.create(s"local:$pipeName") + // pipeName should already look like "\\.\pipe\…", no need to add a prefix or anything + def uri: String = pipeName override def toString: String = s"pipe $pipeName" } final case class UnixLocal(socketFile: AbsolutePath) extends ServerHandle { val server: ServerSocket = new UnixDomainServerSocket(socketFile.syntax) - def uri: URI = URI.create(s"local://${socketFile.syntax}") + def uri: String = s"local://${socketFile.syntax}" override def toString: String = s"local://${socketFile.syntax}" } final case class Tcp(address: InetSocketAddress, backlog: Int) extends ServerHandle { val server: ServerSocket = new ServerSocket(address.getPort, backlog, address.getAddress) - def uri: URI = URI.create(s"tcp://${address.getHostString}:${server.getLocalPort}") + def uri: String = s"tcp://${address.getHostString}:${server.getLocalPort}" override def toString: String = s"${address.getHostString}:${server.getLocalPort}" }