Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1224280

Incorrect warning about exception not caught

XMLWordPrintable

    • 1.0beta
    • sparc
    • solaris_2.4
    • Not verified

      The following code generates this compiler warning:
      finallyBug.java:12: Warning: Exception java.lang.InterruptedException must be caught, or it must be declared in throws clause of this method.
      t.join();
      ^
      1 warning

      This warning is wrong because the exception cannot be propagated: the
      try{...}finally{return;} surrounding t.wait() effectively catches and discards
      all exceptions.

          public
          class finallyBug extends java.applet.Applet implements Runnable{
      boolean v;
      public void run(){
      v = true;
      }
      static boolean foo( finallyBug b ){
      try{
      Thread t;
      t = new Thread( b );
      t.start();
      t.join();
      } finally {
      return b.v;
      }
      }
          
      public finallyBug(){v = false;}
      public void init(){
      System.out.println("foo() "+(foo( this )?"succeeded":"failed") );
      }
          
      public static void main( String ignore[] ){
      System.out.println("foo() "+(foo( new finallyBug() )?"succeeded":"failed") );
      }
          
          }
          

            fyellinsunw Frank Yellin (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: