You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jorge Merlino <jo...@ipcontact.com.uy> on 2009/03/02 21:19:03 UTC

Strange exception

Hi,

I'm trying use the tapestry tree component found in http://wiki.apache.org/tapestry/Tapestry5TreeComponent 
but I'm stuck with a very strange exception which is this:

java.lang.ClassCastException: uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode

Java is trying to cast an object to its same class and failing to do so! This works if I create the TreeNode object 
in the tapestry page class but does not If I create the TreeNode objects in another class and return them to
the page class via a procedure return value.

Here is some more context for the exception if it helps.

Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: Failure reading parameter 'source' of component Index:tree_0: uy.com.ipcontact.webjastconf.components.TreeNo
de cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode [at context:Index.tml, line 3, column 73]
  at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:932)
  at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$200(ComponentPageElementImpl.java:50)
  at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$13.render(ComponentPageElementImpl.java:499)
  at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
  ... 64 more
Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: Failure reading parameter 'source' of component Index:tree_0: uy.com.ipcontact.webjastconf.components.TreeNo
de cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode [at context:Index.tml, line 3, column 73]
  at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:290)
  at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:315)
  at uy.com.ipcontact.webjastconf.components.Tree._$read_parameter_source(Tree.java)
  at uy.com.ipcontact.webjastconf.components.Tree.setupRender(Tree.java:55)
  at uy.com.ipcontact.webjastconf.components.Tree.setupRender(Tree.java)
  at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$13$1.run(ComponentPageElementImpl.java:495)
  at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:917)
  ... 67 more
Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to uy.com.ipcontact.webjastconf.components.T
reeNode [at context:Index.tml, line 3, column 73]
  at org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:57)
  at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:284)
  ... 73 more
Caused by: java.lang.ClassCastException: uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode
  at uy.com.ipcontact.webjastconf.pages.Index.getTreeNodes(Index.java:46)
  at $PropertyConduit_11fc8c4abe7.get($PropertyConduit_11fc8c4abe7.java)
  at org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:53)
  ... 74 more

Thank you for your time

Best regards
	Jorge

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Strange exception

Posted by Jorge Merlino <jo...@ipcontact.com.uy>.
El Lun 02 Mar 2009 18:26:32 Carl Crowder escribió:
> This is just a vague guess, but as far as I *think* that class name
> isn't the only thing Java uses to compare two classes when casting. So
> if you have defined your TreeNode class in more than once place, it's
> possible that the class you're passing it and the class Tapestry is
> trying to use were loaded by different classloaders from different
> places. When you define it in the Tapestry page class I guess it only
> uses the one class file so it works fine. Check how many TreeNode.class
> files you have on your classpath, in jars or locally.

Yes I think that's the problem. I found about it in the tapestry faq just 
after I sent this email :)

Best regards
	Jorge

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Strange exception

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 02 Mar 2009 17:26:32 -0300, Carl Crowder <ca...@taptu.com>  
escreveu:

> This is just a vague guess, but as far as I *think* that class name  
> isn't the only thing Java uses to compare two classes when casting. So  
> if you have defined your TreeNode class in more than once place, it's  
> possible that the class you're passing it and the class Tapestry is  
> trying to use were loaded by different classloaders from different  
> places.

This is not a vague guess, it is a very correct explanation. Tapestry  
loads page, component and mixin classes using a special classloader that  
changes them on the fly. That's why you must never, never, ever put a  
class or interface that is not a component in the components, pages, or  
mixins package. That's also why you cannot instantiate a component, page  
or mixin in your package: you must let Tapestry to do that.

The solution is to move the TreeNode class and ITree interface to another  
package. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Strange exception

Posted by Carl Crowder <ca...@taptu.com>.
This is just a vague guess, but as far as I *think* that class name 
isn't the only thing Java uses to compare two classes when casting. So 
if you have defined your TreeNode class in more than once place, it's 
possible that the class you're passing it and the class Tapestry is 
trying to use were loaded by different classloaders from different 
places. When you define it in the Tapestry page class I guess it only 
uses the one class file so it works fine. Check how many TreeNode.class 
files you have on your classpath, in jars or locally.

Carl

Jorge Merlino wrote:
> Hi,
> 
> I'm trying use the tapestry tree component found in http://wiki.apache.org/tapestry/Tapestry5TreeComponent 
> but I'm stuck with a very strange exception which is this:
> 
> java.lang.ClassCastException: uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode
> 
> Java is trying to cast an object to its same class and failing to do so! This works if I create the TreeNode object 
> in the tapestry page class but does not If I create the TreeNode objects in another class and return them to
> the page class via a procedure return value.
> 
> Here is some more context for the exception if it helps.
> 
> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: Failure reading parameter 'source' of component Index:tree_0: uy.com.ipcontact.webjastconf.components.TreeNo
> de cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode [at context:Index.tml, line 3, column 73]
>   at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:932)
>   at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$200(ComponentPageElementImpl.java:50)
>   at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$13.render(ComponentPageElementImpl.java:499)
>   at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
>   ... 64 more
> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: Failure reading parameter 'source' of component Index:tree_0: uy.com.ipcontact.webjastconf.components.TreeNo
> de cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode [at context:Index.tml, line 3, column 73]
>   at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:290)
>   at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:315)
>   at uy.com.ipcontact.webjastconf.components.Tree._$read_parameter_source(Tree.java)
>   at uy.com.ipcontact.webjastconf.components.Tree.setupRender(Tree.java:55)
>   at uy.com.ipcontact.webjastconf.components.Tree.setupRender(Tree.java)
>   at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$13$1.run(ComponentPageElementImpl.java:495)
>   at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:917)
>   ... 67 more
> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to uy.com.ipcontact.webjastconf.components.T
> reeNode [at context:Index.tml, line 3, column 73]
>   at org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:57)
>   at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:284)
>   ... 73 more
> Caused by: java.lang.ClassCastException: uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode
>   at uy.com.ipcontact.webjastconf.pages.Index.getTreeNodes(Index.java:46)
>   at $PropertyConduit_11fc8c4abe7.get($PropertyConduit_11fc8c4abe7.java)
>   at org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:53)
>   ... 74 more
> 
> Thank you for your time
> 
> Best regards
> 	Jorge
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Strange exception

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 02 Mar 2009 17:19:03 -0300, Jorge Merlino  
<jo...@ipcontact.com.uy> escreveu:

> I'm trying use the tapestry tree component found in  
> http://wiki.apache.org/tapestry/Tapestry5TreeComponent
> but I'm stuck with a very strange exception which is this:

By the way, that wiki page does not follow the Tapestry best practices  
about two issues:

1) JavaScript: intead of using <script> tags in components, you should use  
RenderSupport.  
http://wiki.apache.org/tapestry/Tapestry5AndJavaScriptExplained couldn't  
explain it better.

2) Programatically generating HTML in a component: you should  
MarkupWriter.writeRaw() just when element() is not enough (it it is enough  
99.9999% of the time). element() guaranties that you generate valid markup.

Short and simple example:

	@BeforeRenderTemplate
	public boolean render(MarkupWriter writer) {
		
		if (message != null && message.trim().length() > 0) {
			
			writer.element("div", "class", "t-crud-message"); // <div  
class="t-crud-message">
			
			writer.element("p");    // <p>
			writer.write(message);  //     message
			writer.end();           // </p>
			
			writer.end();           // </div>
			
		}
		
		return false;
		
	}


>
> java.lang.ClassCastException:  
> uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to  
> uy.com.ipcontact.webjastconf.components.TreeNode
>
> Java is trying to cast an object to its same class and failing to do so!  
> This works if I create the TreeNode object
> in the tapestry page class but does not If I create the TreeNode objects  
> in another class and return them to
> the page class via a procedure return value.
>
> Here is some more context for the exception if it helps.
>
> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException:  
> Failure reading parameter 'source' of component Index:tree_0:  
> uy.com.ipcontact.webjastconf.components.TreeNo
> de cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode  
> [at context:Index.tml, line 3, column 73]
>   at  
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:932)
>   at  
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$200(ComponentPageElementImpl.java:50)
>   at  
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$13.render(ComponentPageElementImpl.java:499)
>   at  
> org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
>   ... 64 more
> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException:  
> Failure reading parameter 'source' of component Index:tree_0:  
> uy.com.ipcontact.webjastconf.components.TreeNo
> de cannot be cast to uy.com.ipcontact.webjastconf.components.TreeNode  
> [at context:Index.tml, line 3, column 73]
>   at  
> org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:290)
>   at  
> org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:315)
>   at  
> uy.com.ipcontact.webjastconf.components.Tree._$read_parameter_source(Tree.java)
>   at  
> uy.com.ipcontact.webjastconf.components.Tree.setupRender(Tree.java:55)
>   at uy.com.ipcontact.webjastconf.components.Tree.setupRender(Tree.java)
>   at  
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl$13$1.run(ComponentPageElementImpl.java:495)
>   at  
> org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:917)
>   ... 67 more
> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException:  
> uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to  
> uy.com.ipcontact.webjastconf.components.T
> reeNode [at context:Index.tml, line 3, column 73]
>   at  
> org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:57)
>   at  
> org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.readParameter(InternalComponentResourcesImpl.java:284)
>   ... 73 more
> Caused by: java.lang.ClassCastException:  
> uy.com.ipcontact.webjastconf.components.TreeNode cannot be cast to  
> uy.com.ipcontact.webjastconf.components.TreeNode
>   at uy.com.ipcontact.webjastconf.pages.Index.getTreeNodes(Index.java:46)
>   at $PropertyConduit_11fc8c4abe7.get($PropertyConduit_11fc8c4abe7.java)
>   at  
> org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:53)
>   ... 74 more
>
> Thank you for your time
>
> Best regards
> 	Jorge
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>



-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org