java.lang.VerifyError: Bad type on operand stack

Continuing the discussion from How to configure ProGuard on Spring Boot 2.6.X and Java 1.11.X?:

Provide solution for the below problem

giving exception java.lang.VerifyError: Bad type on operand stack

pom.xml with java 11

    <plugins>
        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <proguardVersion>7.0.0</proguardVersion>
                <injar>${project.build.finalName}.jar</injar>
                <outjar>${project.build.finalName}.jar</outjar>
                <obfuscate>true</obfuscate>
                <proguardInclude>${project.basedir}/proguard.cfg</proguardInclude>
                <libs>
                    <lib>${java.home}/lib/jrt-fs.jar</lib>
                </libs>
            </configuration>
            <dependencies>
                <!-- https://mvnrepository.com/artifact/com.guardsquare/proguard-base -->
                <dependency>
                    <groupId>com.guardsquare</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>7.0.0</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                    </exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.im.invoicestatusprocessor.InvoiceStatusProcessorApplication
                        </mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

proguard.cfg

-target 11 ##Specify the java version number
-dontshrink ##Default is enabled, here the shrink is turned off, that is, the unused classes/members are not deleted.
-dontoptimize ##Default is enabled, here to turn off bytecode level optimization
-useuniqueclassmembernames ## Take a unique strategy for confusing the naming of class members
-adaptclassstrings ## After confusing the class name, replace it with a place like Class.forName(‘className’)
-dontnote
-ignorewarnings
-dontwarn
-keep public class * extends org.springframework.boot.web.support.SpringBootServletInitializer
-keepdirectories
-keepclasseswithmembers public class * { public static void main(java.lang.String[]);} ##Maintain the class of the main method and its method name
-keepclassmembers enum * { *; } ##Reserving enumeration members and methods
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Qualifier *;
@org.springframework.beans.factory.annotation.Value *;
@org.springframework.beans.factory.annotation.Required *;
@org.springframework.context.annotation.Bean *;
@org.springframework.context.annotation.Primary *;
@org.springframework.boot.context.properties.ConfigurationProperties ;
@org.springframework.boot.context.properties.EnableConfigurationProperties ;
@javax.inject.Inject ;
@javax.annotation.PostConstruct ;
@javax.annotation.PreDestroy ;
}
-keep @org.springframework.cache.annotation.EnableCaching class *
-keep @org.springframework.context.annotation.Configuration class *
-keep @org.springframework.boot.context.properties.ConfigurationProperties class *
-keep @org.springframework.boot.autoconfigure.SpringBootApplication class *
-allowaccessmodification
-keepattributes Annotation
-keepdirectories com.jayk.springboot.proguard.obfuscationdemo
-keepdirectories org.springframework.boot.autoconfigure
-keepclassmembers class * {
*** get
();
void set
(
);
}
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
public static ** fromValue(java.lang.String);
}
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient ;
!private ;
!private ;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired ;
@org.springframework.beans.factory.annotation.Autowired ;
@org.springframework.security.access.prepost.PreAuthorize ;
}

Dear @Siva_Madhupada ,

Welcome and thank you for posting your question on our community!

Is it possible that you are missing some libraryjars? You currently only defined

${java.home}/lib/jrt-fs.jar

While rt.jar or jmods are missing (if you are using Java 11).

Kind regards,

Ewout

1 Like

Thank you for quick response. Now exception changed. Now I got this exception

00:21:57.663 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.im.invoicestatusprocessor.InvoiceStatusProcessorApplication’: Unsatisfied dependenc
y expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.im.invoicestatuspr
ocessor.Application’ defined in URL [jar:file:/C:/Users/mramayya/Documents/GitHub/invoice_status_processor/target/invoice-status-processor-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/im/
invoicestatusprocessor/Application.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException
: Error creating bean with name ‘com.im.invoicestatusprocessor.g.b’ defined in com.im.invoicestatusprocessor.g.b defined in @EnableJpaRepositories declared on InvoiceStatusProcessorApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object

Hi Siva,

You could initially try creating a keep rule for some of the classes mentioned in the error, such as: com.im.invoicestatusprocessor.g.b. In addition, narrowing down the issue by disabling obfuscation, shrinking, or optimization one at a time to see which is causing the issue could help.

Best,
Jared

1 Like