[Building Sakai] ClassCastException: Cannot cast org.sakaiproject.site.impl.BaseSite (id=260) to org.sakaiproject.site.impl.BaseSite

Matthew Buckett matthew.buckett at oucs.ox.ac.uk
Tue Mar 10 14:11:47 PDT 2009


On Tue, Mar 10, 2009 at 5:28 PM, Jose Morell
<jose.morell.at.sakai at gmail.com> wrote:
> Hi Matthew,
>
> I have a problem with this.
>
> I'm working in the site-manage-tool.
>
> I need to extend the Site class with another attribute visitedTime.
>
> I have created VisitedSiteImpl that extends from BaseSite and implements
> VisitedSited (that extends from Site).

Just to check, so you have created these classes in the site-manage-tool?

> The first problem with this, is that if I add the kernel-impl dependency
> with <scope>provided</scope>, then the classes from kernel-impl there isn't
> found in execution time, but if I add the dependency with the default scope,

The kernel-impl artifact shouldn't be depended on by tools, this is so
that the implementation can change without breaking all tools, which
should only be depending on the APIs. You tools shouldn't have any
knowledge of kernel-impl and in the standard deployment, the
classloader setup prevents you from accessing the implementations from
the tools (this is a deliberate design decision), and hence the reason
for the error you get.

> then the kernel-impl-1.0.jar is in components, and in the deployed
> site-manage, and I get the ClassCastException of the first mail.

This is because the tool and the component now have a copy of the
BaseSite class, and they have different classloaders which means you
cannot case from one to the other. Putting kernel-impl into a webapp
is always going to break tools.

The solution is not to extends BaseSite in a tool, either move the
concept of VisitedSite into the kernel or change your class design to
just depend on the Site interface.

-- 
  Matthew Buckett


More information about the sakai-dev mailing list