Repository: detekt/detekt (kotlin)

Issue:
False-positive OutdatedDocumentation for generic parameters
<!-- The bug you're experiencing might have already be reported! -->
<!-- Please search in the [issues](https://github.com/detekt/detekt/issues) before creating one. -->

## Expected Behavior
<!-- Tell us what should happen -->
`@param T` supported for generic type documentation

## Observed Behavior
<!-- Tell us what happens instead of the expected behavior -->
`@param T` is reported as a false positive
`Documentation of JsonObject is outdated [OutdatedDocumentation]`

## Steps to Reproduce
<!-- Provide a link to a live example, or an unambiguous set of steps to -->
<!-- reproduce this bug. Include code to reproduce, if relevant -->
Run detekt with `OutdatedDocumentation` rule enabled on this code
```kotlin
/**
 * Some interesting description
 * @param T value type
 */
public abstract class Test<T : Any>
```

## Context
<!-- How has this issue affected you? What are you trying to accomplish? -->
<!-- Providing context helps us come up with a solution that is most useful in the real world -->

## Your Environment
<!-- Include as many relevant details about the environment you experienced the bug in -->
* Version of detekt used: 1.20.0
* Version of Gradle used (if applicable): 7.4
* Gradle scan link (add `--scan` option when running the gradle task):
* Operating System and version: Linux/Fedora 35
* Link to your project (if it's a public repository): https://github.com/mpetuska/npm-publish

Pull request description:
Fixes #4727

Patch:
diff --git a/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentation.kt b/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentation.kt
index 71a8f665319c..f6fd27d969ec 100644
--- a/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentation.kt
+++ b/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentation.kt
@@ -95,8 +95,8 @@ class OutdatedDocumentation(config: Config = Config.empty) : Rule(config) {
     }
 
     private fun getClassDeclarations(klass: KtClass): List<Declaration> {
-        val ctor = klass.primaryConstructor ?: return emptyList()
-        val constructorDeclarations = getPrimaryConstructorDeclarations(ctor)
+        val ctor = klass.primaryConstructor
+        val constructorDeclarations = if (ctor != null) getPrimaryConstructorDeclarations(ctor) else emptyList()
         val typeParams = if (matchTypeParameters) {
             klass.typeParameters.mapNotNull { it.name.toParamOrNull() }
         } else emptyList()


Test patch:
diff --git a/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentationSpec.kt b/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentationSpec.kt
index c36753b159af..feb78e40e859 100644
--- a/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentationSpec.kt
+++ b/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/OutdatedDocumentationSpec.kt
@@ -171,6 +171,18 @@ class OutdatedDocumentationSpec {
                 assertThat(subject.compileAndLint(correctTypeParam)).isEmpty()
             }
 
+            @Test
+            fun `should not report when doc match class params and no primary constructor`() {
+                val correctTypeParam = """
+                /**
+                 * Some description
+                 * @param T Description of type param
+                 */
+                class MyClass<T>
+                """
+                assertThat(subject.compileAndLint(correctTypeParam)).isEmpty()
+            }
+
             @Test
             fun `should report when doc misses type param`() {
                 val missingTypeParam = """