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

SONARJAVA-4446 Check if the parent class or implemented interface symbols of the test class are known. #4956

Merged
merged 10 commits into from
Dec 10, 2024

Conversation

erwan-serandour
Copy link
Contributor

@erwan-serandour erwan-serandour commented Dec 9, 2024

SONARJAVA-4446

If any symbol is not known, do not raise an issue to avoid false positives.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title SONARJAVA-4446 Check if the parent class or implemented interface symbols of the test class are known. SONARJAVA-4446 Check if the parent class or implemented interface symbols of the test class are known. Dec 9, 2024
@erwan-serandour erwan-serandour force-pushed the erwan/S2187_SONARJAVA-4446 branch from ce3965a to 1d1b1c7 Compare December 9, 2024 15:54
@@ -21,6 +21,18 @@
import com.googlecode.zohhak.api.TestWith;
import com.googlecode.zohhak.api.runners.ZohhakRunner;

class SubclassTest extends ParentTestClass { // Compliant, we cannot know what is in ParentTestClass so we don't raise issues

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the name so it suggests that the class is not defined, for example, UndefinedParentTestClass?

}

abstract class ResolvedParent {}
class Subclass4Test extends ResolvedParent {} // Noncompliant

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a good reason to put this new block at the beginning of the file. Could we move it towards the end?

@@ -78,7 +79,16 @@ private void resetAnnotationCache() {
}

private void checkClass(ClassTree classTree) {
if (!ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.ABSTRACT)) {
boolean knownParent = Optional.ofNullable(classTree.superClass())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more typical way of doing this would be to define private static knownParent(...) and use if in if-then. Same for knownImplementedInterfaces. You could even put this new check into one method.

@erwan-serandour erwan-serandour merged commit 889e741 into master Dec 10, 2024
15 of 16 checks passed
@erwan-serandour erwan-serandour deleted the erwan/S2187_SONARJAVA-4446 branch December 10, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants