Skip to content

Commit d4b2ec0

Browse files
authored
Merge branch 'main' into redsun82/rust-analyzer-update
2 parents 2a81cc9 + c8a1ad6 commit d4b2ec0

File tree

15 files changed

+507
-13
lines changed

15 files changed

+507
-13
lines changed

Diff for: .github/workflows/build-ripunzip.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [ubuntu-20.04, macos-13, windows-2019]
20+
os: [ubuntu-22.04, macos-13, windows-2019]
2121
runs-on: ${{ matrix.os }}
2222
steps:
2323
- uses: actions/checkout@v4

Diff for: go/documentation/library-coverage/coverage.csv

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ github.com/beego/beego,142,68,42,,,,68,,10,,,,,,60,4,,,,,26,,,42,,42,
3333
github.com/caarlos0/env,,5,2,,,,,,,,,,,,,,,,,,,5,,,,1,1
3434
github.com/clevergo/clevergo,1,,,,,,,,,,,,,,,,,1,,,,,,,,,
3535
github.com/codeskyblue/go-sh,4,,,4,,,,,,,,,,,,,,,,,,,,,,,
36-
github.com/couchbase/gocb,8,,18,,,,,8,,,,,,,,,,,,,,,,,,18,
37-
github.com/couchbaselabs/gocb,8,,18,,,,,8,,,,,,,,,,,,,,,,,,18,
36+
github.com/couchbase/gocb,8,22,48,,,,,8,,,,,,,,,,,,,22,,,,,48,
37+
github.com/couchbaselabs/gocb,8,22,48,,,,,8,,,,,,,,,,,,,22,,,,,48,
3838
github.com/crankycoder/xmlpath,2,,,,,,,,,,,,,,,,,,2,,,,,,,,
3939
github.com/cristalhq/jwt,1,,,,1,,,,,,,,,,,,,,,,,,,,,,
4040
github.com/davecgh/go-spew/spew,9,,,,,,9,,,,,,,,,,,,,,,,,,,,
@@ -107,7 +107,7 @@ google.golang.org/protobuf/internal/impl,,,2,,,,,,,,,,,,,,,,,,,,,,,2,
107107
google.golang.org/protobuf/proto,,,8,,,,,,,,,,,,,,,,,,,,,,,8,
108108
google.golang.org/protobuf/reflect/protoreflect,,,1,,,,,,,,,,,,,,,,,,,,,,,1,
109109
gopkg.in/Masterminds/squirrel,32,,,,,,,,,,,,,,32,,,,,,,,,,,,
110-
gopkg.in/couchbase/gocb,8,,18,,,,,8,,,,,,,,,,,,,,,,,,18,
110+
gopkg.in/couchbase/gocb,8,22,48,,,,,8,,,,,,,,,,,,,22,,,,,48,
111111
gopkg.in/glog,90,,,,,,90,,,,,,,,,,,,,,,,,,,,
112112
gopkg.in/go-jose/go-jose,3,,4,,2,1,,,,,,,,,,,,,,,,,,,,4,
113113
gopkg.in/go-xmlpath/xmlpath,2,,,,,,,,,,,,,,,,,,2,,,,,,,,

Diff for: go/documentation/library-coverage/coverage.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Go framework & library support
1010
`Afero <https://github.com/spf13/afero>`_,``github.com/spf13/afero*``,,,34
1111
`Bun <https://bun.uptrace.dev/>`_,``github.com/uptrace/bun*``,,,63
1212
`CleverGo <https://github.com/clevergo/clevergo>`_,"``clevergo.tech/clevergo*``, ``github.com/clevergo/clevergo*``",,,2
13-
`Couchbase official client(gocb) <https://github.com/couchbase/gocb>`_,"``github.com/couchbase/gocb*``, ``gopkg.in/couchbase/gocb*``",,36,16
14-
`Couchbase unofficial client <http://www.github.com/couchbase/go-couchbase>`_,``github.com/couchbaselabs/gocb*``,,18,8
13+
`Couchbase official client(gocb) <https://github.com/couchbase/gocb>`_,"``github.com/couchbase/gocb*``, ``gopkg.in/couchbase/gocb*``",44,96,16
14+
`Couchbase unofficial client <http://www.github.com/couchbase/go-couchbase>`_,``github.com/couchbaselabs/gocb*``,22,48,8
1515
`Echo <https://echo.labstack.com/>`_,``github.com/labstack/echo*``,12,2,3
1616
`Fiber <https://github.com/gofiber/fiber>`_,``github.com/gofiber/fiber*``,,,5
1717
`Fosite <https://github.com/ory/fosite>`_,``github.com/ory/fosite*``,,,2
@@ -74,5 +74,5 @@ Go framework & library support
7474
`yaml <https://gopkg.in/yaml.v3>`_,``gopkg.in/yaml*``,,9,
7575
`zap <https://go.uber.org/zap>`_,``go.uber.org/zap*``,,11,33
7676
Others,``github.com/kanikanema/gorqlite``,8,2,24
77-
Totals,,494,958,1556
77+
Totals,,560,1048,1556
7878

Diff for: java/ql/lib/semmle/code/java/UnitTests.qll

+44
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class TestClass extends Class {
6666
}
6767
}
6868

69+
/**
70+
* A class that is likely a test class. That is either a definite test class, or
71+
* a class whose name, package, or location suggests that it might be a test class.
72+
*/
73+
class LikelyTestClass extends Class {
74+
LikelyTestClass() {
75+
this instanceof TestClass or
76+
this.getName().toLowerCase().matches("%test%") or
77+
this.getPackage().getName().toLowerCase().matches("%test%") or
78+
this.getLocation().getFile().getAbsolutePath().matches("%/src/test/java%")
79+
}
80+
}
81+
6982
/**
7083
* A test method declared within a JUnit 3.8 test class.
7184
*/
@@ -185,6 +198,37 @@ class TestMethod extends Method {
185198
}
186199
}
187200

201+
/**
202+
* A method that is likely a test method.
203+
*/
204+
class LikelyTestMethod extends Method {
205+
LikelyTestMethod() {
206+
this.getDeclaringType() instanceof LikelyTestClass
207+
or
208+
this instanceof TestMethod
209+
or
210+
this instanceof LikelyJunitTest
211+
}
212+
}
213+
214+
/**
215+
* A `Method` that is public, has no parameters,
216+
* has a "void" return type, AND either has a name that starts with "test" OR
217+
* has an annotation that ends with "Test"
218+
*/
219+
class LikelyJunitTest extends Method {
220+
LikelyJunitTest() {
221+
this.isPublic() and
222+
this.getReturnType().hasName("void") and
223+
this.hasNoParameters() and
224+
(
225+
this.getName().matches("JUnit%") or
226+
this.getName().matches("test%") or
227+
this.getAnAnnotation().getType().getName().matches("%Test")
228+
)
229+
}
230+
}
231+
188232
/**
189233
* A TestNG annotation used to mark a method that runs "before".
190234
*/

Diff for: java/ql/src/Language Abuse/EmptyMethod.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Overview
2+
3+
An empty method may indicate that an implementation was intended to be provided but was accidentally omitted. When using the method, it will not be clear that it does not provide an implementation and with dynamic dispatch, resolving to a blank method may result in unexpected program behavior.
4+
5+
## Recommendation
6+
7+
If a method is intended to be left empty, do one of the following to indicate that it is intentionally empty:
8+
1. Mark it abstract in an abstract class
9+
2. Place it in an interface (then it can be implicitly abstract)
10+
3. Place a comment in that method that lets others know that the implementation was intentionally omitted
11+
4. Add `UnsupportedOperationException` to the method (as in `java.util.Collection.add`).
12+
13+
## Example
14+
15+
```java
16+
public class Test {
17+
public void f1() { // COMPLIANT
18+
// intentionally empty
19+
}
20+
21+
public void f2() {} // NON_COMPLIANT
22+
23+
public void f3(){ throw new UnsupportedOperationException(); } // COMPLIANT
24+
25+
public abstract class TestInner {
26+
27+
public abstract void f(); // COMPLIANT - intentionally empty
28+
}
29+
30+
}
31+
```
32+
33+
## Implementation Notes
34+
35+
The rule excludes reporting methods that are annotated.
36+
37+
## References
38+
- Java SE Documentation: [java.util.Collection.add](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/Collection.html#add(E)).
39+
- Wikipedia: [Template method pattern](https://en.wikipedia.org/wiki/Template_method_pattern).
40+
- Common Weakness Enumeration: [CWE-1071](https://cwe.mitre.org/data/definitions/1071.html).

Diff for: java/ql/src/Language Abuse/EmptyMethod.ql

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @id java/empty-method
3+
* @name Empty method
4+
* @description An empty method serves no purpose and makes code less readable. An empty method may
5+
* indicate an error on the part of the developer.
6+
* @kind problem
7+
* @precision medium
8+
* @problem.severity recommendation
9+
* @tags correctness
10+
* maintainability
11+
* readability
12+
* quality
13+
* external/cwe/cwe-1071
14+
*/
15+
16+
import java
17+
18+
/**
19+
* A `Method` from source that is not abstract, and likely not a test method
20+
*/
21+
class NonAbstractSource extends Method {
22+
NonAbstractSource() {
23+
this.fromSource() and
24+
not this.isAbstract() and
25+
not this instanceof LikelyTestMethod
26+
}
27+
}
28+
29+
from NonAbstractSource m
30+
where
31+
//empty
32+
not exists(m.getBody().getAChild()) and
33+
//permit comment lines explaining why this is empty
34+
m.getNumberOfCommentLines() = 0 and
35+
//permit a javadoc above as well as sufficient reason to leave empty
36+
not exists(m.getDoc().getJavadoc()) and
37+
//annotated methods are considered compliant
38+
not exists(m.getAnAnnotation()) and
39+
//native methods have no body
40+
not m.isNative()
41+
select m, "Empty method found."

Diff for: java/ql/src/change-notes/2025-03-10-empty-method.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: newQuery
3+
---
4+
* Added a new quality query, `java/empty-method`, to detect empty methods.

Diff for: java/ql/src/experimental/Security/CWE/CWE-489/TestLib.qll

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,4 @@ import java
1010
* c) in a test class whose name has the word `test`
1111
* d) in a test class implementing a test framework such as JUnit or TestNG
1212
*/
13-
predicate isTestMethod(Method m) {
14-
m.getDeclaringType().getName().toLowerCase().matches("%test%") or // Simple check to exclude test classes to reduce FPs
15-
m.getDeclaringType().getPackage().getName().toLowerCase().matches("%test%") or // Simple check to exclude classes in test packages to reduce FPs
16-
exists(m.getLocation().getFile().getAbsolutePath().indexOf("/src/test/java")) or // Match test directory structure of build tools like maven
17-
m instanceof TestMethod // Test method of a test case implementing a test framework such as JUnit or TestNG
18-
}
13+
predicate isTestMethod(LikelyTestMethod m) { any() }

Diff for: java/ql/test/query-tests/EmptyMethod/Class1.java

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import org.aspectj.lang.annotation.Pointcut;
2+
3+
public class Class1 {
4+
5+
// COMPLIANT
6+
public void f() {
7+
int i = 0;
8+
}
9+
10+
// COMPLIANT
11+
public void f1() {
12+
// intentionally empty
13+
}
14+
15+
// NON_COMPLIANT
16+
public void f2() { } // $ Alert
17+
18+
// COMPLIANT - exception
19+
@Pointcut()
20+
public void f4() {
21+
}
22+
23+
/**
24+
* COMPLIANT - empty method with javadoc
25+
*/
26+
public void f5() {
27+
}
28+
29+
public abstract class TestInner {
30+
31+
public abstract void f(); // COMPLIANT - intentionally empty
32+
33+
}
34+
35+
public class Derived extends TestInner {
36+
37+
// COMPLIANT: with annotation
38+
@Override
39+
public void f() {
40+
}
41+
42+
// COMPLIANT: native
43+
public native int nativeMethod();
44+
}
45+
46+
public interface TestInterface {
47+
48+
// NON_COMPLIANT
49+
default void method() { } // $ Alert
50+
51+
void method2(); // COMPLIANT
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Class1.java:16:15:16:16 | f2 | Empty method found. |
2+
| Class1.java:49:18:49:23 | method | Empty method found. |
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Language Abuse/EmptyMethod.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

Diff for: java/ql/test/query-tests/EmptyMethod/Test.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Test {
2+
// COMPLIANT: allow empty method in test class
3+
public void f() {
4+
}
5+
}

Diff for: java/ql/test/query-tests/EmptyMethod/options

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

0 commit comments

Comments
 (0)