Bug 183339 - [compiler] "Unncessary declaration of thrown checked exception" should consider overrides/implementations
Summary: [compiler] "Unncessary declaration of thrown checked exception" should consid...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-20 04:44 EDT by David Moles CLA
Modified: 2008-08-25 06:12 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Moles CLA 2007-04-20 04:44:12 EDT
If a public or protected method declares an exception that is not actually thrown, but an overriding method in a subclass DOES throw the exception, the exception declaration should not produce a warning in the superclass.

Example:

public class Foo {
  // Produces a warning, but shouldn't
  public void someMethod() throws SomeException {   
    // default implementation does nothing
  }

  // Produces a warning, but shouldn't
  public void anotherMethod() throws SomeException {   
    // default implementation does nothing
  }
}

public class Bar extends Foo {
  public someMethod() throws SomeException {
    boolean someResult = doSomething();
    if (!someResult) {
      throw SomeException();
    }
  }
}

public class Baz extends Bar {
  public void anotherMethod() throws SomeException {
    boolean anotherResult = doSomethingElse();
    if (!anotherResult ) {
      throw SomeException();
    }
  }
}
Comment 1 Philipe Mulet CLA 2007-04-23 11:42:34 EDT
Known limitation. Rather than doing what is suggested here, we should consider documented exception in Javadoc (@throws).