14 Replies Latest reply on Mar 10, 2006 8:00 AM by Scott Marlow

    Collection proxy(Map) bug with Long values as keys

    prateek mathur Newbie

      I'm using TreeCacheAOP (JBOSSCache version 1.2.4SP1) for which im storing a map in the cache.
      When i retrieve the map and do a get() or a containsKey() it returns a null or a false value respectively for the given key.
      This happens only when i have a Long object stored as a key in my HashMap. When I use a string it works perfectly.
      And also,when we do similar operations on regular java Maps they work.Its an issue with the Proxy map that is returned by the getObject();
      My key looks like 8225676592564383 .
      So I insert my values like map.put(new Long("8225676592564383"),"prateek");
      Below is a code sample of what Im doing:

      public class AOPTest extends HttpServlet {
       protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
       throws ServletException, IOException {
       TreeCacheAop cache = (TreeCacheAop) getServletContext().getAttribute("treecache");
       Map nonCacheMap = (Map) getServletContext().getAttribute("noncachemap");
       try {
       Map guidMap = (Map) cache.getObject("/aop/guidmap");
       Map guidMap2 = (Map) cache.getObject("/aop/guidmap2");
       System.out.println(guidMap.containsKey("8225676592564383"));//This works-Its a string key
       System.out.println(guidMap2.containsKey("8225676592564383"));//this returns false.Its a long.
      
       } catch (CacheException e) {
       e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
       }
       }
      
       public void init() throws ServletException {
       TreeCacheAop cache = null;
       try {
       cache = new TreeCacheAop();
      
       PropertyConfigurator config = new PropertyConfigurator();
       config.configure(cache, "META-INF/jbosscache-config.xml");
       cache.start();
       Map guidMap = new HashMap();
       Map guidMap2 = new HashMap();
       cache.putObject("/aop/guidmap", guidMap);
       cache.putObject("/aop/guidmap2", guidMap2);
      
       guidMap = (Map) cache.getObject("/aop/guidmap");
       guidMap2 = (Map) cache.getObject("/aop/guidmap");
      
       guidMap.put("8225676592564383", "abhishek");
       guidMap2.put(new Long("8225676592564383"), "abhishek");
       getServletContext().setAttribute("treecache", cache);
       } catch (ConfigureException e) {
       e.printStackTrace();
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      
      }
      


      Please tell me a solution for this ..I want to use the Long key only in my map.