fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem

The name of the picture


fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem



I am using scapegoat for static code analysis i am getting a warning message


fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem



here is my code


object ActorSystemSetting extends ActorSystemSettingTrait{
val config = ConfigFactory.load()
val log = LoggerFactory.getLogger(this.getClass)

var actorSystem : Option[ActorSystem] = None
def createActorSystem: Option[ActorSystem] = {
actorSystem = Option(ActorSystem("ArteciateActorSystem", config))
actorSystem
}

def getActorSystem : Option[ActorSystem] ={
if (actorSystem == None){
createActorSystem
}
else{
log.debug("ActorSystem is not null")
}
actorSystem
}
}



In this section i am getting warning message
on the line


case Some(system: ActorSystem) =>




Option(ActorSystemSetting.getActorSystem) match {
case Some(system: ActorSystem) =>
system.actorOf(Props[PaymentViaCreditDeletionActor]
, name = "PaymentViaCreditDeletionActor")
case None => log.debug("ActorSystem is null")
}
}




1 Answer
1



You need to change this


Option(ActorSystemSetting.getActorSystem) match {



to just this:


ActorSystemSetting.getActorSystem match {



ActorSystemSetting.getActorSystem already returns Option(ActorSystem) so you don't need to wrap it in another Option.


ActorSystemSetting.getActorSystem


Option(ActorSystem)


Option



It is not working because you are trying to match a value of type Option[Option[ActorSystem]] with Some(system: ActorSystem), which is of type Option[ActorSystem] so it can never match.


Option[Option[ActorSystem]]


Some(system: ActorSystem)


Option[ActorSystem]






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions