Scala-xml: CDATA behaves differently on Scala 2.11 and 2.12

We upgraded one of our projects using Scala XML from 2.11.7 to 2.12.1 and run into a difference in the handling of CDATA sections.

This code
val xml = <start><![CDATA[hi]]></start> println(xml) println(xml.child) println(xml.child(0).getClass)

With Scala 2.11 build.sbt
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6" scalaVersion in ThisBuild := "2.11.7"

gives
<start>hi</start> ArrayBuffer(hi) class scala.xml.Text

With Scala 2.12 build.sbt
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6" scalaVersion in ThisBuild := "2.12.1"

gives
<start><![CDATA[hi]]></start> ArrayBuffer(<![CDATA[hi]]>) class scala.xml.PCData

Is this change in behaviour intentional?

Cheers,
Enno.

How is the old behavior anything but a bug?

The answer would be yes, this change is intentional. See SI-3368 and scala-xml issue 74.

It seems puzzling that you’d get different behavior even though the module version is 1.0.6 in both cases. Perhaps the dependency is being overridden somehow, and you’re not actually getting 1.0.6 in both places? https://github.com/scala/scala-module-dependency-sample/pull/14 has an example of how this can happen. (I’m not 100% clear on the details, so you’d have to take a look yourself and decide if it’s relevant.)

@nafg Bug or feature? An oversimplification one could say.

@jpallas Thank you for the issue pointers.
So I found out there is the backwards compatibility flag -Xxml:coalescing.

@SethTisue Yes, that’s what puzzled me, but the change SI-3368 is in the compiler, not the module. I’m sure it has nothing to do with the problem you pointed at.

2 Likes