2.12.0: JavaScanner stack overflows for large block comment

68 views
Skip to first unread message

Enno

unread,
Nov 3, 2016, 1:00:18 PM11/3/16
to scala-internals
Hi,

Trying Scala 2.12.0 on one of our projects that generate code with JAXB I identified a rather serious issue in scalac's scanning of Java sources.

The method JavaScanner.skipBlockComment(Boolean) calls itself recursively for every character and is not tail recursive. It is protected as ScalaDoc overwrites it.
My naive fix would be to introduce a private helper method that can be tail recursive and call it from the original like this.

    @tailrec
    private def skipBlockCommentRecursively(isDoc: Boolean): Unit = in.ch match {
      case SU  => incompleteInputError("unclosed comment")
      case '*' => putCommentChar() ; if (in.ch == '/') putCommentChar() else skipBlockCommentRecursively(isDoc)
      case _   => putCommentChar() ; skipBlockCommentRecursively(isDoc)
    }

    protected def skipBlockComment(isDoc: Boolean): Unit = skipBlockCommentRecursively(isDoc)

I've a test case that works in the scala build, but I don't have Jira access yet. After getting access I can file a bug report and a pull request in case nobody takes on before me.

Cheers,
Enno.

Jakob Odersky

unread,
Nov 3, 2016, 2:23:38 PM11/3/16
to scala-i...@googlegroups.com
Hi Enno,

this bug came from my attempt to add support for doc comments from
Java sources to Scaladoc. Fortunately, Adriaan already has an open
pull request that fixes the issue
https://github.com/scala/scala/pull/5469

As a workaround, until scala 2.12.1 is out, you can try increasing the
stack size when running scaladoc on java sources, e.g. `scaladoc
-J-Xss3M`

best,
--Jakob
> --
> You received this message because you are subscribed to the Google Groups
> "scala-internals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scala-interna...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Adriaan Moors

unread,
Nov 3, 2016, 2:52:18 PM11/3/16
to scala-i...@googlegroups.com
Hi,

.. or temporarily disable this feature with -no-java-comments. 

cheers
adriaan

Jakob Odersky

unread,
Nov 3, 2016, 3:16:11 PM11/3/16
to scala-i...@googlegroups.com
Hey Adriaan,

unfortunately disabling the feature will not prevent the stack
overflow. It will stop parsing any comments and leave the java scanner
untouched, however that still does not restore tail recursion
optimization.

cheers,
--Jakob

Adriaan Moors

unread,
Nov 3, 2016, 3:41:34 PM11/3/16
to scala-i...@googlegroups.com
Ah yes! Good point. Should've thought of that.

Enno

unread,
Nov 3, 2016, 5:27:40 PM11/3/16
to scala-internals
Thank you Jakob and Adriaan,

Good to know the fix is so close. I was a bit surprised to run into this kind of issue in the first project I tried 2.12 on.

Cheers,
Enno. 

Jakob Odersky

unread,
Nov 3, 2016, 5:29:12 PM11/3/16
to scala-i...@googlegroups.com
Your project is very well documented then :)
Reply all
Reply to author
Forward
0 new messages