mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
Merge pull request #18947 from tamasvajk/tamasvajk/java_empty_method
Java: Add new quality query to detect empty methods
This commit is contained in:
54
java/ql/test/query-tests/EmptyMethod/Class1.java
Normal file
54
java/ql/test/query-tests/EmptyMethod/Class1.java
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
| Class1.java:16:15:16:16 | f2 | Empty method found. |
|
||||
| Class1.java:49:18:49:23 | method | Empty method found. |
|
||||
2
java/ql/test/query-tests/EmptyMethod/EmptyMethod.qlref
Normal file
2
java/ql/test/query-tests/EmptyMethod/EmptyMethod.qlref
Normal file
@@ -0,0 +1,2 @@
|
||||
query: Language Abuse/EmptyMethod.ql
|
||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
||||
5
java/ql/test/query-tests/EmptyMethod/Test.java
Normal file
5
java/ql/test/query-tests/EmptyMethod/Test.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public class Test {
|
||||
// COMPLIANT: allow empty method in test class
|
||||
public void f() {
|
||||
}
|
||||
}
|
||||
1
java/ql/test/query-tests/EmptyMethod/options
Normal file
1
java/ql/test/query-tests/EmptyMethod/options
Normal file
@@ -0,0 +1 @@
|
||||
//semmle-extractor-options: --javac-args -cp ${testdir}/../../stubs/aspectj
|
||||
Reference in New Issue
Block a user