simpleTag points MySimple which extends SimpleTagSupport; classicTag points MyClassic which extends TagSupport
Inside MyClassic.java, I can get parent without problem using MySimple parent = (MySimple)((TagAdapter)getParent()).getAdaptee();
According to lots of study materials saything that -- "An alternative way to find a specific parent tag is with the findAncestorWithClass() method provided by the SimpleTagSupport and TagSupport classes", so I tried to use following MySimple parent = (MySimple)findAncestorWithClass(this, MySimple.class);
That is really interesting. I tried your example and I got the same results.
But after modifying MyClassic.java to :
...it worked fine (yes, findAncestorWithClass is static in both SimpleTagSupport and TagSupport).
I think the reason comes from the fact that TagSupport's findAncestorWithClass method returns an object of Tag klass, and it would be illegal for that method to return an object of MySimple klass (which only implements JspTag, but does not implement Tag). So, it seems that findAncestorWithClass is intelligent enough to avoid producing a ClassCastException (at least tomcat's implementation, I have not read the specs yet to confirm this is the defined behaviour).