MVEL
  1. MVEL
  2. MVEL-251

Simple for-loop block inside def/function

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1
    • Component/s: Core
    • Environment:
      fails in 2.1.Beta5 and 2.0.19.
      works in 2.0.13
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      Exception NPE is thrown only when for-loop is inside def/function. Empty or more complex code in for-loop works, this bug appears only for simple code inside loop. Example:

        def test() { 
          for(i = 0; i < 3; i++) {
            // some code inside, assignment, log to console or so...
            System.out.println('...');
          }
        }
        // call function
        test();
      

      Code inside loop is executed once and then NPE is thrown, has something to do with ASTNode "null".

        Activity

        Hide
        Martin Schayna added a comment -

        Fails also when there are more than one line of code inside loop, but more complex works. I am unable to find level of complexity, when begins to work. There is a sample of real script that works:

        def getSQL(datefrom) {
          result = "";
          date1 = datefrom;
          date2 = null;
          for (int i =0; i < 12; i++) { 
            date2 = ETimeUnit.getEndDate(date1, ETimeUnit.MONTH, 1);
            if (!StringUtils.isEmpty(result)) {
              result = result + "\nUNION\n";
            }
            result = result + getPartialSQL(i, date1, date2);
            date1 = date2;
          }
          result;
        }
        
        Show
        Martin Schayna added a comment - Fails also when there are more than one line of code inside loop, but more complex works. I am unable to find level of complexity, when begins to work. There is a sample of real script that works: def getSQL(datefrom) { result = ""; date1 = datefrom; date2 = null ; for ( int i =0; i < 12; i++) { date2 = ETimeUnit.getEndDate(date1, ETimeUnit.MONTH, 1); if (!StringUtils.isEmpty(result)) { result = result + "\nUNION\n" ; } result = result + getPartialSQL(i, date1, date2); date1 = date2; } result; }
        Hide
        Mike Brock added a comment -

        yeah, i see the problem. it has to do with the new internal optimizations for variable allocation. Fixing this now.

        Show
        Mike Brock added a comment - yeah, i see the problem. it has to do with the new internal optimizations for variable allocation. Fixing this now.
        Hide
        Mike Brock added a comment -

        This fix is now in the latest 2.1-SNAPSHOT

        Show
        Mike Brock added a comment - This fix is now in the latest 2.1-SNAPSHOT

          People

          • Assignee:
            Mike Brock
            Reporter:
            Martin Schayna
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: