Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Add new quality query to detect empty methods #18947

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Mar 7, 2025

This query is migrated from the advance security team's quality queries.

The initial version was somewhat modified to report fewer alerts. The changes reduce the alert count in MRVA top 100 from 16800 to 3800.

Comment on lines +16 to +20
/**
* Represents a likely a test method, which is either a method that is already
* recognized as a `TestMethod` or something that is likely a JUnit test or
* something in the expected test path for Java tests.
*/

Check warning

Code scanning / CodeQL

Class QLDoc style. Warning

The QLDoc for a class should start with 'A', 'An', or 'The'.
(
this.getName().matches("JUnit%") or
this.getName().matches("test%") or
this.getAnAnnotation().toString().matches("%Test")

Check warning

Code scanning / CodeQL

Using 'toString' in query logic Warning

Query logic depends on implementation of 'toString'.
Comment on lines +55 to +58
/**
* Maven surefire patterns to consider which files are testcases:
* https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
*/

Check warning

Code scanning / CodeQL

Class QLDoc style. Warning

The QLDoc for a class should start with 'A', 'An', or 'The'.
//permit comment lines explaining why this is empty
m.getNumberOfCommentLines() = 0 and
//permit a javadoc above as well as sufficient reason to leave empty
not exists(Javadoc jd | m.getDoc().getJavadoc() = jd) and

Check warning

Code scanning / CodeQL

Expression can be replaced with a cast Warning

The assignment in the exists(..) is redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant