Skip to content

StackOverflowError when parsing some scala files. #2

Description

@GoogleCodeExporter
I get a StackOverflowError caused by an unmatched single quote when parsing 
scala files with a comment style such as: /* `123' */

This can be reproduced with:

    String s = "'"; for(int x = 0; x < 2000; x++) s += '\n';
    new SyntaxHighlighterParser(new BrushScala()).parse(null, s);

Which gives the same error as:

    Pattern multiLineSingleQuotedString = Pattern.compile("'((\\\\.)|([^\\\\']))*'", Pattern.DOTALL);
    String s = "'"; for(int x = 0; x < 2000; x++) s += '1';
    multiLineSingleQuotedString.matcher(s).find();

Exception in thread "main" java.lang.StackOverflowError
    at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3714)
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4556)
    at java.util.regex.Pattern$Branch.match(Pattern.java:4502)
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4556)
    at java.util.regex.Pattern$Loop.match(Pattern.java:4683)
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4615)
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4466)
    ...
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4466)
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4615)

Running on OpenJDK 1.7.0_40 and ideone https://ideone.com/AnAJdf

This seems to be fixed by using a possessive quantifier in RegExpRule.java:

    public static final Pattern multiLineSingleQuotedString = Pattern.compile("'((\\\\.)|([^\\\\']))*+'", Pattern.DOTALL);

Some of the other rules here could have the same problem.

Original issue reported on code.google.com by d22...@gmail.com on 20 May 2014 at 12:56

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions