[ 
https://issues.apache.org/jira/browse/LANG-1773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17950706#comment-17950706
 ] 

Éamonn McManus commented on LANG-1773:
--------------------------------------

Actually, looking more closely, I don't think the code needs to reference 
{{AnnotatedType}} at all. This is what we have:

{noformat}
    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;
                }
            }
        }
        return false;
    }
{noformat}
There's no need to call {{{}getAnnotatedBounds(){}}}, since the code 
immediately calls {{getType()}} on the result. So the loop could just call 
{{typeParameter.getBounds()}} directly. I'll prototype this and send a PR if 
tests pass.

 

> 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)

Reply via email to