Skip to content

Commit

Permalink
Merge pull request #4100 from square/jw.animal.2024-03-18
Browse files Browse the repository at this point in the history
Re-enable Animal Sniffer on all JVMs
  • Loading branch information
JakeWharton committed Mar 18, 2024
2 parents 87e0c81 + 97b0632 commit 98b02b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
26 changes: 11 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import net.ltgt.gradle.errorprone.CheckSeverity
import org.gradle.internal.jvm.Jvm

buildscript {
dependencies {
Expand Down Expand Up @@ -66,21 +65,18 @@ subprojects {
}

plugins.withId('java-library') {
// Animal Sniffer only works on JDK 11 or older currently.
if (!Jvm.current().javaVersion.isJava12Compatible()) {
project.apply plugin: 'ru.vyarus.animalsniffer'
animalsniffer {
sourceSets = [sourceSets.main] // Only check main sources, ignore test code.
}
dependencies {
signature 'org.codehaus.mojo.signature:java18:1.0@signature'
project.apply plugin: 'ru.vyarus.animalsniffer'
animalsniffer {
sourceSets = [sourceSets.main] // Only check main sources, ignore test code.
}
dependencies {
signature 'org.codehaus.mojo.signature:java18:1.0@signature'

if (project.path != ':retrofit-converters:java8' &&
project.path != ':retrofit-converters:jaxb' &&
project.path != ':retrofit-converters:jaxb3' &&
project.path != ':retrofit-adapters:java8') {
signature 'net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature'
}
if (project.path != ':retrofit-converters:java8' &&
project.path != ':retrofit-converters:jaxb' &&
project.path != ':retrofit-converters:jaxb3' &&
project.path != ':retrofit-adapters:java8') {
signature 'net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature'
}
}

Expand Down
2 changes: 2 additions & 0 deletions retrofit/src/main/java/retrofit2/DefaultMethodSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import javax.annotation.Nullable;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;

/**
* From Java 8 to Java 13, the only way to invoke a default method on a proxied interface is by
Expand All @@ -29,6 +30,7 @@
final class DefaultMethodSupport {
private static @Nullable Constructor<Lookup> lookupConstructor;

@IgnoreJRERequirement // Only used on JVM or Android API 24+.
@Nullable
static Object invoke(
Method method, Class<?> declaringClass, Object proxy, @Nullable Object[] args)
Expand Down
3 changes: 3 additions & 0 deletions retrofit/src/main/java/retrofit2/Reflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import javax.annotation.Nullable;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;

class Reflection {
boolean isDefaultMethod(Method method) {
Expand All @@ -37,6 +38,7 @@ String describeMethodParameter(Method method, int index) {
return "parameter #" + (index + 1);
}

@IgnoreJRERequirement // Only used on JVM.
static class Java8 extends Reflection {
@Override
boolean isDefaultMethod(Method method) {
Expand Down Expand Up @@ -67,6 +69,7 @@ String describeMethodParameter(Method method, int index) {
* through the proxy, was not added until API 26.
*/
@TargetApi(24)
@IgnoreJRERequirement // Only used on Android API 24+.
static final class Android24 extends Reflection {
@Override
boolean isDefaultMethod(Method method) {
Expand Down

0 comments on commit 98b02b7

Please sign in to comment.