[Jastadd] [bug report] bug in TryStmt.reachedException()

From: Na, Hyunik <hina_at_kaist.ac.kr>
Date: Mon, 30 Apr 2012 23:34:54 +0900

Hello JastAddJ Developers,

 

In ExceptionHandling.jrag in Java1.4Frontend, TryStmt.reachedException() is
defined as follows:

 

-=-=-=

  protected boolean TryStmt.reachedException(TypeDecl type) {

    boolean found = false;

    // found is true if the exception type is caught by a catch clause

    for(int i = 0; i < getNumCatchClause() && !found; i++)

      if(getCatchClause(i).handles(type))

        found = true;

    // if an exception is thrown in the block and the exception is not
caught and

    // either there is no finally block or the finally block can complete
normally

    if(!found && (!hasFinally() || getFinally().canCompleteNormally()) )

      if(getBlock().reachedException(type))

        return true;

    // even if the exception is caught by the catch clauses they may

    // throw new exceptions

    for(int i = 0; i < getNumCatchClause() && found; i++)
// ***

     if(getCatchClause(i).reachedException(type))

        return true;

    return hasFinally() && getFinally().reachedException(type);

  }

-=-=-=

 

I think that the "&& found" should be dropped from the line marked by ***

because the body of the second for statement should be executed regardless
of whether 'found' is true or not.

 

Current JastAddJ (rev. 9238) rejects the following correct program.

 

-=-=-= Test.java

class ExceptionA extends Exception {}

class ExceptionB extends Exception {}

 

public class Test {

  void test() {

    try {

      try {

        throw new ExceptionA();

      } catch ( ExceptionA e ) {

        throw new ExceptionB ();

      }

    } catch ( ExceptionB e ) {

      ;

    }

  }

}

-=-=-=

 

The error message is as follows:

 

-=-=-=

Errors:

Test.java:15:

  Semantic Error: statement is unreachable

-=-=-=

 

JastAddJ wrongly judges that the catch clause of the outer try statement is
unreachable

because it judges that ExceptionB does not reach the inner try statement.

 

This problem was observed while compiling

           . sun/rmi/transport/Transport.java

           . sun/rmi/registry/RegistryImpl.java

           . sun/rmi/server/ActivationGroupImpl.java

from OpenJDK1.6

 

Please check this.

 

- Hyunik
Received on Mon Apr 30 2012 - 16:35:11 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 16 2014 - 17:19:06 CEST