[ https://issues.apache.org/jira/browse/LANG-1773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17950374#comment-17950374 ]
Gary D. Gregory edited comment on LANG-1773 at 5/8/25 9:49 PM: --------------------------------------------------------------- I would not want to use reflection but what about rewriting the method to use a stream: {noformat} diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java index 3cdc9c1..ba1be44 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java @@ -16,7 +16,6 @@ */ package org.apache.commons.lang3.reflect; -import java.lang.reflect.AnnotatedType; import java.lang.reflect.Array; import java.lang.reflect.GenericArrayType; import java.lang.reflect.GenericDeclaration; @@ -34,6 +33,7 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; +import java.util.stream.Stream; import org.apache.commons.lang3.AppendableJoiner; import org.apache.commons.lang3.ArrayUtils; @@ -1361,10 +1361,9 @@ private static boolean isAssignable(final Type type, final WildcardType toWildca */ private static boolean isCyclical(final Class<?> cls) { for (final TypeVariable<?> typeParameter : cls.getTypeParameters()) { - for (final AnnotatedType annotatedBound : typeParameter.getAnnotatedBounds()) { - if (annotatedBound.getType().getTypeName().contains(cls.getName())) { - return true; - } + // Hack for LANG-1173 + if (Stream.of(typeParameter.getAnnotatedBounds()).anyMatch(bound -> bound.getType().getTypeName().contains(cls.getName()))) { + return true; } } return false; {noformat} was (Author: garydgregory): I would not want to use reflection but what about rewriting the method to use a stream? > Apache Commons Lang no longer builds on Android > ----------------------------------------------- > > Key: LANG-1773 > URL: https://issues.apache.org/jira/browse/LANG-1773 > Project: Commons Lang > Issue Type: Bug > Components: lang.reflect.* > Reporter: Éamonn McManus > Priority: Major > > Google periodically imports various open source projects into the [Google > Monorepo|https://research.google/pubs/why-google-stores-billions-of-lines-of-code-in-a-single-repository] > > [.|https://research.google/pubs/why-google-stores-billions-of-lines-of-code-in-a-single-repository/].] > When I attempted to do that for Commons Lang, I found that it no longer > builds against the Android API. The reason is that [this > commit|https://github.com/apache/commons-lang/commit/c4007c4a24eafbed53109e4b0376b4fd0ba01b56] > introduced a usage of `java.lang.reflect.AnnotatedType`, but that interface > doesn't exist on Android ([Android > `java.lang.reflect`|https://developer.android.com/reference/java/lang/reflect/package-summary]). > The open-source Commons Lang is probably not built against the Android API, > but the built artifacts get used there, and this code could lead to bizarre > runtime failures. > I was able to patch the code so that it uses reflection to access > `AnnotatedType`, and I could make a PR with that change if that is helpful. > Then if `AnnotatedType` doesn't exist, the private `TypeUtils.isCyclical` > method just returns false. Or perhaps the test for these cyclical types could > work some other way that doesn't involve `AnnotatedType`. > Alternatively, if this is unlikely to be useful to users outside Google, we > can maintain a private patch. -- This message was sent by Atlassian Jira (v8.20.10#820010)