You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Alex Karasulu <ao...@bellsouth.net> on 2004/02/19 07:09:06 UTC
[OT] Bug in NIO
I think I found a bug in NIO but I'm seeing double right now
after chasing it for so long. The bug has to do with a simple
hashCode function - nothing really to do with the core operations
of the API.
I was wondering if others can look at this junit testcase I have here
and perhaps even run it to confirm that I'm not smoking crack.
I this really a bug?
The test is simply this here:
public void testBufferHashing() throws Exception
{
HashMap l_map = new HashMap() ;
for( int ii = 0; ii < 10; ii++ )
{
ByteBuffer l_buf = ByteBuffer.allocateDirect( 4096 ) ;
l_map.put( l_buf, new Integer( ii ) ) ;
}
assertTrue( l_map.size() == 10 ) ;
}
Seems like there's a hashCode problem with the direct buffer.
Thanks in advance,
Alex
RE: [OT] Bug in NIO
Posted by Alex Karasulu <ao...@bellsouth.net>.
Thanks Leo that's a good idea.
> -----Original Message-----
> From: Leo Sutic [mailto:leo.sutic@inspireinfrastructure.com]
> Sent: Thursday, February 19, 2004 3:28 AM
> To: 'Avalon Developers List'
> Subject: RE: [OT] Bug in NIO
>
> Alex,
>
> what you can do is wrap the buffer in an object that
> implements Object.equals by == with the wrapped Buffer,
> and hashCode via System.identityHashCode(wrapped Buffer).
>
> /LS
>
> > From: Alex Karasulu [mailto:aok123@bellsouth.net]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
RE: [OT] Bug in NIO
Posted by Leo Sutic <le...@inspireinfrastructure.com>.
Alex,
what you can do is wrap the buffer in an object that
implements Object.equals by == with the wrapped Buffer,
and hashCode via System.identityHashCode(wrapped Buffer).
/LS
> From: Alex Karasulu [mailto:aok123@bellsouth.net]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
RE: [OT] Bug in NIO
Posted by Alex Karasulu <ao...@bellsouth.net>.
Yeah you're right. This really bit me in the ass though.
Alex
> -----Original Message-----
> From: Boon Hian Tek [mailto:btek@cox.net]
> Sent: Thursday, February 19, 2004 2:17 AM
> To: Avalon Developers List
> Subject: Re: [OT] Bug in NIO
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Alex,
>
> We all have one of those days once in a while to keep our ego from
> over-flowing :P
>
> Boon
>
> Alex Karasulu wrote:
> | Boon,
> |
> | Son of a gun! I'm feeling like a dumb ass now. Well this settles it.
> | I should have read the manual on this one. Ok I'll go put my head in
> | the sand now.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFANGLvNJFBtmCH2hIRAmw/AKCwfuNwmuHTtfFW2iRSxEzFW0mUPACghEPr
> G6rlxyqRAOzyvL/YlUohf6E=
> =1gxp
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
Re: [OT] Bug in NIO
Posted by Boon Hian Tek <bt...@cox.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Alex,
We all have one of those days once in a while to keep our ego from
over-flowing :P
Boon
Alex Karasulu wrote:
| Boon,
|
| Son of a gun! I'm feeling like a dumb ass now. Well this settles it.
| I should have read the manual on this one. Ok I'll go put my head in
| the sand now.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFANGLvNJFBtmCH2hIRAmw/AKCwfuNwmuHTtfFW2iRSxEzFW0mUPACghEPr
G6rlxyqRAOzyvL/YlUohf6E=
=1gxp
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
RE: [OT] Bug in NIO
Posted by Alex Karasulu <ao...@bellsouth.net>.
Boon,
Son of a gun! I'm feeling like a dumb ass now. Well this settles it.
I should have read the manual on this one. Ok I'll go put my head in
the sand now.
> -----Original Message-----
> From: Boon Hian Tek [mailto:btek@cox.net]
> Sent: Thursday, February 19, 2004 2:04 AM
> To: Avalon Developers List
> Subject: Re: [OT] Bug in NIO
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Alex,
>
> Alex Karasulu wrote:
> | I think I found a bug in NIO but I'm seeing double right now
> | after chasing it for so long. The bug has to do with a simple
> | hashCode function - nothing really to do with the core operations
> | of the API.
> |
> | I was wondering if others can look at this junit testcase I have here
> | and perhaps even run it to confirm that I'm not smoking crack.
> | I this really a bug?
> |
> | The test is simply this here:
> |
> | public void testBufferHashing() throws Exception
> | {
> | HashMap l_map = new HashMap() ;
> |
> | for( int ii = 0; ii < 10; ii++ )
> | {
> | ByteBuffer l_buf = ByteBuffer.allocateDirect( 4096 ) ;
> | l_map.put( l_buf, new Integer( ii ) ) ;
> | }
> |
> | assertTrue( l_map.size() == 10 ) ;
> | }
> |
> | Seems like there's a hashCode problem with the direct buffer.
> |
> | Thanks in advance,
> | Alex
>
> "Because buffer hash codes are content-dependent, it is inadvisable to
> use buffers as keys in hash maps or similar data structures unless it is
> known that their contents will not change."
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/nio/ByteBuffer.html#hashCode(
> )
>
> The equals method evaluate two empty buffers as equals.
>
> I don't think this is a bug.
>
> My 2 cents.
>
> Boon
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFANF/iNJFBtmCH2hIRAtTbAKCHvROEHkxHkkumZMwqaawDG0NRXgCfcpiO
> J9WOcMrA/inmDpD0X2M6hJQ=
> =BCf5
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
Re: [OT] Bug in NIO
Posted by Boon Hian Tek <bt...@cox.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Alex,
Alex Karasulu wrote:
| I think I found a bug in NIO but I'm seeing double right now
| after chasing it for so long. The bug has to do with a simple
| hashCode function - nothing really to do with the core operations
| of the API.
|
| I was wondering if others can look at this junit testcase I have here
| and perhaps even run it to confirm that I'm not smoking crack.
| I this really a bug?
|
| The test is simply this here:
|
| public void testBufferHashing() throws Exception
| {
| HashMap l_map = new HashMap() ;
|
| for( int ii = 0; ii < 10; ii++ )
| {
| ByteBuffer l_buf = ByteBuffer.allocateDirect( 4096 ) ;
| l_map.put( l_buf, new Integer( ii ) ) ;
| }
|
| assertTrue( l_map.size() == 10 ) ;
| }
|
| Seems like there's a hashCode problem with the direct buffer.
|
| Thanks in advance,
| Alex
"Because buffer hash codes are content-dependent, it is inadvisable to
use buffers as keys in hash maps or similar data structures unless it is
known that their contents will not change."
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/ByteBuffer.html#hashCode()
The equals method evaluate two empty buffers as equals.
I don't think this is a bug.
My 2 cents.
Boon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFANF/iNJFBtmCH2hIRAtTbAKCHvROEHkxHkkumZMwqaawDG0NRXgCfcpiO
J9WOcMrA/inmDpD0X2M6hJQ=
=BCf5
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
RE: [OT] Bug in NIO
Posted by Alex Karasulu <ao...@bellsouth.net>.
Just for the record since the attachment of the file did not make it
through here is the link to the test case:
http://www.apache.org/~akarasulu/BufferHashing.java
Alex
>
> Confirmation - testcase fails:
>
Thanks!
> Testcase: testBufferHashing took 0.063 sec
> FAILED
> null
> > The test is simply this here:
> >
> > public void testBufferHashing() throws Exception
> > {
> > HashMap l_map = new HashMap() ;
> >
> > for( int ii = 0; ii < 10; ii++ )
> > {
> > ByteBuffer l_buf = ByteBuffer.allocateDirect( 4096 ) ;
> > l_map.put( l_buf, new Integer( ii ) ) ;
> > }
> >
> > assertTrue( l_map.size() == 10 ) ;
> > }
> >
> > Seems like there's a hashCode problem with the direct buffer.
> >
> > Thanks in advance,
> > Alex
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org
Re: [OT] Bug in NIO
Posted by Stephen McConnell <mc...@apache.org>.
Confirmation - testcase fails:
Testcase: testBufferHashing took 0.063 sec
FAILED
null
junit.framework.AssertionFailedError
at tutorial.NullTestCase.testBufferHashing(NullTestCase.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:232)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135)
at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233)
at org.apache.commons.jelly.tags.core.IfTag.doTag(IfTag.java:88)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135)
at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233)
at com.werken.werkz.jelly.GoalTag$1.performAction(GoalTag.java:128)
at com.werken.werkz.Goal.fire(Goal.java:639)
at com.werken.werkz.Goal.attain(Goal.java:575)
at com.werken.werkz.Goal.attainPrecursors(Goal.java:488)
at com.werken.werkz.Goal.attain(Goal.java:573)
at
org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:434)
at org.apache.maven.MavenSession.attainGoals(MavenSession.java:348)
at org.apache.maven.cli.App.doMain(App.java:525)
at org.apache.maven.cli.App.main(App.java:1088)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.werken.forehead.Forehead.run(Forehead.java:543)
at com.werken.forehead.Forehead.main(Forehead.java:573)
Testcase: testBufferHashing
Steve.
Alex Karasulu wrote:
> I think I found a bug in NIO but I'm seeing double right now
> after chasing it for so long. The bug has to do with a simple
> hashCode function - nothing really to do with the core operations
> of the API.
>
> I was wondering if others can look at this junit testcase I have here
> and perhaps even run it to confirm that I'm not smoking crack.
> I this really a bug?
>
> The test is simply this here:
>
> public void testBufferHashing() throws Exception
> {
> HashMap l_map = new HashMap() ;
>
> for( int ii = 0; ii < 10; ii++ )
> {
> ByteBuffer l_buf = ByteBuffer.allocateDirect( 4096 ) ;
> l_map.put( l_buf, new Integer( ii ) ) ;
> }
>
> assertTrue( l_map.size() == 10 ) ;
> }
>
> Seems like there's a hashCode problem with the direct buffer.
>
> Thanks in advance,
> Alex
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org
--
|------------------------------------------------|
| Magic by Merlin |
| Production by Avalon |
| |
| http://avalon.apache.org/merlin |
| http://dpml.net/merlin/distributions/latest |
|------------------------------------------------|
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org