-
Notifications
You must be signed in to change notification settings - Fork 297
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
DEPRECATED_API_SHOULD_NOT_BE_USED has false positive if a user doesn't actually use deprecated features #1333
Comments
I can reproduce your finding. The generated bytecode only has the annotation `JsonSerialize` using `ToStringSerializer`
but the rule fails with:
I think this is because |
I expect, that it would check actual usage, as name suggests. Jackson is a very stable library, where deprecation can be for years before actually removed. This renders ArchUnit to conflict with quite popular Jackson library. Is there's a way to ignore this particular field without adding archunit to production code and without changing code generation process? |
Don't get me wrong: I see your point and agree that Jackson and As a workaround, you can "fork" the predefined rule in your own code and whitelist that val deprecatedApiShouldNotBeUsed = noClasses()
.should(accessTargetWhere(target(annotatedWith(Deprecated::class.java))).`as`("access @Deprecated members"))
.orShould(
dependOnClassesThat(
+ not(equivalentTo(JsonSerialize.Inclusion::class.java)).and( // workaround for ArchUnit#1333
annotatedWith(Deprecated::class.java)
+ )
.`as`("depend on @Deprecated classes")
)
) FYI: I'm using the following imports:import com.tngtech.archunit.base.DescribedPredicate.not
import com.tngtech.archunit.core.domain.JavaAccess.Predicates.target
import com.tngtech.archunit.core.domain.JavaClass.Predicates.equivalentTo
import com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith
import com.tngtech.archunit.lang.conditions.ArchConditions.accessTargetWhere
import com.tngtech.archunit.lang.conditions.ArchConditions.dependOnClassesThat
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses |
FYI: Only the additional condition "should not depend on @Deprecated
class DeprecatedClass {
int target;
void target() {
}
}
class Origin {
@DeprecatedAnnotation
void origin() {
DeprecatedClass instanceOfDeprecatedClass = new DeprecatedClass();
instanceOfDeprecatedClass.target++;
instanceOfDeprecatedClass.target();
Class<?> deprecatedClass = DeprecatedClass.class;
}
} We need to wrap our head around the question whether it's fair to say that we depend on a deprecated class when we use an annotation that has deprecated members. Probably the dependencies from annotations needs to be revised here. |
Thank you for your response. |
Hi,
I've found interesting false-positive example, where
DEPRECATED_API_SHOULD_NOT_BE_USED
trows an exception, while I don't actually use a deprecated feature.Minimal example is below, it's in Kotlin.
There archunit found that
JsonSerialize
annotation has a deprecated field (include
), but I don't use it directly, so this code should not violate the check.Jackson version is
2.17.2
archunit version is
1.3.0
Java version: 17
The text was updated successfully, but these errors were encountered: