From 75eb133620d5aa7f7e8a59f5129b273326ae29be Mon Sep 17 00:00:00 2001 From: Marco Kaufmann <83189575+kaufco@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:31:51 +0200 Subject: [PATCH] Enable S1197, S1220, S1223, S1488, S1598, S3008 on Test code (#4821) --- .../sonar/it/java/suite/SonarLintTest.java | 4 +- .../commons-beanutils/java-S1197.json | 160 ++++++++++++++++++ .../commons-beanutils/java-S1488.json | 20 +++ .../java-S1488.json | 3 + .../java-S3008.json | 19 +++ .../resources/eclipse-jetty/java-S1488.json | 9 + .../resources/eclipse-jetty/java-S3008.json | 62 +++++++ .../resources/sonar-server/java-S1488.json | 17 ++ .../resources/sonar-server/java-S3008.json | 78 +++++++++ .../org/sonar/plugins/java/CheckList.java | 12 +- 10 files changed, 377 insertions(+), 7 deletions(-) create mode 100644 its/ruling/src/test/resources/sonar-server/java-S1488.json diff --git a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SonarLintTest.java b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SonarLintTest.java index bc81f851be9..911ee749d36 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SonarLintTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/java/suite/SonarLintTest.java @@ -126,7 +126,9 @@ public void simpleTestFileJava() throws Exception { // Issues reported by S1607 are no longer expected here as the check requires complete semantic to run properly. assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly( // tuple("squid:S2970", 6, inputFile.getPath(), "BLOCKER"), - tuple("java:S2925", 7, inputFile.getPath(), IssueSeverity.MAJOR)); + tuple("java:S2925", 7, inputFile.getPath(), IssueSeverity.MAJOR), + // expected issue + tuple("java:S1220", null, inputFile.getPath(), IssueSeverity.MINOR)); } @Test diff --git a/its/ruling/src/test/resources/commons-beanutils/java-S1197.json b/its/ruling/src/test/resources/commons-beanutils/java-S1197.json index 8a506420e1a..0978f1455bf 100644 --- a/its/ruling/src/test/resources/commons-beanutils/java-S1197.json +++ b/its/ruling/src/test/resources/commons-beanutils/java-S1197.json @@ -6,4 +6,164 @@ "commons-beanutils:commons-beanutils:src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java": [ 104 ], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/BasicDynaBeanTestCase.java": [ +113, +115, +136, +139, +285, +287, +983, +984 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/BeanUtilsTestCase.java": [ +77, +233, +239, +245, +296, +302, +362, +368, +374, +437, +438, +444, +679, +681, +1334, +1335, +1337, +1559, +1559 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java": [ +100, +205, +218, +219, +220, +221, +222, +223, +278, +280, +282, +287, +290, +304, +305, +306, +493, +494, +496, +679, +684, +694, +699 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java": [ +59, +120, +122, +124, +151, +154, +244, +250, +256, +320, +326, +332, +385, +391, +451, +457, +463, +530, +532, +538, +565, +566, +572, +1111, +1112, +1114, +1205, +1205, +1234, +1235 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java": [ +53, +115, +117, +148, +151, +226, +232, +2611, +2612 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/DynaResultSetTestCase.java": [ +51, +153 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java": [ +54, +156 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/NestedTestBean.java": [ +72 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/PropertyUtilsTestCase.java": [ +132, +294, +300, +571, +574, +1714, +1715, +1903, +3989, +3992, +4046, +4050 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/TestBean.java": [ +229, +243 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/TestResultSet.java": [ +754, +760 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/TestResultSetMetaData.java": [ +46 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/locale/LocaleConvertUtilsTestCase.java": [ +110, +249, +262, +263, +264, +265, +266, +267, +324, +326, +328, +333, +336, +351, +352, +353, +547, +548, +550, +644, +649, +659, +664 +] } diff --git a/its/ruling/src/test/resources/commons-beanutils/java-S1488.json b/its/ruling/src/test/resources/commons-beanutils/java-S1488.json index 63a28e3c7ca..44950c34791 100644 --- a/its/ruling/src/test/resources/commons-beanutils/java-S1488.json +++ b/its/ruling/src/test/resources/commons-beanutils/java-S1488.json @@ -9,4 +9,24 @@ 528, 570 ], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/BasicDynaBeanTestCase.java": [ +986 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java": [ +181, +208, +226 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java": [ +1237 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java": [ +2614 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/bugs/Jira347TestCase.java": [ +150 +], +"commons-beanutils:commons-beanutils:src/test/java/org/apache/commons/beanutils2/memoryleaktests/MemoryLeakTestCase.java": [ +528 +] } diff --git a/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S1488.json b/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S1488.json index a98ad66bfa0..d09c0cd6bc1 100644 --- a/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S1488.json +++ b/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S1488.json @@ -14,4 +14,7 @@ 187, 194 ], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/HttpOutputTest.java": [ +177 +] } diff --git a/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S3008.json b/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S3008.json index be3cdf6dce0..ce547cec8e3 100644 --- a/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S3008.json +++ b/its/ruling/src/test/resources/eclipse-jetty-similar-to-main/java-S3008.json @@ -5,6 +5,9 @@ "org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/QuotedQualityCSV.java": [ 50 ], +"org.eclipse.jetty:jetty-project:jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java": [ +67 +], "org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java": [ 69 ], @@ -26,4 +29,20 @@ "org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java": [ 46 ], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java": [ +329 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java": [ +40, +53 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java": [ +57, +64, +71, +78, +85, +92, +99 +] } diff --git a/its/ruling/src/test/resources/eclipse-jetty/java-S1488.json b/its/ruling/src/test/resources/eclipse-jetty/java-S1488.json index 73abf7478be..d06ea2fdc0c 100644 --- a/its/ruling/src/test/resources/eclipse-jetty/java-S1488.json +++ b/its/ruling/src/test/resources/eclipse-jetty/java-S1488.json @@ -14,7 +14,16 @@ 187, 194 ], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/HttpOutputTest.java": [ +177 +], "org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarResource.java": [ 131 +], +"org.eclipse.jetty:jetty-project:jetty-util/src/test/java/org/eclipse/jetty/util/RolloverFileOutputStreamTest.java": [ +53 +], +"org.eclipse.jetty:jetty-project:jetty-util/src/test/java/org/eclipse/jetty/util/ssl/X509Test.java": [ +93 ] } diff --git a/its/ruling/src/test/resources/eclipse-jetty/java-S3008.json b/its/ruling/src/test/resources/eclipse-jetty/java-S3008.json index afe12c29378..b6cb68f4e4b 100644 --- a/its/ruling/src/test/resources/eclipse-jetty/java-S3008.json +++ b/its/ruling/src/test/resources/eclipse-jetty/java-S3008.json @@ -5,6 +5,9 @@ "org.eclipse.jetty:jetty-project:jetty-http/src/main/java/org/eclipse/jetty/http/QuotedQualityCSV.java": [ 50 ], +"org.eclipse.jetty:jetty-project:jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java": [ +67 +], "org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java": [ 69 ], @@ -26,6 +29,56 @@ "org.eclipse.jetty:jetty-project:jetty-server/src/main/java/org/eclipse/jetty/server/handler/gzip/GzipHttpOutputInterceptor.java": [ 46 ], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java": [ +329 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java": [ +40, +53 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java": [ +57, +64, +71, +78, +85, +92, +99 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java": [ +59, +60, +61 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/handler/BufferedResponseHandlerTest.java": [ +46, +47, +48, +49, +50, +51 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerGetResourceTest.java": [ +51 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/handler/InetAccessHandlerTest.java": [ +49, +50, +51, +52 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/handler/ResourceHandlerTest.java": [ +69, +70, +71, +72, +73, +74, +75 +], +"org.eclipse.jetty:jetty-project:jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSelectChannelTimeoutTest.java": [ +35 +], "org.eclipse.jetty:jetty-project:jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggingServiceProvider.java": [ 35 ], @@ -73,5 +126,14 @@ ], "org.eclipse.jetty:jetty-project:jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java": [ 51 +], +"org.eclipse.jetty:jetty-project:jetty-util/src/test/java/org/eclipse/jetty/util/ScannerTest.java": [ +50, +51, +52, +53 +], +"org.eclipse.jetty:jetty-project:jetty-xml/src/test/java/org/eclipse/jetty/xml/TestConfiguration.java": [ +35 ] } diff --git a/its/ruling/src/test/resources/sonar-server/java-S1488.json b/its/ruling/src/test/resources/sonar-server/java-S1488.json new file mode 100644 index 00000000000..92cbedd4765 --- /dev/null +++ b/its/ruling/src/test/resources/sonar-server/java-S1488.json @@ -0,0 +1,17 @@ +{ +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java": [ +207 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoImplTest.java": [ +132 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/issue/ws/AssignActionTest.java": [ +268 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java": [ +120 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesActionTest.java": [ +65 +] +} diff --git a/its/ruling/src/test/resources/sonar-server/java-S3008.json b/its/ruling/src/test/resources/sonar-server/java-S3008.json index 48839285013..2c5376b5940 100644 --- a/its/ruling/src/test/resources/sonar-server/java-S3008.json +++ b/its/ruling/src/test/resources/sonar-server/java-S3008.json @@ -2,4 +2,82 @@ "org.sonarsource.sonarqube:sonar-server:src/main/java/org/sonar/server/platform/web/MasterServletFilter.java": [ 44 ], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/authentication/IdentityProviderRepositoryTest.java": [ +36, +41, +46 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/authentication/UserIdentityAuthenticatorTest.java": [ +59, +61, +68 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/batch/IssuesActionTest.java": [ +77 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java": [ +36 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/duplication/CrossProjectDuplicationStatusHolderImplTest.java": [ +33 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/issue/TrackerRawInputFactoryTest.java": [ +52, +54, +55 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CommentDensityRuleTest.java": [ +46, +48 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/CoverageRuleTest.java": [ +45 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/DuplicatedBlockRuleTest.java": [ +45, +47 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/SkippedTestRuleTest.java": [ +45, +47 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/issue/commonrule/TestErrorRuleTest.java": [ +45, +47 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/computation/task/projectanalysis/step/ValidateProjectStepTest.java": [ +45 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/es/EsServerHolder.java": [ +39 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java": [ +90 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/notification/NotificationDaemonTest.java": [ +48, +49, +50 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/organization/BillingValidationsProxyImplTest.java": [ +34, +35 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java": [ +69, +70, +71 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java": [ +61, +62, +63 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java": [ +74 +], +"org.sonarsource.sonarqube:sonar-server:src/test/java/org/sonar/server/user/ws/IdentityProvidersActionTest.java": [ +37, +46 +] } diff --git a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/CheckList.java b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/CheckList.java index e0cf9f14635..0b08c589901 100644 --- a/sonar-java-plugin/src/main/java/org/sonar/plugins/java/CheckList.java +++ b/sonar-java-plugin/src/main/java/org/sonar/plugins/java/CheckList.java @@ -707,7 +707,6 @@ public final class CheckList { AnnotationDefaultArgumentCheck.class, ArrayCopyLoopCheck.class, ArrayDesignatorAfterTypeCheck.class, - ArrayDesignatorOnVariableCheck.class, ArrayForVarArgCheck.class, ArrayHashCodeAndToStringCheck.class, ArraysAsListOfPrimitiveToStreamCheck.class, @@ -730,7 +729,6 @@ public final class CheckList { AwsRegionSetterCheck.class, AwsRegionShouldBeSetExplicitlyCheck.class, AwsReusableResourcesInitializedOnceCheck.class, - BadFieldNameStaticNonFinalCheck.class, BadLocalConstantNameCheck.class, BadMethodNameCheck.class, BasicAuthCheck.class, @@ -1210,7 +1208,6 @@ public final class CheckList { CollectionIsEmptyCheck.class, CompareObjectWithEqualsCheck.class, StringConcatenationInLoopCheck.class, - ImmediatelyReturnedVariableCheck.class, DisallowedThreadGroupCheck.class, ClassVariableVisibilityCheck.class, PublicStaticFieldShouldBeFinalCheck.class, @@ -1226,7 +1223,6 @@ public final class CheckList { CollectionsEmptyConstantsCheck.class, CompareStringsBoxedTypesWithEqualsCheck.class, FieldNameMatchingTypeNameCheck.class, - DefaultPackageCheck.class, SunPackagesUsedCheck.class, ConcatenationWithStringValueOfCheck.class, EmptyFileCheck.class, @@ -1236,13 +1232,11 @@ public final class CheckList { CastArithmeticOperandCheck.class, NestedBlocksCheck.class, HardcodedIpCheck.class, - MismatchPackageDirectoryCheck.class, UselessPackageInfoCheck.class, BadPackageNameCheck.class, RepeatAnnotationCheck.class, OctalValuesCheck.class, DuplicateConditionIfElseIfCheck.class, - MethodNameSameAsClassCheck.class, IndentationAfterConditionalCheck.class, RawByteBitwiseOperationsCheck.class, StringBufferAndBuilderWithCharCheck.class, @@ -1304,8 +1298,10 @@ public final class CheckList { UnusedTestRuleCheck.class); private static final List> JAVA_MAIN_AND_TEST_CHECKS = Arrays.asList( + ArrayDesignatorOnVariableCheck.class, BadConstantNameCheck.class, BadFieldNameCheck.class, + BadFieldNameStaticNonFinalCheck.class, BadInterfaceNameCheck.class, BadLocalVariableNameCheck.class, BadTypeParameterNameCheck.class, @@ -1315,11 +1311,15 @@ public final class CheckList { CollectorsToListCheck.class, CommentedOutCodeLineCheck.class, DeadStoreCheck.class, + DefaultPackageCheck.class, EmptyBlockCheck.class, FixmeTagPresenceCheck.class, HiddenFieldCheck.class, + ImmediatelyReturnedVariableCheck.class, LambdaOptionalParenthesisCheck.class, MethodIdenticalImplementationsCheck.class, + MethodNameSameAsClassCheck.class, + MismatchPackageDirectoryCheck.class, PrintfMisuseCheck.class, RedundantThrowsDeclarationCheck.class, ReplaceGuavaWithJavaCheck.class,