#235 DesignForExtension issue

Future
closed
nobody
None
5
2016-06-20
2003-06-23
No

Hi

I have two method like this

boolean startup(final String[] args) throws MyException {
return true;
}

void shutdown() throws MyException {
}

which a subclass may override either or both. When I
run checkstyle I get this message:

Method 'startup' is not designed for extension - needs
to be abstract, final or empty.

So, I would call this a bug. I suggest that if a method
has a returnvalue other than void only a return
statement is allowed.

Trygvis

Discussion

  • Lars Kühne

    Lars Kühne - 2003-07-19

    Logged In: YES
    user_id=401384

    The module behaves exactly as documented, so this is not a
    bug - moving to RFE tracker.

    The request is reasonable, though. We should add a property
    that controls whether a single return statement is allowed.

     
  • Lars Kühne

    Lars Kühne - 2003-11-13

    Logged In: YES
    user_id=401384

    Bug 841160 has been marked as a duplicate of this RFE, see
    also comments there.

    Rethinking my original comment here, I think Oleg is right
    that we need to be very careful about this. The intention to
    provide a "trivial implementation" kind of clashes with the
    API design style the check enforces.

    This does not mean that classes that are reported by this
    check are badly designed, and the JDK classes were
    explicitly not designed with this design philosopy in mind.

    If you are not starting with a fresh project, it's probably
    very hard to use this check at all (hint: if it gets in your
    way, you have the option of removing it from your
    configuration).

    We could still implement a property that allows "trivial"
    implementations, like I originally suggested, but what
    exactly counts as "trivial"? Is

    return someValue() + someOtherValue();

    or

    return new Blah(this) {
    // some complex anon inner class
    };

    still trivial? I don't think so - but what is the exact
    criteria?

     
  • Lars Kühne

    Lars Kühne - 2003-12-03

    Logged In: YES
    user_id=401384

    If we implement this we should also take Exceptions into accout:

    public String blah()
    {
    throw new UnsupportedOperationException();
    }

     
  • Roman Ivanov

    Roman Ivanov - 2016-06-20
    • status: open --> closed
    • Group: --> Future
     

Log in to post a comment.