Java 7 multi-catch clauses are not supported by the parser

Create issue
Issue #308 resolved
Jesper Öqvist created an issue

JastAdd does not correctly parse Java 7 catch clauses with multiple catch types.

Comments (2)

  1. Jesper Öqvist reporter

    Test case for this issue:

    // Test that the aspect parser allows Java 7 multi-catch syntax.
    // https://bitbucket.org/jastadd/jastadd2/issues/308/java-7-multi-catch-clauses-are-not
    // .grammar: { A; }
    // .result: JASTADD_PASS
    
    aspect Java7_MultiCatch {
      // No semicolon after last resource declaration.
      public void A.check(boolean t1, boolean t2) {
        try {
          throw1(t1);
          throw2(t2);
        } catch (Exception1 | Exception2 e) {
        }
    
        try {
          throw1(t1);
          throw2(t2);
          throw3(true);
        } catch (Exception1 | Exception2 | Exception3 e) {
        }
      }
    
      public void A.throw1(boolean doThrow) throws Exception1 {
        if (doThrow)
          throw new Exception1();
      }
    
      public void A.throw2(boolean doThrow) throws Exception2 {
        if (doThrow)
          throw new Exception2();
      }
    
      public void A.throw3(boolean doThrow) throws Exception3 {
        if (doThrow)
          throw new Exception3();
      }
    
      static class Exception1 extends Exception { }
      static class Exception2 extends Exception { }
      static class Exception3 extends Exception { }
    }
    

    Error message:

        [junit] [FAIL] runTest[aspect/java7_02p](tests.jastadd2.TestShouldPass)
        [junit] JastAdd code generation failed when expected to pass:
        [junit] Problems during JRAG parsing:
        [junit] Error at tests/aspect/java7_02p/Test.jrag:12:25: unexpected token "|":
        [junit]     } catch (Exception1 | Exception2 e) {
        [junit]                         ^
    
  2. Log in to comment