diff --git a/core/src/main/java/feign/Contract.java b/core/src/main/java/feign/Contract.java index 41e4fd88a5..b71fe5782e 100644 --- a/core/src/main/java/feign/Contract.java +++ b/core/src/main/java/feign/Contract.java @@ -22,7 +22,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.lang.reflect.Parameter; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.net.URI; @@ -319,11 +318,8 @@ public Default() { Param.class, (paramAnnotation, data, paramIndex) -> { final String annotationName = paramAnnotation.value(); - final Parameter parameter = data.method().getParameters()[paramIndex]; - final String name; - if (emptyToNull(annotationName) == null && parameter.isNamePresent()) { - name = parameter.getName(); - } else { + String name = ""; + if (emptyToNull(annotationName) != null) { name = annotationName; } checkState( diff --git a/core/src/main/java/feign/DeclarativeContract.java b/core/src/main/java/feign/DeclarativeContract.java index f455fd9b39..5755630cd5 100644 --- a/core/src/main/java/feign/DeclarativeContract.java +++ b/core/src/main/java/feign/DeclarativeContract.java @@ -18,7 +18,6 @@ import feign.Contract.BaseContract; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.lang.reflect.Parameter; import java.util.*; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -135,9 +134,7 @@ protected final boolean processAnnotationsOnParameter( .process(annotation, data, paramIndex)); } else { - final Parameter parameter = data.method().getParameters()[paramIndex]; - String parameterName = - parameter.isNamePresent() ? parameter.getName() : parameter.getType().getSimpleName(); + String parameterName = data.method().getParameterTypes()[paramIndex].getSimpleName(); if (annotations.length == 0) { data.addWarning( String.format( diff --git a/core/src/main/java/feign/DefaultMethodHandler.java b/core/src/main/java/feign/DefaultMethodHandler.java index 7f1df4581c..2dea8a32e2 100644 --- a/core/src/main/java/feign/DefaultMethodHandler.java +++ b/core/src/main/java/feign/DefaultMethodHandler.java @@ -38,17 +38,18 @@ final class DefaultMethodHandler implements MethodHandler { private MethodHandle handle; public DefaultMethodHandler(Method defaultMethod) { - Class declaringClass = defaultMethod.getDeclaringClass(); - - try { - Lookup lookup = readLookup(declaringClass); - this.unboundHandle = lookup.unreflectSpecial(defaultMethod, declaringClass); - } catch (NoSuchFieldException - | IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { - throw new IllegalStateException(ex); - } + this.unboundHandle = null; + // Class declaringClass = defaultMethod.getDeclaringClass(); + // + // try { + // Lookup lookup = readLookup(declaringClass); + // this.unboundHandle = lookup.unreflectSpecial(defaultMethod, declaringClass); + // } catch (NoSuchFieldException + // | IllegalAccessException + // | IllegalArgumentException + // | InvocationTargetException ex) { + // throw new IllegalStateException(ex); + // } } private Lookup readLookup(Class declaringClass) @@ -126,11 +127,11 @@ private Lookup legacyReadLookup() throws NoSuchFieldException, IllegalAccessExce * DefaultMethodHandler */ public void bindTo(Object proxy) { - if (handle != null) { - throw new IllegalStateException( - "Attempted to rebind a default method handler that was already bound"); - } - handle = unboundHandle.bindTo(proxy); + // if (handle != null) { + // throw new IllegalStateException( + // "Attempted to rebind a default method handler that was already bound"); + // } + // handle = unboundHandle.bindTo(proxy); } /** diff --git a/core/src/main/java/feign/Util.java b/core/src/main/java/feign/Util.java index 99b56683df..341599bfd9 100644 --- a/core/src/main/java/feign/Util.java +++ b/core/src/main/java/feign/Util.java @@ -121,6 +121,33 @@ public static void checkState( /** Identifies a method as a default instance method. */ public static boolean isDefault(Method method) { + // Check for Android's desugar of default methods. + try { + String name = method.getDeclaringClass().getName() + "$-CC"; + Class clazz = Class.forName(name, false, method.getDeclaringClass().getClassLoader()); + java.lang.reflect.Method[] methods = clazz.getDeclaredMethods(); + for (java.lang.reflect.Method m : methods) { + // The companion method will take the class as the first argument and then the rest of the + // original arguments + if (!m.getName().startsWith("$default$" + method.getName()) + || m.getParameterCount() != method.getParameterCount() + 1) continue; + + boolean paramsMatch = true; + Class[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + if (!parameterTypes[i].equals(m.getParameterTypes()[i + 1])) { + paramsMatch = false; + break; + } + } + if (!paramsMatch) continue; + + return true; + } + } catch (ClassNotFoundException e) { + // Ignore + } + // Default methods are public non-abstract, non-synthetic, and non-static instance methods // declared in an interface. // method.isDefault() is not sufficient for our usage as it does not check diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000000..e9bf556b5c --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,20 @@ +# +# Copyright © 2012 The Feign Authors (feign@commonhaus.dev) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +jdk: + - openjdk21 +install: + - ./mvnw install -pl core -am -DskipTests diff --git a/pom.xml b/pom.xml index 42097ee5bf..a69c92e564 100644 --- a/pom.xml +++ b/pom.xml @@ -1093,39 +1093,6 @@ - - org.apache.maven.plugins - maven-toolchains-plugin - 3.2.0 - - - - toolchain - - - - - ${main.java.version} - - - - - - test - - toolchain - - generate-test-sources - - - - ${latest.java.version} - - - - - - org.apache.maven.plugins maven-surefire-plugin