Injection of SortedMap throws IllegalArgumentException
------------------------------------------------------
Key: JBSEAM-3998
URL:
https://jira.jboss.org/jira/browse/JBSEAM-3998
Project: Seam
Issue Type: Bug
Components: Core
Affects Versions: 2.1.0.SP1
Reporter: Naresh Bhatia
I have a bean called instrumentManager that contains a factory to create a SortedMap of
Instruments:
@Name("instrumentManager")
@Scope(ScopeType.CONVERSATION)
public class InstrumentManager implements Serializable {
@In private InstrumentRepository instrumentRepository;
@Out(required=false)
private SortedMap<String, Instrument> instrumentMap;
public SortedMap<String, Instrument> getInstrumentMap() {
return instrumentMap;
}
@Factory("instrumentMap")
public void createInstrumentMap() {
List<Instrument> instrumentList = instrumentRepository.findAll();
instrumentMap = new TreeMap<String, Instrument>();
for (Instrument instrument : instrumentList) {
instrumentMap.put(instrument.getSymbol(), instrument);
}
}
}
I am injecting the instrument map in a JSF converter bean:
@Name("instrumentConverter")
@Converter(forClass=Instrument.class)
public class InstrumentConverter implements javax.faces.convert.Converter {
@In(create=true)
private SortedMap<String, Instrument> instrumentMap;
@Override
public Object getAsObject(
FacesContext context, UIComponent component, String value) {
if (StringUtils.isEmpty(value)) {
return null;
}
return instrumentMap.get(value);
}
@Override
public String getAsString(
FacesContext context, UIComponent component, Object value) {
return value.toString();
}
}
When the converter tries to access the instrument map, I get the following exception:
14:22:30.484 WARN [javax.enterprise.resource.webcontainer.jsf.lifecycle] could not set
field value: instrumentConverter.instrumentMap
java.lang.IllegalArgumentException: could not set field value:
instrumentConverter.instrumentMap
at org.jboss.seam.Component.setFieldValue(Component.java:1884)
at org.jboss.seam.Component.access$600(Component.java:126)
at org.jboss.seam.Component$BijectedField.set(Component.java:2900)
at org.jboss.seam.Component.injectAttributes(Component.java:1693)
at org.jboss.seam.Component.inject(Component.java:1511)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
at
org.test.myapp.web.util.InstrumentConverter_$$_javassist_11.getAsObject(InstrumentConverter_$$_javassist_11.java)
at
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:167)
at
com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:188)
at
com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:301)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
at javax.faces.component.UIInput.validate(UIInput.java:868)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
at javax.faces.component.UIInput.processValidators(UIInput.java:672)
at javax.faces.component.UIForm.processValidators(UIForm.java:235)
at org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:439)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:455)
at
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
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)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:51)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: Could not set field value by reflection:
InstrumentConverter.instrumentMap on: org.test.myapp.web.util.InstrumentConverter with
value: class java.util.HashMap
at org.jboss.seam.util.Reflections.set(Reflections.java:86)
at org.jboss.seam.Component.setFieldValue(Component.java:1880)
... 67 more
Caused by: java.lang.IllegalArgumentException: Can not set java.util.SortedMap field
org.test.myapp.web.util.InstrumentConverter.instrumentMap to java.util.HashMap
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
at java.lang.reflect.Field.set(Field.java:657)
at org.jboss.seam.util.Reflections.set(Reflections.java:71)
... 68 more
Note that replacing the SortedMap everywhere with just a java.util.Map fixes the problem.
So I suspect that somewhere a SortedMap is being initialized with a HashMap.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira