Hi All,
I am facing Runtime Error while executing Custom code in Java 1.6, which was working fine with Java 1.4.
The issue is Typecasting Super Class Object to Sub Class Reference. Scenario is explained below:
Utils.Java ( Here we are doing Typecasting)
Z_BusinessObjectManager zOZBOM = new Z_BusinessObjectManager();
if (zOZBOM instanceof BOManager) {
BusinessObjectManager zOBOM = (BusinessObjectManager) userSessionData.getBOM(BusinessObjectManager.ISACORE_BOM);
return (Z_BusinessObjectManager) zOBOM; -- This is throwing Runtime Error - ClassCastException
}
Z_BusinessObjectManager.java (Here we are doing Inheritance)
public class Z_BusinessObjectManager extends BusinessObjectManager
{
public Z_BusinessObjectManager() {
super();
}
Stack Trace:
[EXCEPTION]
java.lang.ClassCastException: class com.sap.isa.businessobject.BusinessObjectManager:sap.com/b2b_ecom@com.sap.engine.boot.loader.ResourceMultiParentClassLoader@5f9d3ee6@alive incompatible with class com.ecom.isa.businessobject.Z_BusinessObjectManager:sap.com/b2b_ecom@com.sap.engine.boot.loader.ResourceMultiParentClassLoader@5f9d3ee6@alive
#Please assume imports and other set up is all fine. Only issue is Typecast.
What I have already tried is below:
First Assigning Sub Class Object to Super Class Reference. Then saving the retrun output from getBOM method to this Super class Object and then typecasting it. No use, same error.
instanceOf Operator is also not helping to prevent this code to execute -> means zOZBOM instanceof BOManager is returning true, which makes it further weird. Above of all, same code, same type cast is working fine in SAP 7.0 environment (JDK 1.4_19) where as throwiong exception in SAP 7.3 environment (JDK 1.6).
Any suggestion how to avoid this exception either by code or by any config change in Java Compiling or Runtime Environment Or any work around to achieve same functionality without error will be of great help.
- Akhil