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; 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 6f9c77086..c32582339 100644 --- a/src/test/java/org/javacs/WarningsTest.java +++ b/src/test/java/org/javacs/WarningsTest.java @@ -92,7 +92,10 @@ 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 { } + 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