Menu

#587 ClassFormatError

v5.2
closed-works-for-me
None
High
2019-12-06
2015-11-18
stegeto22
No

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)
1 Attachments

Discussion

  • Eric Lafortune

    Eric Lafortune - 2015-11-18

    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?

     
  • Eric Lafortune

    Eric Lafortune - 2015-11-18
    • status: open --> open-works-for-me
     
  • stegeto22

    stegeto22 - 2015-11-19

    I've attached a small example.

     
  • Philip Guin

    Philip Guin - 2017-04-13

    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:

    package main;
    
    public final class ProGuardBugTest
    {
        private static final boolean MY_CONSTANT_BOOL = false;
    
        private static final void foo()
        {
            if (!MY_CONSTANT_BOOL)
                return;
    
            System.out.println("Hello!");
        }
    
        public static void main(String[] args)
        {
            System.out.println("Starting...");
            foo();
            System.out.println("Finished!");
        }
    }
    
     

    Last edit: Philip Guin 2017-04-14
  • T. Neidhart

    T. Neidhart - 2019-12-06
    • status: open-works-for-me --> closed-works-for-me
    • Priority: 5 --> High
     
  • T. Neidhart

    T. Neidhart - 2019-12-06

    Tested both samples with 6.2.0 and they are correctly processed / executed after obfuscation.

     

Log in to post a comment.

MongoDB Logo MongoDB