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

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

Closed
retronym opened this issue Jan 28, 2020 · 0 comments
Milestone

Comments

@retronym
Copy link
Member

retronym commented Jan 28, 2020

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.

@lrytz lrytz added this to the 2.12.11 milestone Jan 28, 2020
@lrytz lrytz closed this as completed Jan 28, 2020
eed3si9n added a commit to eed3si9n/zinc that referenced this issue Feb 3, 2020
Fixes sbt#734
Ref scala/bug#11865

When `ArrayIndexOutOfBoundsException` is encountered, this will use startLine and startColumn as fallback. This is probably cheaper than trying to figure out the EOL position.
eed3si9n added a commit to eed3si9n/zinc that referenced this issue Feb 3, 2020
Fixes sbt#734
Ref scala/bug#11865

When `ArrayIndexOutOfBoundsException` is encountered, this will use startLine and startColumn as fallback. This is probably cheaper than trying to figure out the EOL position.
lrytz pushed a commit to lrytz/scala that referenced this issue Jul 13, 2023
Fixes sbt/zinc#734
Ref scala/bug#11865

When `ArrayIndexOutOfBoundsException` is encountered, this will use startLine and startColumn as fallback. This is probably cheaper than trying to figure out the EOL position.

Rewritten from sbt/zinc@4c33afe
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

2 participants