[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Mark Struberg (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Mark Struberg commented on CDI-630:
-----------------------------------
You will end up with 2 instances, think about it again ;)
Of course equals() would return true, but hashCode is different.
You are right with hash collision, but the other way we end up with not finding the right instances :(
> 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
> Priority: Optional
> 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.
> UPDATE: We may not return a number based on the annotation type because it would break the {{java.lang.annotation.Annotation.hashCode()}} contract.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba edited comment on CDI-630 at 9/13/16 3:17 AM:
-----------------------------------------------------------
bq. If we would change the hashCode of empty AnnotationLiterals then you would end up with 2 entries in the HashMap.
[~struberg] No, you don't have to end up with 2 entries because those annotation instances are equal. From what I know the hash code is only used to compute an index into array of buckets. But it really depends on impl. So right now all annotation literal keys will end up in one bucket (-> hash collisions -> less effective lookup).
Anyway, we would break the general equals/contract and also the {{java.lang.annotation.Annotation.hashCode()}} contract (I wasn't aware of its existence :-(. So it's definitely NOT POSSIBLE.
Still, I don't get the meaning of storing a zero integer if there are no members. Checking the members array length should be fine. Lowering the priority...
was (Author: mkouba):
bq. If we would change the hashCode of empty AnnotationLiterals then you would end up with 2 entries in the HashMap.
[~struberg] No, you will not end up with 2 entries because those annotation instances are equal. From what I know the hash code is only used to compute an index into array of buckets. So right now all annotation literal keys will end up in one bucket (-> hash collisions -> less effective lookup).
But I agree we MAY NOT break the {{java.lang.annotation.Annotation.hashCode()}} contract - I wasn't aware of its existence :-(
Still, I don't get the meaning of storing a zero integer if there are no members. Checking the members array length should be fine. Lowering the priority...
> 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
> Priority: Optional
> 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.
> UPDATE: We may not return a number based on the annotation type because it would break the {{java.lang.annotation.Annotation.hashCode()}} contract.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba updated CDI-630:
-----------------------------
Description:
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.
UPDATE: We may not return a number based on the annotation type because it would break the {{java.lang.annotation.Annotation.hashCode()}} contract.
was: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.
> 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
> Priority: Optional
> 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.
> UPDATE: We may not return a number based on the annotation type because it would break the {{java.lang.annotation.Annotation.hashCode()}} contract.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba updated CDI-630:
-----------------------------
Priority: Optional (was: Major)
> 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
> Priority: Optional
> 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)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba commented on CDI-630:
----------------------------------
bq. If we would change the hashCode of empty AnnotationLiterals then you would end up with 2 entries in the HashMap.
[~struberg] No, you will not end up with 2 entries because those annotation instances are equal. From what I know the hash code is only used to compute an index into array of buckets. So right now all annotation literal keys will end up in one bucket (-> hash collisions -> less effective lookup).
But I agree we MAY NOT break the {{java.lang.annotation.Annotation.hashCode()}} contract - I wasn't aware of its existence :-(
Still, I don't get the meaning of storing a zero integer if there are no members. Checking the members array length should be fine. Lowering the priority...
> 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)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Matej Novotny (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Matej Novotny commented on CDI-630:
-----------------------------------
So, if I get this right, then we are basically stuck here because our {{hashCode}} impl has to be alligned with that defined by {{java.lang.annotation.Annotation}}?
And the reason behind that is that people are able to use both approaches ({{class.getAnnotation}} and {{AnnotationLiteral}}) and the results would then differ.
> 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)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Mark Struberg (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
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)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Martin Kouba (JIRA)
Martin Kouba created CDI-630:
--------------------------------
Summary: 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
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)
7 years, 7 months
[JBoss JIRA] (CDI-630) Revise javax.enterprise.util.AnnotationLiteral.cachedHashCode
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-630?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba updated CDI-630:
-----------------------------
Fix Version/s: 2.0 (discussion)
> 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)
7 years, 7 months