java.lang.UnsupportedOperationException异常

今天在启动tomcat的时候,在日志里发现一个异常

意思是在SecurityFilter 这个类里面第69行 destroy这个方法报出的异常,根据网上搜索到的回答:

因为调用Arrays.asLisvt() 方法 ,返回的是java.util.Arrays$ArrayList对象, 而不是ArrayList对象。Arrays$ArrayList和ArrayList都是继承AbstractList。AbstractList中的remove,add等方法都是默认throw UnsupportedOperationException。而ArrayList 自己重写了这些方法,但是Arrays$ArrayList没有重写 remove(int),add(int)等方法,所以调用asLisv 后,如果调用remove(int),add(int)等方法,其实是java.util.Arrays$ArrayList对象在调用 remove(int),add(int)等方法,也就是在调用父类AbstractList中的这些方法。

看截图AbstractList

但是我在SecurityFilter 发现 69行destroy 虽然调用clear方法,并没有涉及到remove,为啥remove 的时候报异常,而且这个两个句柄并定义为Arraylist,应该不会涉及上面说的问题

     我仔细想想,既然调用父类AbstractList的方法,根据继承的原则

       当超类对象引用变量引用子类对象时,被引用对象的类型而不是引用变量的类型决定了调用谁的成员方法,但是这个被调用的方法必须是在超类中定义过的,也就是说被子类覆盖的方法

      意思是当超类(这里说的是父类AbstractList)的引用对象,引用子类(ArrayList)的时候,调用谁的方法不是由超类的引用类型来决定的,而是由子类类型型决定的,而且子类中的方法在父类中被定义过。

    所以这里在过滤器被初始化 init的时候肯定使用了asLisvt方法,我发现在init方法里面有一个convStrToList方法

我进去一看发现convStrToList调用asList方法 导致返回的类型不是Arraylist。

 

阅读更多

java.lang.UnsupportedOperationException jsf

05-30

index.jsprn<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>rn<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>rn<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>rn<%rnString path = request.getContextPath();rnString basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";rn%>rnrnrnrn rn rn rn My JSP 'index.jsp' starting pagern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnsuccess.jsprn<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>rn<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>rn<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>rn<%rnString path = request.getContextPath();rnString basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";rn%>rnrnrnrn rn rn rn My JSP 'index.jsp' starting pagern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnfailure.jsprn<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>rn<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>rn<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>rn<%rnString path = request.getContextPath();rnString basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";rn%>rnrnrnrn rn rn rn My JSP 'index.jsp' starting pagern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnfaces-config.jsprnrnrnrn rn registrationBeanrn com.RegistrationBeanrn requestrn rn rn /index.jsprn rn successrn /success.jsprn rn rn failurern /failure.jsprn rn rn com.ApplicationMessagern rn zh_CNrn en_USrn zh_TWrn rn com.ApplicationMessagern bundlern rn rnrnrnrnweb.jsprnrnrn rn FacesServletrn javax.faces.webapp.FacesServletrn rn rn FacesServletrn *.facesrn rn rn index.jsprn rn rn BASICrn rnrnrn 总是报这个异常,其高手指点,急急急啊!rnrn2010-5-30 13:35:15 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet FacesServlet threw exceptionrnjava.lang.UnsupportedOperationExceptionrn at javax.faces.application.Application.getResourceHandler(Application.java:286)rn at javax.faces.webapp.FacesServlet.service(FacesServlet.java:307)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rnrn请高手指点!

java.lang.UnsupportedOperationException报错

10-03

2010-10-3 17:05:34 org.apache.catalina.core.StandardHostValve customrn严重: Exception Processing ErrorPage[errorCode=404, location=/error/404.jsf]rnjava.lang.UnsupportedOperationExceptionrn at javax.faces.context.FacesContext.getELContext(FacesContext.java:137)rn at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:888)rn at org.apache.myfaces.application.jsp.JspViewHandlerImpl.createView(JspViewHandlerImpl.java:121)rn at org.ajax4jsf.application.ViewHandlerWrapper.createView(ViewHandlerWrapper.java:84)rn at org.ajax4jsf.application.AjaxViewHandler.createView(AjaxViewHandler.java:91)rn at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.createView(ViewHandlerImpl.java:124)rn at org.ajax4jsf.application.ViewHandlerWrapper.createView(ViewHandlerWrapper.java:84)rn at org.ajax4jsf.application.AjaxViewHandler.createView(AjaxViewHandler.java:91)rn at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:83)rn at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)rn at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)rn at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)rn at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)rn at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)rn at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)rn at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:424)rn at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:343)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:144)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)rn at java.lang.Thread.run(Unknown Source)

没有更多推荐了,返回首页