Skip to content
Permalink
Browse files
Improved the hashcode pre-computation protection: we use a temporary
variable to store the value, so that concurrent calls don't impact the
final value
  • Loading branch information
elecharny committed Mar 4, 2019
1 parent 850dee0 commit 2a77152705392ccb4e1af4313fe4dc30bc676816
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
@@ -1889,22 +1889,24 @@ public boolean isInstanceOf( AttributeType attributeType ) throws LdapInvalidAtt
*/
private void rehash()
{
h = 37;
int hTmp = 37;

if ( isHR != null )
{
h = h * 17 + isHR.hashCode();
hTmp = hTmp * 17 + isHR.hashCode();
}

if ( id != null )
{
h = h * 17 + id.hashCode();
hTmp = hTmp * 17 + id.hashCode();
}

if ( attributeType != null )
{
h = h * 17 + attributeType.hashCode();
hTmp = hTmp * 17 + attributeType.hashCode();
}

h = hTmp;
}


@@ -546,8 +546,8 @@ private Dn normalizeDn( Dn dn )
*/
private void rehash()
{
h = 37;
h = h * 17 + dn.hashCode();
int hTmp = 37;
h = hTmp * 17 + dn.hashCode();
}


@@ -1470,10 +1470,10 @@ public int hashCode()
{
if ( h == 0 )
{
h = 37;
int hTmp = 37;

h = h * 17 + ( normType != null ? normType.hashCode() : 0 );
h = h * 17 + ( value != null ? value.hashCode() : 0 );
hTmp = hTmp * 17 + ( normType != null ? normType.hashCode() : 0 );
h = hTmp * 17 + ( value != null ? value.hashCode() : 0 );
}

return h;
@@ -1730,7 +1730,7 @@ public int hashCode()
{
if ( h == 0 )
{
h = 37;
int hTmp = 37;

switch ( nbAvas )
{
@@ -1740,15 +1740,15 @@ public int hashCode()

case 1:
// We have a single Ava
h = h * 17 + ava.hashCode();
h = hTmp * 17 + ava.hashCode();
break;

default:
// We have more than one Ava

for ( Ava ata : avas )
{
h = h * 17 + ata.hashCode();
h = hTmp * 17 + ata.hashCode();
}

break;

0 comments on commit 2a77152

Please sign in to comment.