Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9213

Parser runs (possibly) endless loop for unclosed parenthesis followed by many expressions/statements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      Consider the following:

      int a = 0
      // insert ( here instead of this comment and try to select anything below
      a = 0
      a = 0
      a = 0
      ... (like 50 times)
      

      With the unmatched parenthesis inserted at line 2, there is a loop in the parser looking for command arguments.

      Here is a test case that demonstrates:

      import groovy.transform.CompileStatic
      import org.codehaus.groovy.control.CompilerConfiguration
      import org.junit.Test
      
      import static org.codehaus.groovy.control.ParserPluginFactory.antlr2
      import static org.codehaus.groovy.control.ParserPluginFactory.antlr4
      
      @CompileStatic
      final class Groovy9213 {
      
          @Test(timeout=15000L)
          void testUnmatchedParenInLongScript2() {
              def config = new CompilerConfiguration()
              config.pluginFactory = antlr2()
      
              new GroovyShell(config).evaluate('''
                  int a = 0
                  (
              ''' + ('a = 0\n' * 50))
          }
      
          @Test(timeout=15000L)
          void testUnmatchedParenInLongScript4() {
              def config = new CompilerConfiguration()
              config.pluginFactory = antlr4(config)
      
              new GroovyShell(config).evaluate('''
                  int a = 0
                  (
              ''' + ('a = 0\n' * 50))
          }
      }
      

      This is a problem for users editing Groovy scripts in the IDE: https://github.com/groovy/groovy-eclipse/issues/932

      Attachments

        Activity

          People

            Unassigned Unassigned
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: