Skip to content

Scaladoc use case has invalid end in range position which triggers crash in recent Zinc/SBT releases #11865

@retronym

Description

@retronym

Reproduction and details in in https://github.com/retronym/sbt-scaladoc-aioooe.

The failure mode is:

    [error] java.lang.ArrayIndexOutOfBoundsException: 150
    [error]         at scala.reflect.internal.util.BatchSourceFile.findLine$1(SourceFile.scala:199)
    [error]         at scala.reflect.internal.util.BatchSourceFile.offsetToLine(SourceFile.scala:202)
    [error]         at xsbt.DelegatingReporter$.lineOf$1(DelegatingReporter.scala:99)
    [error]         at xsbt.DelegatingReporter$.makePosition$1(DelegatingReporter.scala:112)
    [error]         at xsbt.DelegatingReporter$.convert(DelegatingReporter.scala:134)
    [error]         at xsbt.DelegatingReporter.info0(DelegatingReporter.scala:165)
    [error]         at xsbt.DelegatingReporter.info0(DelegatingReporter.scala:142)
    [error]         at scala.reflect.internal.Reporter.warning(Reporting.scala:90)
    [error]         at scala.tools.nsc.doc.ScaladocAnalyzer$ScaladocTyper.$anonfun$typedDocDef$1(ScaladocAnalyzer.scala:48)
    [error]         at scala.tools.nsc.doc.ScaladocAnalyzer$ScaladocTyper.typedDocDef(ScaladocAnalyzer.scala:45)

I believe the bug would be fixed by:

diff --git a/src/compiler/scala/tools/nsc/ast/DocComments.scala b/src/compiler/scala/tools/nsc/ast/DocComments.scala
index c2e8f8e01e..243dc91726 100644
--- a/src/compiler/scala/tools/nsc/ast/DocComments.scala
+++ b/src/compiler/scala/tools/nsc/ast/DocComments.scala
@@ -415,7 +415,7 @@ trait DocComments { self: Global =>
       if (pos == NoPosition) NoPosition
       else {
         val start1 = pos.start + start
-        val end1 = pos.end + end
+        val end1 = pos.start + end
         pos withStart start1 withPoint start1 withEnd end1
       }

Use case handling in Scaladoc is something of a dead feature anyway as the Scala 2.13.x collection design doesn't call for them.

Here is the Zinc change that introduces the conversion from the (bogus) end position to a line which crashes with an AIOOBE. A bug fix in this area could also include a softer failure mode for such a conversion (e.g. just return the last line of the file.)

Workaround is to add padding to the end of the file to make sure the number of characters from @usecase ... */ is less than that from the */ ... EOF.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions