diff --git a/mtags/src/main/scala/scala/meta/internal/mtags/JavaToplevelMtags.scala b/mtags/src/main/scala/scala/meta/internal/mtags/JavaToplevelMtags.scala index 9e6ce7db67e..364d93f424c 100644 --- a/mtags/src/main/scala/scala/meta/internal/mtags/JavaToplevelMtags.scala +++ b/mtags/src/main/scala/scala/meta/internal/mtags/JavaToplevelMtags.scala @@ -168,6 +168,10 @@ class JavaToplevelMtags( @tailrec def quotedLiteral(quote: Char): Token = { reader.nextChar() + + if (reader.endCharOffset >= reader.buf.length) + throw new RuntimeException("Broken file, quote doesn't end.") + reader.ch match { case `quote` => Token.Literal case '\\' => diff --git a/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala b/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala index d01d058da76..26f46e8cd55 100644 --- a/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala +++ b/tests/unit/src/test/scala/tests/JavaToplevelSuite.scala @@ -66,6 +66,17 @@ class JavaToplevelSuite extends BaseToplevelSuite { List("dot/enum/Abc#"), ) + check( + "broken", + """|package dot.enum; + | + |public class Abc { + | public static final String REFERRER_ORIGIN_HOST = "audit.example.org.apache.hadoop.shaded.org.; + |} + |""".stripMargin, + List("dot/enum/Abc#"), + ) + check( "extends", """|package dot.example;