Hi all,
I’ve got a bit of a weird problem. The other day I refactored some classes into new packages and renamed a few of them to be a bit more consistent. Since then I keep finding various classes that refer to ArrayLists or HashMaps containing references to these refactored classes that throw a ClassCastException.
The thing is most of the classes throwing the error don’t even need to know what class they’re referring to. EG:
// Snippet of rendering code from a completely separate class
int parentPlayer = 5;
if( parentPlayer != -1 ) {
float alpha = 1.0f;
if( parent.ghosts.get(parentPlayer) != null ) {
alpha = 0.3f;
} else if( parent.players.get(parentPlayer) != null &&
parent.players.get(parentPlayer).dead ) {
alpha = 0.1f;
}
g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha) );
}
In this case parent.ghosts and parent.players are HashMap<Integer, RenderableRemotePlayer> RenderableRemotePlayer is in the package: com.drentsoft.kryo.client.renderable
But when this code runs, during the get(parentPlayer) call, it tries to cast RenderableRemotePlayer to the old form of RemoteRenderablePlayer which was in the com.drentsoft.kryo.client package. I had a similar problem before where I was getting a nosuchfield error and I was able to work out that it was expecting the old class name and package and I managed to force it to work by temporarily replacing an if( game.player != null ) with a if( game.player instanceof NewClassName ).
This worked, I assume, because it forced the compiler to re-evaluate what classes were expected but how do I get this to happen automatically?
I’m using Netbeans 8 with a git repo on the src folder. I’m wondering if this is a bug in the way Netbeans 8 is handling refactoring or if it’s semi-expected behaviour and I just need to go one extra step to get it evaluating properly?
Overall it’s a bit weird and not something I’ve really experienced before but I’m worried that it’ll crop up in some unexpected rarely called code if I don’t work out how to fix it properly. Any help would be greatly appreciated.