• No replies
1 Post

Pinned topic problem of "instanceof" operator with IBM's JDK1.5

‏2009-11-10T10:33:02Z |
When using the JDK1.5 and an obfuscated libarary(by Proguard), we randomly encountered an issue. The issue occured randomly. For the same application, maybe it can run first time ok, and when run it again the issue occured. After tracing the libarary, we found maybe the cause is that the "instanceof" operator gives wrong result. For example, see attached one class file, there is a method with signature:

private boolean a(dn, String, char c1, int, int, char, short)

In this method, the work flow should be(following is what should occur in our original class, and we do not know what has happened after the class being obfuscated.):
There is one object, assume it is named as "address". "address" is got by invoking another method a(int, int, char[], int, int, int, int).
Just follows the code to get "address", we print out the class named "address" and check the type of "address" by operator "instanceof":
Object address = a(...); //invoke a(int, int, char[], int, int, int, int);
System.out.println("--------" + ... + address.getClass().getName()
+":ca " + (address instanceof gI) +":cr " + (address instanceof W)
+":nm " + (address instanceof Name));
if(address instanceof gI)
gI ca = (gI)address;
System.out.println("--------" + ...); //print some properties of ca
When running our application, the result we got is:
---------1:-1:com.aspose.cells.gI:ca true:cr false:nm false
This means that "address" does is instance of gI. However, when the flow goes to next step,
System.out.println("no sn");
if(address instanceof gI)
else if(address instanceof W)
else if(address instanceof Name)
System.out.println("--------!!!!2Error here: " + address.getClass().getName()) + ":" + (s instanceof gI));
the output is:
no sn
--------!!!!2Error here: com.aspose.cells.gI:false
So, here address' class is still com.aspose.cells.gI but (address instanceof gI) is false.
And if we try following code:
gI v = (gI)address;
the flow will exit this method and all codes after that will be ignored just like they does not exist.

Any help will be appreciated. By the way, the obfuscated libarary can work fine with Sun's JDK.

Some other information:

The JDK:

java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pwi32devifx-20080907 (SR8a + IZ297
67 + IZ30684 + IZ31214 + IZ31213))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223ifx-20080811 (JIT
J9VM - 20080809_21892_lHdSMr
JIT - 20080620_1845_r8
GC - 200806_19)
JCL - 20080907

The OS: Windows XP