From 47a325a713353f16160fe449bbe4067b01e6e0f8 Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Tue, 11 Aug 2026 20:26:58 +0200 Subject: [PATCH] ObjectFinalizeCallsSuper: add failing test for two-level finalize hierarchy Pins the correct behavior for A and B extends A where both override finalize() without calling super: one run should add both calls and widen both throws clauses so the hierarchy compiles. On main both calls are added but neither clause is widened, and B gets a duplicate call in cycle two. Marked @ExpectedToFail pending a ScanningRecipe. --- .../ObjectFinalizeCallsSuperTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/test/java/org/openrewrite/staticanalysis/ObjectFinalizeCallsSuperTest.java b/src/test/java/org/openrewrite/staticanalysis/ObjectFinalizeCallsSuperTest.java index 71f460e4f..d36616d01 100644 --- a/src/test/java/org/openrewrite/staticanalysis/ObjectFinalizeCallsSuperTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/ObjectFinalizeCallsSuperTest.java @@ -16,7 +16,9 @@ package org.openrewrite.staticanalysis; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.ExpectedToFail; import org.openrewrite.DocumentExample; +import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -60,6 +62,45 @@ protected void finalize() throws Throwable { ); } + @ExpectedToFail("Widens neither throws clause, and the second cycle inserts a duplicate super.finalize() into the subclass; needs hierarchy-aware handling") + @Issue("https://github.com/openrewrite/rewrite-static-analysis/pull/969") + @Test + void addsSuperFinalizeAndWidensThrowsAcrossClassHierarchy() { + rewriteRun( + //language=java + java( + """ + class A { + @Override + protected void finalize() { + } + } + + class B extends A { + @Override + protected void finalize() { + } + } + """, + """ + class A { + @Override + protected void finalize() throws Throwable { + super.finalize(); + } + } + + class B extends A { + @Override + protected void finalize() throws Throwable { + super.finalize(); + } + } + """ + ) + ); + } + @Test void hasSuperFinalizeInvocation() { rewriteRun(