Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes NullPointerException caused by initialization bug in STArray #155

Merged
merged 1 commit into from Sep 24, 2012

Conversation

Projects
None yet
2 participants
@eed3si9n
Copy link
Contributor

eed3si9n commented Sep 22, 2012

steps

  1. See the STTest that I started:
  "STArray" in {
    def e1[S] = for {
      arr <- newArr[S, Boolean](3, true)
      _ <- arr.write(0, false)
      r <- arr.freeze
    } yield r
    runST(new ForallST[ImmutableArray[Boolean]] { def apply[S] = e1[S] }).toList must be_===(
      List(false, true, true))
  }

problem

NullPointerException.

[error] ! STArray
[error]   NullPointerException: null (ArrayBuilder.scala:37)
[error] scala.collection.mutable.ArrayBuilder$.make(ArrayBuilder.scala:37)
[error] scala.Array$.newBuilder(Array.scala:52)
[error] scala.Array$.fill(Array.scala:235)
[error] scalaz.effect.STArray$class.$init$(ST.scala:71)
[error] scalaz.effect.STArrayFunctions$$anon$4.<init>(ST.scala:108)
[error] scalaz.effect.STArrayFunctions$class.stArray(ST.scala:108)
[error] scalaz.effect.STArray$.stArray(ST.scala:103)
[error] scalaz.effect.STFunctions$$anonfun$newArr$1.apply(ST.scala:164)
[error] scalaz.effect.STFunctions$$anonfun$newArr$1.apply(ST.scala:164)
[error] scalaz.effect.STFunctions$$anonfun$returnST$1.apply(ST.scala:151)
[error] scalaz.effect.STFunctions$$anonfun$returnST$1.apply(ST.scala:151)
[error] scalaz.effect.STFunctions$$anon$5.apply(ST.scala:142)
[error] scalaz.effect.ST$$anonfun$flatMap$1.apply(ST.scala:125)
[error] scalaz.effect.ST$$anonfun$flatMap$1.apply(ST.scala:125)
[error] scalaz.effect.STFunctions$$anon$5.apply(ST.scala:142)
[error] scalaz.effect.STFunctions$class.runST(ST.scala:155)
[error] scalaz.effect.ST$.runST(ST.scala:135)
[error] scalaz.effect.STTest$$anonfun$3$$anonfun$apply$8.apply(STTest.scala:28)
[error] scalaz.effect.STTest$$anonfun$3$$anonfun$apply$8.apply(STTest.scala:28)

what this changes

To work around the initialization order of STArray trait, I turned size, z, and manifest into defs (these are overridden later as vals), and turned value into a lazy val. Now the test passes without NPE.

tonymorris added a commit that referenced this pull request Sep 24, 2012

Merge pull request #155 from eed3si9n/topic/starrayfix
fixes NullPointerException caused by initialization bug in STArray

@tonymorris tonymorris merged commit f036fe5 into scalaz:scalaz-seven Sep 24, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.