[Jastadd] [bug report] bug in establishing throws clauses of anonymous class constructors, and a possible fix

From: Na, Hyunik <hina_at_kaist.ac.kr>
Date: Sat, 25 Feb 2012 18:39:33 +0900

I'm sorry. I pressed Ctrl+Enter by mistake.

The following is the whole thing that I intended to send.





Hello JastAdd developers,


I found a minor bug of JastAddJ in establishing throws clauses of anonymous
class constructors, and a possible fix.

It is minor in that it is extremely rare that this bug causes a problem. (in
only one .java file, java/security/KeyStore.java, in OpenJDK6 class

But, due to this bug (and two others), I couldn't compile OpenJDK6 class
library using JastAddJ, as I reported 3 months ago.


The bug manifests itself in the following simple example:




           class C { }

           class D { }

           class MyException extends Exception { }


           public class Test {

             public static void main( String [] args ) {

               new C() {

                 D d = new D() { void m() throws MyException { throw new
MyException(); } };







Running JastAddJ compiler (rev. 9210) on this example produces the following
error message:




[hina_at_hyunikLinux temp]$ java -cp JastAddJ/Java1.5Backend/ JavaCompiler



  Semantic Error: new C() {

        D d = new D() {

            void m() throws MyException {

              throw new MyException();



    } may throw uncaught exception MyException; it must be caught or
declared as being thrown

[hina_at_hyunikLinux temp]$




The problem is that JastAddJ adds MyException in the throws clause of the
anonymous constructor, "new C() {.}",

which should not be the case.


I made a slight modification of the JastAddJ source code at this problem:

The last line


           return super.reachedException(catchType);


of ClassInstanceExpr.reachedException() in
Java1.4Frontend/ExceptionHandling.jrag was replaced by the following four


           for ( int i = 0 ; i < getNumArg() ; i++ ) {

              if ( getArg(i).reachedException(catchType) )

                 return true;


           return false;


This is to prevent JastAddJ from wrongly recognizing the exceptions thrown
in the TypeDecl subtree of a ClassInstanceExpr

as the exceptions that the ClassInstanceExpr throws.


Now, I can compile java/security/KeyStore.java


I hope this modification is appropriate.


- Hyunik.


Received on Sat Feb 25 2012 - 10:39:47 CET

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