Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Objectteams » ClassCastException when instanceof is true
ClassCastException when instanceof is true [message #567144] Sat, 09 January 2010 18:04 Go to next message
Eugene Hutorny is currently offline Eugene HutornyFriend
Messages: 110
Registered: January 2010
Senior Member
The following code fails with ClassCastException on casting to Actor

Object[] roles = getAllRoles();
for(Object role : roles) {
if( role instanceof Actor) {
Actor server = (Actor) role;


The role class does not implement Actor interface but inherits its implementation from the super class
The problem disappears after adding clause 'implements Actor' to the concrete role class.

Complete sources to reproduce the problem are available on this http://hutorny.in.ua/wp-content/uploads/2010/01/exer8.zip
Re: ClassCastException when instanceof is true [message #567202 is a reply to message #567144] Sun, 10 January 2010 16:19 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Thanks for the report.

I've filed https://trac.objectteams.org/ot/ticket/333

Explanation for the curious: the two statements internally
use different versions of role Actor:
The instanceof check uses Service.Actor, this check passes.
The cast is internally translated as a call to a dynamically bound
synthetic method which then attempts a cast to Shaving.Actor,
which wrongly fails (due to a missing "implements" link in the
generated byte code).
Of course, this difference concerning Service.Actor and
Shaving.Actor shouldn't surface here.

best,
Stephan
Previous Topic:Suggestion on callin bindings
Next Topic:ClassCastException when instanceof is true
Goto Forum:
  


Current Time: Fri Apr 26 21:45:13 GMT 2024

Powered by FUDForum. Page generated in 0.03261 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top