[cdi-dev] [JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
Mark Struberg (JIRA)
issues at jboss.org
Mon Sep 12 14:27:00 EDT 2016
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13292123#comment-13292123 ]
Mark Struberg commented on CDI-630:
-----------------------------------
Kids sleeping, now is time for the long explanation:
The hascode for empty annotations is defined as zero,
Imagine a class
{code}
@Default
@ApplicationScoped
public class Bla {...
{code}
now put this annotation in a HashMap:
{code}
map.put(Bla.class.getAnnotation(Default.class));
{code}
And we also have another dynamic annotation
{code}
map.put( new AnnotationLiteral<Default> {} );
{code}
If we would change the hashCode of empty AnnotationLiterals then you would end up with 2 entries in the HashMap.
> Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
> -------------------------------------------------------------
>
> Key: CDI-630
> URL: https://issues.jboss.org/browse/CDI-630
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Reporter: Martin Kouba
> Fix For: 2.0 (discussion)
>
>
> Currently, {{AnnotationLiteral.hashCode()}} always returns {{0}} if there are no members (ignoring annotation type completely). Although it does not break {{Object.hashCode()}} contract, I believe we should either return a number based on the annotation type (to make the annotation literal instances more usable in hash tables) or simply return zero and don't cache the value at all.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the cdi-dev
mailing list