Merge pull request #18947 from tamasvajk/tamasvajk/java_empty_method

Java: Add new quality query to detect empty methods
This commit is contained in:
Tamás Vajk
2025-03-26 09:33:47 +01:00
committed by GitHub
12 changed files with 500 additions and 6 deletions

View File

@@ -0,0 +1,54 @@
import org.aspectj.lang.annotation.Pointcut;
public class Class1 {
// COMPLIANT
public void f() {
int i = 0;
}
// COMPLIANT
public void f1() {
// intentionally empty
}
// NON_COMPLIANT
public void f2() { } // $ Alert
// COMPLIANT - exception
@Pointcut()
public void f4() {
}
/**
* COMPLIANT - empty method with javadoc
*/
public void f5() {
}
public abstract class TestInner {
public abstract void f(); // COMPLIANT - intentionally empty
}
public class Derived extends TestInner {
// COMPLIANT: with annotation
@Override
public void f() {
}
// COMPLIANT: native
public native int nativeMethod();
}
public interface TestInterface {
// NON_COMPLIANT
default void method() { } // $ Alert
void method2(); // COMPLIANT
}
}

View File

@@ -0,0 +1,2 @@
| Class1.java:16:15:16:16 | f2 | Empty method found. |
| Class1.java:49:18:49:23 | method | Empty method found. |

View File

@@ -0,0 +1,2 @@
query: Language Abuse/EmptyMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -0,0 +1,5 @@
public class Test {
// COMPLIANT: allow empty method in test class
public void f() {
}
}

View File

@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args -cp ${testdir}/../../stubs/aspectj