Hi everyone, this is the first time I post in this or any forum, so I hope I am doing it the correct way.

I have a problem at work with a bug where the application is throwing a ClassCastException, this is the scenario: The application authorizes transactions like sales, refunds, rollbacks. There is a base core module, which we are not allowed to modify, just use the classes in it and derive from them, so we have some POJOs that are used to store the transaction information, the basic structure is like this:


Code:
public class BaseTransaction{
...
}
public class ModuleTransaction extends BaseTransaction{

}

public class BaseRefundTransaction extends BaseTransaction{
}

public class ModuleRefundTransaction extends ModuleTransaction{
}
In the code, ModuleRefundTransaction uses a lot of things that come from ModuleTransaction, thatīs why it is extending it and not BaseRefundTransaction .

The problem is that the base module does a lot of processing for refunds so, it is doing stuff like:

Code:
BaseRefundTransaction  refundTxn = (BaseRefundTransaction )helper.getRefundTransaction();
and there we get the ClassCastException, because our helper is returning a ModuleRefundTransaction not a BaseRefundTransaction.

I have to fix this bug, but I donīt see any elegant solution, I think that the whole thing has a bad design, but maybe I am not experienced enough to see a good solution. The main problem is that we canīt change anything in the base module.
My first lazy thought was to start copying all the code in the base module into our module and use our class, but that's just not good.

Any suggestions? Thank you very much.