Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GoogleCodeExporter opened this issue Sep 9, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

This issue was closed by revision r43.

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: milestone-2.1b0

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: v2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant