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

ConstructingParser throws NoSuchMethodError in Scala 3 #541

Closed
cayhorstmann opened this issue Jul 16, 2021 · 6 comments
Closed

ConstructingParser throws NoSuchMethodError in Scala 3 #541

cayhorstmann opened this issue Jul 16, 2021 · 6 comments

Comments

@cayhorstmann
Copy link

cayhorstmann commented Jul 16, 2021

Save https://horstmann.com/unblog/2020-11-27/index.html to a local file and run

import java.io.File
import scala.xml.parsing.ConstructingParser
val filename="..."
val file = new File(filename)
val parser = ConstructingParser.fromFile(file, preserveWS = true)
val doc = parser.document().docElem

In Scala 2, this works perfectly. In Scala 3.0.0, an exception is thrown:

java.lang.NoSuchMethodError: 'scala.xml.parsing.MarkupParser scala.xml.parsing.MarkupParser$WithLookAhead.scala$xml$parsing$MarkupParser$WithLookAhead$$$outer()'
  at scala.xml.parsing.MarkupParser.lookahead(MarkupParser.scala:77)
  at scala.xml.parsing.MarkupParser.lookahead$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.lookahead(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParserCommon.peek(MarkupParserCommon.scala:267)
  at scala.xml.parsing.MarkupParserCommon.xTakeUntil(MarkupParserCommon.scala:249)
  at scala.xml.parsing.MarkupParserCommon.xTakeUntil$(MarkupParserCommon.scala:25)
  at scala.xml.parsing.ConstructingParser.xTakeUntil(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.xCharData(MarkupParser.scala:382)
  at scala.xml.parsing.MarkupParser.xCharData$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.xCharData(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content1(MarkupParser.scala:427)
  at scala.xml.parsing.MarkupParser.content1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content(MarkupParser.scala:462)
  at scala.xml.parsing.MarkupParser.content$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.element1(MarkupParser.scala:591)
  at scala.xml.parsing.MarkupParser.element1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.element1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content1(MarkupParser.scala:436)
  at scala.xml.parsing.MarkupParser.content1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content(MarkupParser.scala:462)
  at scala.xml.parsing.MarkupParser.content$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.element1(MarkupParser.scala:591)
  at scala.xml.parsing.MarkupParser.element1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.element1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content1(MarkupParser.scala:436)
  at scala.xml.parsing.MarkupParser.content1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content(MarkupParser.scala:462)
  at scala.xml.parsing.MarkupParser.content$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.element1(MarkupParser.scala:591)
  at scala.xml.parsing.MarkupParser.element1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.element1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content1(MarkupParser.scala:436)
  at scala.xml.parsing.MarkupParser.content1$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content1(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.content(MarkupParser.scala:462)
  at scala.xml.parsing.MarkupParser.content$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.content(ConstructingParser.scala:52)
  at scala.xml.parsing.MarkupParser.document(MarkupParser.scala:251)
  at scala.xml.parsing.MarkupParser.document$(MarkupParser.scala:33)
  at scala.xml.parsing.ConstructingParser.document(ConstructingParser.scala:52)

The offending code is

def lookahead(): BufferedIterator[Char] = curInput match {
    case curInputWLA: WithLookAhead =>
      curInputWLA.lookahead()

The library dependency in build.sbt:

libraryDependencies ++= Seq(
  "org.scala-lang.modules" %% "scala-xml" % "2.0.0",
)
@SethTisue
Copy link
Member

SethTisue commented Jul 16, 2021

I'm able to reproduce the problem locally in the Scala 3 REPL.

Once we dig into this it seems like it has to ultimately be a Scala 3 bug rather than something we did wrong in this repo. Regardless, we need this scala-xml ticket anyway because we'll need to publish a new version of the library once there's a compiler fix.

@joroKr21
Copy link
Member

Next step would be to getDeclaredMethods of the WithLookAhead class and see what is the name of the outer accessor (if it exists)

@SethTisue
Copy link
Member

SethTisue commented Jul 16, 2021

minimized (not sure the string is absolutely minimal, but it doesn't matter, we just want something short that triggers it)

  @Test
  def issue541: Unit = {
    val xml =
      """|<script>// <![CDATA[
         |[]; // ]]>
         |</script>""".stripMargin
    val parser = ConstructingParser.fromSource(Source.fromString(xml), preserveWS = true)
    parser.document().docElem  // shouldn't crash
  }

@SethTisue
Copy link
Member

I've reported the Scala 3 compiler bug responsible over at scala/scala3#13096

Here in this repo, I will submit a pull request with a workaround.

@SethTisue
Copy link
Member

PR: #542

@SethTisue
Copy link
Member

fixed in 2.0.1 which is now published

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants