This page is no longer maintained — Please continue to the home page at www.scala-lang.org

NullPointerException for AbstractPartialFunction.orElse in 20110108 trunk (2.10)

2 replies
tolsen77
Joined: 2008-10-08,
User offline. Last seen 1 year 38 weeks ago.
I'm trying out the latest trunk but had some problems running my code. The code segment react(messageMatcher orElse nomatchMatcher) generates NullPointerException:

trait Resumable {
  this: scala.actors.Actor =>

  protected val monitor: scala.actors.Actor with Monitoring
  protected val messageMatcher: PartialFunction[Any, Unit]

  private final val nomatchMatcher: PartialFunction[Any, Unit] = {
    case Resumable.Exit => exit()
    case msg            => monitor.nomatchHandlers.foreach(f => f(this, msg))
  }

  final def act() {
    link(monitor)
    loop {
      react(messageMatcher orElse nomatchMatcher)
    }
  }
}

with the following stack trace:

Caused by: java.lang.NullPointerException
    at scala.runtime.AbstractPartialFunction.orElse(AbstractPartialFunction.scala:41)
    at project.ActorUtil$Resumable$$anonfun$act$1.apply(ActorUtil.scala:34)
    at project.ActorUtil$Resumable$$anonfun$act$1.apply(ActorUtil.scala:34)

Anyone able to spot the problem?

The AbstractPartialFunction is a new optimization for 2.10:

override def orElse[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = {
  val result = this.clone.asInstanceOf[AbstractPartialFunction[A1, B1]]
  result.synchronized {
    result.fallBackField = this.fallBackField orElse that
    result
  }
}

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: NullPointerException for AbstractPartialFunction.orElse in
Where are you assinging:
protected val messageMatcher: PartialFunction[Any, Unit]
?

On Sun, Jan 8, 2012 at 4:57 PM, Trond Olsen <trond [at] steinbit [dot] org> wrote:
I'm trying out the latest trunk but had some problems running my code. The code segment react(messageMatcher orElse nomatchMatcher) generates NullPointerException:

trait Resumable {
  this: scala.actors.Actor =>

  protected val monitor: scala.actors.Actor with Monitoring
  protected val messageMatcher: PartialFunction[Any, Unit]

  private final val nomatchMatcher: PartialFunction[Any, Unit] = {
    case Resumable.Exit => exit()
    case msg            => monitor.nomatchHandlers.foreach(f => f(this, msg))
  }

  final def act() {
    link(monitor)
    loop {
      react(messageMatcher orElse nomatchMatcher)
    }
  }
}

with the following stack trace:

Caused by: java.lang.NullPointerException
    at scala.runtime.AbstractPartialFunction.orElse(AbstractPartialFunction.scala:41)
    at project.ActorUtil$Resumable$$anonfun$act$1.apply(ActorUtil.scala:34)
    at project.ActorUtil$Resumable$$anonfun$act$1.apply(ActorUtil.scala:34)

Anyone able to spot the problem?

The AbstractPartialFunction is a new optimization for 2.10:

override def orElse[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = {
  val result = this.clone.asInstanceOf[AbstractPartialFunction[A1, B1]]
  result.synchronized {
    result.fallBackField = this.fallBackField orElse that
    result
  }
}




--
Viktor Klang

Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang
tolsen77
Joined: 2008-10-08,
User offline. Last seen 1 year 38 weeks ago.
Re: NullPointerException for AbstractPartialFunction.orElse in
In the classes that mixin the Resumable trait ala:

class A
  extends Some
  with Actor with Resumable {
    protected val messageMatcher: PartialFunction[Any, Unit] = {
        case msg =>
    }
}

2012/1/8 √iktor Ҡlang <viktor [dot] klang [at] gmail [dot] com>
Where are you assinging:
protected val messageMatcher: PartialFunction[Any, Unit]
?

On Sun, Jan 8, 2012 at 4:57 PM, Trond Olsen <trond [at] steinbit [dot] org> wrote:
I'm trying out the latest trunk but had some problems running my code. The code segment react(messageMatcher orElse nomatchMatcher) generates NullPointerException:

trait Resumable {
  this: scala.actors.Actor =>

  protected val monitor: scala.actors.Actor with Monitoring
  protected val messageMatcher: PartialFunction[Any, Unit]

  private final val nomatchMatcher: PartialFunction[Any, Unit] = {
    case Resumable.Exit => exit()
    case msg            => monitor.nomatchHandlers.foreach(f => f(this, msg))
  }

  final def act() {
    link(monitor)
    loop {
      react(messageMatcher orElse nomatchMatcher)
    }
  }
}

with the following stack trace:

Caused by: java.lang.NullPointerException
    at scala.runtime.AbstractPartialFunction.orElse(AbstractPartialFunction.scala:41)
    at project.ActorUtil$Resumable$$anonfun$act$1.apply(ActorUtil.scala:34)
    at project.ActorUtil$Resumable$$anonfun$act$1.apply(ActorUtil.scala:34)

Anyone able to spot the problem?

The AbstractPartialFunction is a new optimization for 2.10:

override def orElse[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = {
  val result = this.clone.asInstanceOf[AbstractPartialFunction[A1, B1]]
  result.synchronized {
    result.fallBackField = this.fallBackField orElse that
    result
  }
}




--
Viktor Klang

Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland