Abnormal behavior of class files generated by ProGuard
Java class file shrinker, optimizer, obfuscator, and preverifier
Brought to you by:
guardsquare
Description:
The original jar throws an exception while the obfuscated jar exits normally.
Reproducing steps:
Generate the output (referred to as C0-outjars.jar for following steps) for the attached C0-injars.jar.
Run the two jars.
$ java -cp C0-injars.jar C0
Exception in thread "main" java.lang.NegativeArraySizeException
at C0.main(Unknown Source)
$ java -cp C0-outjars.jar C0
$ echo $?
0
This issue may relate to #681 and #682.
This issue may also relate to an issue of r8. https://issuetracker.google.com/issues/72413928.
Note that the
C0.classhere is different from that of https://issuetracker.google.com/issues/72413928Sorry, this is not a bug. The behavior is expected. java throws an exception since the program allocates an unused array with a negative size, while the optimization of proguard removes the allocation instruction.
Thanks for your report and the update. ProGuard indeed makes a few pragmatic assumptions, like code not intentionally throwing NegativeArraySizeExceptions or ArrayIndexOutOfBoundsExceptions. The assumptions don't hold for this intentionally obfuscated code. You can probably work around it with with the ProGuard system property
-Doptimize.conservatively.