0

I'm having a problem debugging an application which uses an iterator to cycle through the entries in a beanmap. When I use the remove() function on the iterator, the application crashes, and I cannot figure out why. It used to work fine.

The application has been running fine for over a year now without any issues. Perhaps the .remove() function was never really called as it is inside an if clause, but I still think it should work fine.

Here's the code:

BeanMap bm = new BeanMap(pKzlGd);
        Iterator entries = bm.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) entries.next();
            if (entry.getValue() instanceof Class) {
                entries.remove();
            }
        }

This is basically the StackTrace error I get:

Stack trace: javax.faces.FacesException: #{aopUpload.upload}: java.lang.UnsupportedOperationException: remove() is not supported
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
         at si.nkbm.bilbon.net.ExceptionActionListener.processAction(ExceptionActionListener.java:24)
         at javax.faces.component.UICommand.broadcast(UICommand.java:387)
         at org.ajax4jsf.component.UIInclude.broadcast(UIInclude.java:170)
         at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)
         at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:304)
         at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)
         at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:474)
         at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
         at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
Bg Zape
  • 40
  • 6

1 Answers1

2

As far as can see you use BeanMap. It seems that iterators provided by that Map don't support removing of entries. I suppose you've never passed through the if statement before. This behavior is expected. Documentation mentions that it's not actually allowed to remove entries.

Vladimir Pligin
  • 1,547
  • 11
  • 18
  • I might be wrong here, but I've seen several examples where code very simillar to mine was suggested and worked fine (e.g. here: https://stackoverflow.com/questions/1884889/iterating-over-and-removing-from-a-map )... I will try to find another way for it then however, I suppose. – Bg Zape Sep 11 '19 at 10:22
  • That question is about a `Map` providing an iterator that supports removing. That's the only difference in this scope. – Vladimir Pligin Sep 12 '19 at 10:24