Skip to content

fix: avoid more false positive throws#2752

Merged
skylot merged 1 commit intoskylot:masterfrom
ewt45:less-throw3
Jan 21, 2026
Merged

fix: avoid more false positive throws#2752
skylot merged 1 commit intoskylot:masterfrom
ewt45:less-throw3

Conversation

@ewt45
Copy link
Copy Markdown
Contributor

@ewt45 ewt45 commented Jan 21, 2026

This pr avoids more false positive throws in MethodThrowsVisitor.
In MethodThrowsVisitor.checkInsn(), there are two places that call visitThrows() to add throws, and the other two places that call filterExceptions() to add throws.

Only visitThrows() calls isThrowsRequired() to ignore runtime exceptions, so sometimes filterExceptions() adds redundant throws.

visitThrows() and filterExceptions() are very similar, the only difference is that the former has two more conditions: excType.isTypeKnown() && isThrowsRequired(mth, excType). So I think it's safe to replace the latter with the former.

A small reproducible example is added.

    public void noThrownExceptions3() {
		// This line leads to false positive throws.
		// 1. assignment 2. invoked method throws runtime exception
        int i = doSomething3(0);
        System.out.print(i);
    }
    public int doSomething3(int i) throws IllegalArgumentException {
        if (i < 0) {
            throw new IllegalArgumentException();
        }
        return 1;
    }

@ewt45 ewt45 changed the title fix: fix: avoid more false positive throws fix: avoid more false positive throws Jan 21, 2026
@skylot
Copy link
Copy Markdown
Owner

skylot commented Jan 21, 2026

Looks good to me. Thanks 👍

@skylot skylot merged commit 54265e3 into skylot:master Jan 21, 2026
3 of 4 checks passed
@ewt45 ewt45 deleted the less-throw3 branch January 22, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants