openrewrite / rewrite-static-analysis

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

org.openrewrite.staticanalysis.UnnecessaryThrows failing to detect thrown exception that is thrown in the method #270

Open blipper opened 8 months ago

blipper commented 8 months ago

What version of OpenRewrite are you using?

I am using

6.6.3

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

import lombok.Getter;

public class PuntException extends Exception
{
    @Getter
    private final String puntReason;
    @Getter
    private final String source;

    public PuntException(String message, String puntReason)
    {
        this(message, puntReason, null);
    }

    public PuntException(String message, String puntReason, String source) {
        super(message);
        this.puntReason = puntReason;
        this.source = source;
    }
}

   import com.amazon.javelinrenderingservice.exception.PuntException;

    @WithSpan
    public AAXXSPGetAdResponse getAAXResponse(
        RenderPlacementRequest renderPlacementRequest,
        CacheData cacheData,
        AdWorkflowDebugTracer adWorkflowDebugTracer,
        Metrics metrics,
        ServiceLogEntry.ServiceLogEntryBuilder serviceLogEntryBuilder) throws AAXResponseException, PuntException {

        if (cacheData.getPlacementInfo().getPlacement().getConfig().getEnableNoCreativePunting()
                && StringUtils.isEmpty(aaxxspGetAdResponse.getCreative())) {
            throw new PuntException(
                    String.format("Request was punted because of empty exchange creative for requestId: '%s'",
                            renderPlacementRequest.getRequestId()), PuntReason.NO_EXCHANGE_CREATIVE.name(), "JRS");
        }

        return aaxxspGetAdResponse;
    }

What did you expect to see?


throws AAXResponseException, PuntException 

What did you see instead?

throws AAXResponseException

What is the full stack trace of any errors you encountered?

/workplace/mnr/InsistorRedux/src/JavelinRenderingService/src/com/amazon/javelinrenderingservice/client/aax/AAXClientAdaptor.java:71: error: unreported exception PuntException; must be caught or declared to be thrown
            throw new PuntException(

Are you interested in [contributing a fix to OpenRewrite]

Yes

timtebeek commented 8 months ago

That's odd that we're not picking this up; and thanks for offering to help! Feel free to chime into our Slack as well if you'd like help with setting up your tests and IDE to explore a fix.