Skip to content

Remove method throws #6331

@ghusta

Description

@ghusta

What problem are you trying to solve?

I need to remove some exceptions from the method throws clause (see JLS spec).
That's why I'd like to add this recipe.
The recipe is planned to be used on method declaration.

What precondition(s) should be checked before applying this recipe?

Precondition DeclaresMethod using a method pattern.

Describe the situation before applying the recipe

import java.io.IOException;

class A {
    public void foo() throws IOException {
        // no-op
    }
}

Describe the situation after applying the recipe

class A {
    public void foo() {
        // no-op
    }
}

Have you considered any alternatives or workarounds?

None found.

Any additional context

The options planned for this recipe, so far:

  • methodPattern
  • exceptionType (FQN)
  • matchOverrides (true by default), useful for MethodMatcher
  • removeAll (false by default) -- if true, exceptionType is ignored

Are you interested in contributing this recipe to OpenRewrite?

Yes, I'll submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Ready to Review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions