tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Leonardo (JIRA)" <j...@apache.org>
Subject [jira] Created: (TAP5-901) Generics return wrong type when subclassing page
Date Tue, 20 Oct 2009 18:34:00 GMT
Generics return wrong type when subclassing page

                 Key: TAP5-901
                 URL: https://issues.apache.org/jira/browse/TAP5-901
             Project: Tapestry 5
          Issue Type: Bug
    Affects Versions:
            Reporter: Mike Leonardo

I have a custom library that has the following classes:

public abstract class AbstractViewPage<T extends StaticPage<T, V>, V extends StaticPageVersion>
	private static final Pattern ID = Pattern.compile("^\\d+$");

	@InjectDao(StaticPage.class) private Dao<T> dao;
	@Inject private Response response;

	private T page;

	void onActivate(String key) throws IOException {
		if (ID.matcher(key).matches())
			page = dao.get(Long.parseLong(key));
		else {
			page = dao.get(eq("name", key));
		if (page != null && page.getLive() == null)
			page = null;
		if (page == null)
			response.sendError(404, "Page not found");
	public T getPage() {
		return page;

	public void setPage(T page) {
		this.page = page;

	/** Returns the versioned content to display. */
	public V getContent() {
		if (page == null)
			return null;
		return page.getLive();


/** Displays a static page */
public class Page extends AbstractViewPage<IFPStaticPage, IFPStaticPageVersion> {
	@Inject private IAuth auth;
	@Inject private HttpServletRequest request;
	@Inject private HttpServletResponse response;
	Object onActivate() {
		IFPStaticPage page = getPage();
		if (page != null && page.isRestricted() && auth.getAccount(request, response)
== null)
			return "start";
		return null;
	public boolean isTopLevel() {
		return getPage() == getPage().getSectionPage();
	void onEndElementFromBreadcrumb(Element e) {
		if ("a".equals(e.getName()))

As you can see, based on generics the method "getContent" should return a IFPStaticPageVersion.
This works fine when I use this Page.class directly.

Recently I wanted to extend this Page.class to add a few features specific to one project.
When I extended this class (no template so that it would use the Page.class template) I ended
up getting an error on the subclass. The error occurred because getContent returned a completely
different class instead of IFPStaticPageVersion. 

I work around I found to fix this is to override the getContent method so that it explicitly
defines the return type. But I had to do this in both Page.class and the subclass (Page2.class).
Here's my addition to both classes: 


	public IFPStaticPageVersion getContent() {
		return super.getContent();


Obviously I shouldn't have to do this to get the correct class back (especially not to both
Page.class AND Page2.class.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message