Skip to content

Commit

Permalink
fixes crash in LSP frontend if no port is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
ArquintL committed May 20, 2021
1 parent 35bfb36 commit ae407ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/scala/viper/server/ViperConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ class ViperConfig(args: Seq[String]) extends ScallopConf(args) {
+ s"The port must be an integer in range [${ibm.Socket.MIN_PORT_NUMBER}-${ibm.Socket.MAX_PORT_NUMBER}]"
+ "If the option is omitted, an available port will be selected automatically."),
validate = p => try {
ibm.Socket.available(p)
if (p != 0) {
ibm.Socket.available(p)
} else {
true
}
} catch {
case e: Exception =>
println(s"Invalid port $p: $e")
false
},
default = Some(0),
noshort = false,
hidden = false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class ViperHttpServer(config: ViperConfig)(executor: VerificationExecutionContex

ViperCache.initialize(logger.get, config.backendSpecificCache())

port = config.port.getOrElse(ibm.Socket.findFreePort)
port = config.port.toOption
.flatMap(p => if (p == 0) None else Some(p)) // also search for a free port if the provided one is zero
.getOrElse(ibm.Socket.findFreePort)
super.start(config.maximumActiveJobs())
println(s"ViperServer online at http://localhost:$port")
}
Expand Down

0 comments on commit ae407ff

Please sign in to comment.