Subclass opt-in without markers
| Diagnostic | SUBCLASS_OPT_IN_WITHOUT_MARKERS |
| Default severity | Error |
| Gradle property | subclassOptInWithoutMarkers |
| Exemption | none, replace with @IntentionallyOpen |
What it reports
A markerless @SubclassOptInRequired on a class or interface in the public API
that external classes can subclass.
@SubclassOptInRequiredpublic abstract class ExtensionPoint
Rationale
Without a marker class, @SubclassOptInRequired doesn't restrict subclassing.
External subclasses can depend on the API without an opt-in to future changes.
Don't
@SubclassOptInRequiredpublic abstract class Connector
Do
@RequiresOptInpublic annotation class UnstableApi@SubclassOptInRequired(UnstableApi::class)public abstract class Connector
Notes
- Final classes, classes whose constructors are all
internalorprivate, and sealed types aren't reported. - The annotation can list more than one marker class.
@PublishedApi internaltypes aren't reported.- To keep unrestricted subclassing for compatibility, replace
@SubclassOptInRequiredwith@IntentionallyOpen. TheexemptExistingApitask makes this replacement.
Configuration
build.gradle.kts
apiWatchdog {subclassOptInWithoutMarkers = WatchdogSeverity.ERROR}
For a direct compiler call:
-P plugin:org.jetbrains.kotlinx.library.api.watchdog:diagnosticSeverity=SUBCLASS_OPT_IN_WITHOUT_MARKERS:error