[ https://issues.apache.org/jira/browse/TAP5-2674?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17333421#comment-17333421 ]
Thiago Henrique De Paula Figueiredo commented on TAP5-2674: ----------------------------------------------------------- Thanks [~cbo-itop] for reporting the ticket, [~vlamp] for providing the patch and [~ben-ng] for applying it! > Type coercer contribution - cast exception in equals > ----------------------------------------------------- > > Key: TAP5-2674 > URL: https://issues.apache.org/jira/browse/TAP5-2674 > Project: Tapestry 5 > Issue Type: Bug > Components: tapestry-core > Affects Versions: 5.7.2 > Reporter: Cédric BOONE > Assignee: Ben Weidig > Priority: Blocker > Fix For: 5.7.3 > > Attachments: TAP5-2674.patch > > > I have multiple Tapestry modules which contribute to type coercer, I can't > make it work. > > I contribute TypeCoercer this way > > {code:java} > public static void > contributeTypeCoercer(MappedConfiguration<CoercionTuple.Key, CoercionTuple> > configuration) { > Coercion<String, Class> coercion = path -> { > try { > return Class.forName(path); > } catch (ClassNotFoundException e) { > return null; > } > }; > CoercionTuple<String, Class> tuple = new CoercionTuple<>(String.class, > Class.class, coercion); > configuration.override(tuple.getKey(), tuple); > }{code} > > When I try to access a Tapestry page I get the following: > > > {code:java} > Caused by: java.lang.ClassCastException: > org.apache.tapestry5.commons.services.CoercionTuple$Key cannot be cast to > org.apache.tapestry5.commons.services.CoercionTuple > at > org.apache.tapestry5.commons.services.CoercionTuple$Key.equals(CoercionTuple.java:184) > at java.util.HashMap.getNode(HashMap.java:572) > at java.util.HashMap.get(HashMap.java:557) > at > org.apache.tapestry5.ioc.internal.ValidatingMappedConfigurationWrapper.override(ValidatingMappedConfigurationWrapper.java:122) > at > **********.SessionsSubModule.contributeTypeCoercer(SessionsSubModule.java:63) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at > org.apache.tapestry5.ioc.internal.ContributionDefImpl.invokeMethod(ContributionDefImpl.java:133) > ... 219 more > {code} > > The exception is raised in the equals method of CoercionTuple.Key: > {code:java} > @Override > public boolean equals(Object obj) > { > if (this == obj) > return true; > if (obj == null) > return false; > if (getClass() != obj.getClass()) > return false; > // Exception is raised here > CoercionTuple other = (CoercionTuple) obj; > if (sourceType == null) > { > if (other.sourceType != null) > return false; > } else if (!sourceType.equals(other.sourceType)) > return false; > if (targetType == null) > { > if (other.targetType != null) > return false; > } else if (!targetType.equals(other.targetType)) > return false; > return true; > } > {code} > The equals is called in the HashMap#get implementation (used in > ValidatingMappedConfigurationWrapper) > > With this part of code: > {code:java} > ... > if (getClass() != obj.getClass()) > return false; > CoercionTuple other = (CoercionTuple) obj; > ... > {code} > the obj variable can't be a CoercionTuple, it will be a CoercionTuple.Key > (which is the case in the implementation of HashMap<CoercionTupe.Key, > CoercionTuple>#get). > I might not have understood something, if it is the case, I'm sorry for the > trouble. > > -- This message was sent by Atlassian Jira (v8.3.4#803005)