Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/javacs/markup/WarnNotThrown.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public Void visitCompilationUnit(CompilationUnitTree t, Map<TreePath, String> no

@Override
public Void visitMethod(MethodTree t, Map<TreePath, String> notThrown) {
// Skip on abstract or native
if (t.getBody() == null) {
return null;
}
// Create a new method scope
var pushDeclared = declaredExceptions;
var pushObserved = observedExceptions;
Expand Down
12 changes: 11 additions & 1 deletion src/test/examples/maven-project/src/org/javacs/warn/Unused.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ void referenceUsedByUnusedVar() {
}

void notActuallyThrown() throws Exception { }
}

interface Throws {
void interfaceThrows() throws Exception;
}

abstract class AbstractThrows {
abstract void abstractThrows() throws Exception;
}

native void nativeThrows() throws Exception;
}
5 changes: 4 additions & 1 deletion src/test/java/org/javacs/WarningsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down