deanwampler / programming-scala-book-code-examples

The code examples used in Programming Scala, 2nd and 3rd Editions (O'Reilly)
Other
646 stars 412 forks source link

sbt test Compilation failed: Suspicious synchronized call on boxed class #104

Closed mVenetos97 closed 8 months ago

mVenetos97 commented 8 months ago

Hello all,

Im following along Chapter 1 page 4 and I am attempting to execute sbt test under a git-cloned programming-scala-book-code-examples/ directory.

I got the following compilation failure error. Does anyone have an idea on how to fix this?

(base) programming-scala-book-code-examples % sbt test
[info] welcome to sbt 1.9.8 (Eclipse Adoptium Java 21.0.2)
[info] loading settings for project programming-scala-book-code-examples-build from plugins.sbt ...
[info] loading project definition from /Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/project
[info] loading settings for project root from build.sbt ...
[info] set current project to programming-scala-3rd-ed-code-examples (in build file:/Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/)
[info] compiling 139 Scala sources and 4 Java sources to /Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/target/scala-3.4.0/classes ...
[error] -- [E187] Potential Issue Error: /Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/src/main/scala/progscala3/traits/ui/ButtonCountObserver.scala:8:10 
[error] 8 |    count.synchronized { count += 1 }
[error]   |    ^^^^^^^^^^^^^^^^^^
[error]   |    Suspicious synchronized call on boxed class
[error]   |-----------------------------------------------------------------------------
[error]   | Explanation (enabled by `-explain`)
[error]   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]   | You called the synchronized method on a boxed primitive. This might not be what
[error]   | you intended.
[error]    -----------------------------------------------------------------------------
[error] -- [E187] Potential Issue Error: /Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/src/main/scala/progscala3/traits/ui2/CountObserver.scala:7:48 
[error] 7 |  def receiveUpdate(state: State): Unit = count.synchronized { count += 1 }
[error]   |                                          ^^^^^^^^^^^^^^^^^^
[error]   |                               Suspicious synchronized call on boxed class
[error]   |-----------------------------------------------------------------------------
[error]   | Explanation (enabled by `-explain`)
[error]   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]   | You called the synchronized method on a boxed primitive. This might not be what
[error]   | you intended.
[error]    -----------------------------------------------------------------------------
[error] -- [E187] Potential Issue Error: /Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/src/main/scala/progscala3/traits/ui2/VetoableClicks.scala:8:10 
[error] 8 |    count.synchronized { count += 1 }
[error]   |    ^^^^^^^^^^^^^^^^^^
[error]   |    Suspicious synchronized call on boxed class
[error]   |-----------------------------------------------------------------------------
[error]   | Explanation (enabled by `-explain`)
[error]   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]   | You called the synchronized method on a boxed primitive. This might not be what
[error]   | you intended.
[error]    -----------------------------------------------------------------------------
[error] -- [E187] Potential Issue Error: /Users/mvenetos/Documents/GitHub/programming-scala-book-code-examples/src/main/scala/progscala3/traits/ui2/VetoableClicks.scala:14:33 
[error] 14 |  def resetCount(): Unit = count.synchronized { count = 0 }          // <4>
[error]    |                           ^^^^^^^^^^^^^^^^^^
[error]    |                           Suspicious synchronized call on boxed class
[error]    |----------------------------------------------------------------------------
[error]    | Explanation (enabled by `-explain`)
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    | You called the synchronized method on a boxed primitive. This might not be what
[error]    | you intended.
[error]     ----------------------------------------------------------------------------
[error] four errors found
[error] (Compile / compileIncremental) Compilation failed

I am using a MacBook (Sonoma 14.2) with sbt version 1.9.8, Java version 21.0.2, and scala version 3.3.1

deanwampler commented 8 months ago

Thanks for reporting this! #106 fixes the issue.