简体   繁体   中英

Java BeanMap Iterator throws UnsupportedOperationException on iterator.remove()

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM