We are using bcel library for code generation. And for some particualr scenarios our method size is exceeding the method size limit defined by java (65535 bytes) and we get the following error, org.apache.bcel.generic.ClassGenException: Branch target offset too large for short at org.apache.bcel.generic.BranchInstruction.dump(BranchInstruction.java:100) at org.apache.bcel.generic.InstructionList.getByteCode(InstructionList.java:980) at org.apache.bcel.generic.MethodGen.getMethod(MethodGen.java:616) When the method size limit is defined in java as 65535, why does the BCEL gives an error for 32767, in org.apache.bcel.generic.BranchInstruction.dump(DataOutputStream out) the check is for, if(Math.abs(index) >= 32767) // too large for short throw new ClassGenException("Branch target offset too large for short"); why not instead have the if(Math.abs(index) >= 65535) I tried this and then my application works fine, I want to be sure if thats the right approach.
From Java class specification for if_icmp<cond> If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2