cbuschka / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

BshMethod equality succeeds for subtypes, does not support hashcode contract #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
BshMethod.equals() succeeds when comparing subclasses with BshMethod instances:

{{{
   @SuppressWarnings("serial")
   @Test
   public void testEqualsObject_subclassEquality() {
      // define a simple subclass of BshMethod:
      class SubMethod extends BshMethod {
         public SubMethod(String name, Class returnType, String[] paramNames,
               Class[] paramTypes, BSHBlock methodBody,
               NameSpace declaringNameSpace, Modifiers modifiers) {
            super(name, returnType, paramNames, paramTypes, methodBody,
declaringNameSpace,
                  modifiers);
         }
      };

      final String name = "testMethod";
      final BshMethod subInst = new SubMethod(name, 
            Integer.class, new String[]{}, new Class[]{}, null, null, null);
      final BshMethod supInst = new BshMethod(name, 
            Integer.class, new String[]{}, new Class[]{}, null, null, null);

      Assert.assertFalse("Subclasses should not be equal to super classes",
            supInst.equals(subInst));
   }
}}}

This method also does not support the hashcode/equals contract:

{{{
   @Test
   public void testHashCode_contract() {
      final String name = "testMethod";
      final BshMethod method1 = new BshMethod(name, 
            Integer.class, new String[]{}, new Class[]{}, null, null, null);
      final BshMethod method2 = new BshMethod(name, 
            Integer.class, new String[]{}, new Class[]{}, null, null, null);

      Assert.assertTrue("precondition check for test failed.", 
            method2.equals(method1));
      Assert.assertEquals("Equal classes should have equal hashcodes",
            method2.hashCode(), method1.hashCode());
   }
}}}

This is a fairly easy fix, as long as it is not intentional.  I'll try and
attach a patch tonight / tomorrow.

Original issue reported on code.google.com by cresw...@gmail.com on 1 Mar 2009 at 12:30

GoogleCodeExporter commented 9 years ago
These tests are now in svn, see revision r35.  They are ignored, however, since 
they
are known to fail.

I'll check in the fixes to BshMethod as soon as I find time to hack out 
`hashCode()`

Original comment by cresw...@gmail.com on 4 Mar 2009 at 3:36

GoogleCodeExporter commented 9 years ago
Since nothing happend since March 2009 i changed the owner to me.

As far as i can see this defect causes no harm but should be easy to fix

Original comment by pejob...@gmail.com on 21 Feb 2011 at 11:44

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r43.

Original comment by `` on 21 Feb 2011 at 11:59

GoogleCodeExporter commented 9 years ago

Original comment by pejob...@gmail.com on 25 Feb 2011 at 5:56

GoogleCodeExporter commented 9 years ago

Original comment by pejob...@gmail.com on 20 Oct 2011 at 7:12