From 7b24614b13229c3c255fe4c6108186aa553c468c Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Sun, 21 Sep 2025 16:31:02 +0800 Subject: [PATCH 1/3] test(WarningsTest): fix for unused_throws It is unused_throw"s", and we do want that one caught. --- src/test/java/org/javacs/WarningsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/javacs/WarningsTest.java b/src/test/java/org/javacs/WarningsTest.java index 6f9c77086..6f66e79de 100644 --- a/src/test/java/org/javacs/WarningsTest.java +++ b/src/test/java/org/javacs/WarningsTest.java @@ -92,7 +92,7 @@ public void unused() { assertThat(errors, hasItem("unused_method(30)")); // private void unusedMutuallyRecursive1() { ... } assertThat(errors, hasItem("unused_method(34)")); // private void unusedMutuallyRecursive2() { ... } assertThat(errors, not(hasItem("unused_method(38)"))); // private int usedByUnusedVar() { ... } - assertThat(errors, not(hasItem("unused_throw(46)"))); // void notActuallyThrown() throws Exception { } + assertThat(errors, hasItem("unused_throws(46)")); // void notActuallyThrown() throws Exception { } } @Test From 058cad97d9c3af3b0e151183f478cef161f87332 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Sun, 21 Sep 2025 16:40:32 +0800 Subject: [PATCH 2/3] test(WarningsTest): add cases for interface/abstract/native throws --- .../maven-project/src/org/javacs/warn/Unused.java | 12 +++++++++++- src/test/java/org/javacs/WarningsTest.java | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/test/examples/maven-project/src/org/javacs/warn/Unused.java b/src/test/examples/maven-project/src/org/javacs/warn/Unused.java index a99ec88d8..da0fb20d9 100644 --- a/src/test/examples/maven-project/src/org/javacs/warn/Unused.java +++ b/src/test/examples/maven-project/src/org/javacs/warn/Unused.java @@ -44,4 +44,14 @@ void referenceUsedByUnusedVar() { } void notActuallyThrown() throws Exception { } -} \ No newline at end of file + + interface Throws { + void interfaceThrows() throws Exception; + } + + abstract class AbstractThrows { + abstract void abstractThrows() throws Exception; + } + + native void nativeThrows() throws Exception; +} diff --git a/src/test/java/org/javacs/WarningsTest.java b/src/test/java/org/javacs/WarningsTest.java index 6f66e79de..c32582339 100644 --- a/src/test/java/org/javacs/WarningsTest.java +++ b/src/test/java/org/javacs/WarningsTest.java @@ -93,6 +93,9 @@ public void unused() { assertThat(errors, hasItem("unused_method(34)")); // private void unusedMutuallyRecursive2() { ... } assertThat(errors, not(hasItem("unused_method(38)"))); // private int usedByUnusedVar() { ... } assertThat(errors, hasItem("unused_throws(46)")); // void notActuallyThrown() throws Exception { } + assertThat(errors, not(hasItem("unused_throws(49)"))); // void interfaceThrows() throws Exception; + assertThat(errors, not(hasItem("unused_throws(53)"))); // abstract void abstractThrows() throws Exception; + assertThat(errors, not(hasItem("unused_throws(56)"))); // native void nativeThrows() throws Exception; } @Test From 02bd8c31465a8f77bf45ba1e4fb783e48404193f Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Sun, 21 Sep 2025 16:42:43 +0800 Subject: [PATCH 3/3] fix(WarnNotThrown): skip if there is no body For native or abstract. --- src/main/java/org/javacs/markup/WarnNotThrown.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/javacs/markup/WarnNotThrown.java b/src/main/java/org/javacs/markup/WarnNotThrown.java index 4188361d5..aff13c1ca 100644 --- a/src/main/java/org/javacs/markup/WarnNotThrown.java +++ b/src/main/java/org/javacs/markup/WarnNotThrown.java @@ -36,6 +36,10 @@ public Void visitCompilationUnit(CompilationUnitTree t, Map no @Override public Void visitMethod(MethodTree t, Map notThrown) { + // Skip on abstract or native + if (t.getBody() == null) { + return null; + } // Create a new method scope var pushDeclared = declaredExceptions; var pushObserved = observedExceptions;