ClassFormatError
Java class file shrinker, optimizer, obfuscator, and preverifier
Brought to you by:
guardsquare
The following code produces a ClassFormatError.
package test;
class OptTest {
private static final boolean isCheckActive = true;
private int value = 0;
public int getValue() {
if (isCheckActive) {
return value++;
}
return 0;
}
}
The return 0 will be optimized away, but the LineNumerTable is not adjusted. So when loading the class, an error is reported:
Exception in thread "main" java.lang.ClassFormatError: Invalid pc in LineNumberTable in class file test/OptTest
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Thanks for your report. Note that the java compiler already optimizes away if-constructs with final boolean flags. Changing the code slightly so the compiler leaves the code alone and ProGuard indeed optimizes it, I can't reproduce the issue though. ProGuard removes the line numbers that correspond to removed code. Can you double-check that you are working with ProGuard 5.2? Can you add your compiled class file and ProGuard configuration file?
I've attached a small example.
Hi Eric, I'm running into the same issue with version 5.3.3, it would seem. I've attached a minimum test case that reproduces it (includes the test jar, the proguard config file, and a bugged version of the test jar, along with some bats you might have to tinker with first.) All I'm doing is shrinking the jar to get the issue, no obfuscation or anything. I'm running 64-bit Java 8 on Windows 10, fwiw. Thanks!
EDIT: Here's the original test code (one file), though I used an Eclipse project to compile and export this as a runnable jar:
Last edit: Philip Guin 2017-04-14
Tested both samples with 6.2.0 and they are correctly processed / executed after obfuscation.