openrewrite / rewrite-static-analysis

OpenRewrite recipes for identifying and fixing static analysis issues.
Apache License 2.0
31 stars 51 forks source link

UnnecessaryThrows removes `throws` from overridden methods #316

Closed HelloDhero closed 1 week ago

HelloDhero commented 3 months ago

What version of OpenRewrite are you using?

I am using

What is the smallest, simplest way to reproduce the problem?

import java.io.IOException;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
public abstract class AbstractView {
    protected void renderMergedOutputModel(HttpServletResponse response) throws IOException {
    }
}

class Test1 extends AbstractView {
    @Override
    protected final void renderMergedOutputModel(HttpServletResponse response) throws IOException {
        ServletOutputStream out = response.getOutputStream();
        out.flush();
    }
}
class Test2 extends AbstractView {
    /**
     * @throws IOException
     */
    @Override
    protected final void renderMergedOutputModel(HttpServletResponse response) throws IOException {
        ServletOutputStream out = response.getOutputStream();
        out.flush();
    }
}

What did you expect to see?

Exception should not be deleted

timtebeek commented 3 months ago

Could you clarify which of the three throws IOExceptions get removed? Such a before/after/expected helps us understand the issue you're seeing. A runnable unit test would be even better, as it's not yet immediately clear if this is an issue with the recipe, or your classpath setup.

https://github.com/openrewrite/rewrite-static-analysis/blob/b1b711619552c98f3c50f032871d1da0ee13ce49/src/test/java/org/openrewrite/staticanalysis/UnnecessaryThrowsTest.java#L64-L99

HelloDhero commented 3 months ago

Could you clarify which of the three throws IOExceptions get removed? Such a before/after/expected helps us understand the issue you're seeing. A runnable unit test would be even better, as it's not yet immediately clear if this is an issue with the recipe, or your classpath setup.

IOException in Test1 and Test2