This page is no longer maintained — Please continue to the home page at www.scala-lang.org

possible bug in ScalaRunTime hashcode

3 replies
Sam Stainsby
Joined: 2009-01-14,
User offline. Last seen 42 years 45 weeks ago.

Hi all,

Line 89 (see below) in scala.runtime.ScalaRunTime (scala 2.7.3 final)
causes a NPE if the productElement(i) is null. I'm seeing this is a case
class when one of the constructor arguments is null and some other code
is trying to get the hashcode. Is that intended behaviour? Perhaps there
is a contract I am not fulfilling? Happy to log a bug otherwise ...

84 def _hashCode(x: Product): Int = {
85 var code = x.getClass().hashCode()
86 val arr = x.productArity
87 var i = 0
88 while (i < arr) {
89 code = code * 41 + x.productElement(i).hashCode()
90 i += 1
91 }
92 code
93 }

Cheers,
Sam.

Iulian Dragos
Joined: 2008-12-18,
User offline. Last seen 42 years 45 weeks ago.
Re: possible bug in ScalaRunTime hashcode

There's already a ticket for this issue:
https://lampsvn.epfl.ch/trac/scala/ticket/216

iulian

On Wed, Jan 21, 2009 at 7:14 AM, Sam Stainsby
wrote:
> Hi all,
>
> Line 89 (see below) in scala.runtime.ScalaRunTime (scala 2.7.3 final)
> causes a NPE if the productElement(i) is null. I'm seeing this is a case
> class when one of the constructor arguments is null and some other code
> is trying to get the hashcode. Is that intended behaviour? Perhaps there
> is a contract I am not fulfilling? Happy to log a bug otherwise ...
>
>
> 84 def _hashCode(x: Product): Int = {
> 85 var code = x.getClass().hashCode()
> 86 val arr = x.productArity
> 87 var i = 0
> 88 while (i < arr) {
> 89 code = code * 41 + x.productElement(i).hashCode()
> 90 i += 1
> 91 }
> 92 code
> 93 }
>
> Cheers,
> Sam.
>
>

Sam Stainsby
Joined: 2009-01-14,
User offline. Last seen 42 years 45 weeks ago.
Re: possible bug in ScalaRunTime hashcode

I saw that but didn't realise it was the same issue - seems obvious now.
A bit concerning that it has been there for so long, especially
considering the fix is simple and provided.

On Wed, 21 Jan 2009 11:14:06 +0100, Iulian Dragos wrote:

> There's already a ticket for this issue:
> https://lampsvn.epfl.ch/trac/scala/ticket/216
>
> iulian
>
> On Wed, Jan 21, 2009 at 7:14 AM, Sam Stainsby
> wrote:
>> Hi all,
>>
>> Line 89 (see below) in scala.runtime.ScalaRunTime (scala 2.7.3 final)
>> causes a NPE if the productElement(i) is null. I'm seeing this is a
>> case class when one of the constructor arguments is null and some other
>> code is trying to get the hashcode. Is that intended behaviour? Perhaps
>> there is a contract I am not fulfilling? Happy to log a bug otherwise
>> ...
>>
>>
>> 84 def _hashCode(x: Product): Int = { 85 var code =
>> x.getClass().hashCode() 86 val arr = x.productArity 87
>> var i = 0
>> 88 while (i < arr) {
>> 89 code = code * 41 + x.productElement(i).hashCode() 90
>> i += 1
>> 91 }
>> 92 code
>> 93 }
>>
>> Cheers,
>> Sam.
>>
>>

Iulian Dragos
Joined: 2008-12-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: possible bug in ScalaRunTime hashcode

It's fixed now, you can either wait for the next release or grab the
nightly here http://www.scala-lang.org/node/212.

iulian

On Wed, Jan 21, 2009 at 11:44 AM, Sam Stainsby
wrote:
> I saw that but didn't realise it was the same issue - seems obvious now.
> A bit concerning that it has been there for so long, especially
> considering the fix is simple and provided.
>
> On Wed, 21 Jan 2009 11:14:06 +0100, Iulian Dragos wrote:
>
>> There's already a ticket for this issue:
>> https://lampsvn.epfl.ch/trac/scala/ticket/216
>>
>> iulian
>>
>> On Wed, Jan 21, 2009 at 7:14 AM, Sam Stainsby
>> wrote:
>>> Hi all,
>>>
>>> Line 89 (see below) in scala.runtime.ScalaRunTime (scala 2.7.3 final)
>>> causes a NPE if the productElement(i) is null. I'm seeing this is a
>>> case class when one of the constructor arguments is null and some other
>>> code is trying to get the hashcode. Is that intended behaviour? Perhaps
>>> there is a contract I am not fulfilling? Happy to log a bug otherwise
>>> ...
>>>
>>>
>>> 84 def _hashCode(x: Product): Int = { 85 var code =
>>> x.getClass().hashCode() 86 val arr = x.productArity 87
>>> var i = 0
>>> 88 while (i < arr) {
>>> 89 code = code * 41 + x.productElement(i).hashCode() 90
>>> i += 1
>>> 91 }
>>> 92 code
>>> 93 }
>>>
>>> Cheers,
>>> Sam.
>>>
>>>
>
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland