[cdi-dev] [JBoss JIRA] (CDI-149) AnnotationLiteral in the CDI API does not cache the hashCode

Mark Struberg (JIRA) jira-events at lists.jboss.org
Thu Apr 12 06:25:52 EDT 2012


    [ https://issues.jboss.org/browse/CDI-149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12683427#comment-12683427 ] 

Mark Struberg commented on CDI-149:
-----------------------------------

Figured this myself lately. We should really go for it! There are a few areas which we could improve, mostly equals() and hashCode().

A fact upfront: if an Annotation has no member values, it returns 0 as hashCode()! That sucks, but we need to stay compatible. I'm not sure if we can cache the hashCode of an AnnotationLiteral if it contains member values. 
But we can for sure cache the 0 if getDeclaredMethods() returned an empty array. 

for equals() please at least push the getDeclaredMethods() down the call chain as it is madly expensive!.

    public boolean equals(Object other)
    {
-       Method[] methods = this.annotationType.getDeclaredMethods();
        
        if(other == this)
        {
            return true;
        }
        
        if(other == null)
        {
            return false;
        }
+       Method[] methods = this.annotationType.getDeclaredMethods();
        
                
> AnnotationLiteral in the CDI API does not cache the hashCode
> ------------------------------------------------------------
>
>                 Key: CDI-149
>                 URL: https://issues.jboss.org/browse/CDI-149
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Javadoc and API
>    Affects Versions: 1.0
>            Reporter: Stuart Douglas
>             Fix For: 1.1 (Proposed)
>
>
> Instead it is calculated each time using reflection, which could result in performance problems if lots of annotation literals are in use

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the cdi-dev mailing list