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

Animalsniffer check #771

Merged
merged 9 commits into from
Jan 28, 2025

Conversation

LikeTheSalad
Copy link
Contributor

Closes #770

Follow-up for #701

@LikeTheSalad LikeTheSalad requested a review from a team as a code owner January 27, 2025 17:45
@breedx-splk
Copy link
Contributor

Also supersedes #768

@@ -1,58 +0,0 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, I guess this was cruft just left over from a previous rename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The convention configs for animalsniffer checks on plain Java libs are slightly different than for Android libs, for a moment I thought about adding all that config in a separate convention file and so on, but then I realized that the plain Java lib conventions aren't used anywhere right now, so it seems like it's better to just remove them instead of making this PR bigger by adding all that other config that's not needed right now.

@@ -77,7 +78,15 @@ public static int replacementForContentLength(URLConnection connection) {
}

public static long replacementForContentLengthLong(URLConnection connection) {
return replace(connection, () -> connection.getContentLengthLong());
return replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, did this catch one already then!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the method getContentLengthLong() is available starting from API 24 so animalsniffer complains about it because our min is 21. However, for this particular case, this method is guaranteed to be called on apps with at least min API 24 so there's no need to address it, so to disable animalsniffer for this case only we have to annotate the class/method/field with @RequiresApi where this call is made, and I tried first to annotate the parent method replacementForContentLengthLong, though that didn't work, because the call to getContentLengthLong() was made in a lambda and it seems like animalsniffer doesn't check those scenarios, so for it to work I had to turn the lambda into an anonymous class and then annotate the actual method inside where the call to getContentLengthLong() is made.

@breedx-splk breedx-splk merged commit c39efb3 into open-telemetry:main Jan 28, 2025
3 checks passed
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.

Add animal sniffer check
3 participants