sarah w
sarah w

Reputation: 3485

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")
        }
}

Upvotes: 1

Views: 2933

Answers (1)

Tim
Tim

Reputation: 27356

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.

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.

Upvotes: 4

Related Questions