jacoco icon indicating copy to clipboard operation
jacoco copied to clipboard

Improve FinallyFilter

Open Godin opened this issue 1 month ago • 0 comments

class Example {
	private static String example(int i) {
		try {
			switch (i) {
			case 0:
				return "case 0";
			case 1:
				return "case 1";
			}
		} finally {
			System.out.println(i == 0); // currently 1 of 4 branches missed
		}
		return "";
	}

	public static void main(String[] args) {
		example(0);
		example(1);
		example(2);
	}
}

switch

  • is last inside try-finally
  • without default
  • return in all cases

class Example {
	public static void main(String[] args) {
		loop: for (int i = 0; i <= 5; i++) {
			try {
				switch (i) {
				case 1:
					System.out.println("case 1");
					break;
				case 5:
					break loop;
				default:
					System.out.println("default");
					break;
				}
				System.out.println();
			} finally {
				System.out.println(i == 0); // currently 1 of 4 branches missed
			}
		}
	}
}

Godin avatar Dec 09 '25 23:12 Godin