Uploaded image for project: 'Spring Modules'
  1. Spring Modules
  2. MOD-260

HashCodeCacheKeyGenerator doesn't make 2 different cache keys on method invocations on 2 different subclasses of same superclass.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 0.6
    • Fix Version/s: None
    • Component/s: CACHE
    • Labels:
      None

      Description

      HashCodeCacheKeyGenerator creates same CacheKeys for method invocations on different objects if:
      1. those objects have a common interface and,
      2. those objects invoke the same method, defined in the superinterface and,
      3. the make the invocation with equal arguments

      I tested this with a piece of code like this:

      Dao daoA = (Dao) ctx.getBean("daoA");
      Dao daoB = (Dao) ctx.getBean("daoB");

      BusObject busA = daoA.loadById(new Integer(0));
      BusObject busB = daoB.loadById(new Integer(0));

      System.out.println("busA = " + busA.toString());
      System.out.println("busB = " + busB.toString());

      And the output was:

      [java] busA = BusObjectA[id=0]
      [java] busB = BusObjectA[id=0]

      (Bean "daoB.loadById" produces objects of type BusObjectB)

      Cache returned BusObjectA as a cache result for daoBloadById invocation - that is wrong, because daoB.loadById never returns BusObjectA objects

      The problem is in the HashCodeCacheKeyGenerator - and i think that using methodInvocation.getThis().getClass() in creating the hashCode would fix this problem (for non-static invocations). For static invocations methodInvocation.getThis() is null - in that cases methodInvocation.getMethod() would probably be suficent.

      I'll try to upload the program i used for reproducing the bug (if Jira lets me).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              irbouho Omar Irbouh
              Reporter:
              borut Borut Hadžialić
              Votes:
              3 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: