java.lang.VerifyError: Bad return type error occurs after proguard confusion

1. Problem description

After using proguard to confuse the jar package, the following error will be reported when starting:

 Exception in thread "main" java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    aaa/bbb/ccc/ddd/eee/e/c.openConnection(Ljava/net/URL;)Ljava/net/URLConnection; @80: areturn
  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'java/net/URLConnection' (from method signature)
  Current Frame:
    bci: @80
    flags: {
    
     }
    locals: {
    
     }
    stack: {
    
     'java/lang/Object' }
  Bytecode:
    0x0000000: b200 20bb 0014 59b7 0029 1203 b600 2a2b
    0x0000010: b600 2eb6 002a b600 2cb6 0025 2a2b b700
    0x0000020: 314d 2ab4 001f 2bb6 002e b900 3502 0099
    0x0000030: 0020 2cc1 0016 9900 19bb 0008 592c c000
    0x0000040: 162a b400 1d2a b400 1eb7 0021 a700 042c
    0x0000050: b0                                     
  Stackmap Table:
    full_frame(@79,{
    
    Top,Top,Object[#24]},{
    
    })
    full_frame(@80,{
    
    },{
    
    Object[#18]})

	at aaa.bbb.ccc.ddd.eee.e.a.<init>(XxxxClassLoader.java:41)
	at aaa.bbb.ccc.ddd.eee.e.f.createClassLoader(XxxxxLauncher.java:32)
	at org.springframework.boot.loader.Launcher.createClassLoader(Launcher.java:64)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
	at aaa.bbb.ccc.ddd.eee.e.f.a(XxxxLauncher.java:27)
	at aaa.bbb.ccc.ddd.eee.e.f.main(XxxxLauncher.java:23)

That's embarrassing. . . After searching on the Internet, the cause of java.lang.VerifyError: Bad return type is:

JVM 在加载一个类时,会去校验类的正确性,只有类文件不合法才会报这个Error

I searched around, but couldn't find any relevant answers. Basically, it was caused by the version and jar package duplication. The problem is that I don't have these two problems at all. . I found a bunch of related problems in the official issues, which are similar to my mistakes

insert image description here

After a day of fruitless work, I found a solution at night. .

Two, the solution

Found the problem from the error log, in the following line exception:

at aaa.bbb.ccc.ddd.eee.e.a.<init>(XxxxClassLoader.java:41)

Use Bytecode-Viewer to open the jar after confusion, and compare it with the jar package without confusion, and found the secret:

aaa/bbb/ccc/ddd/eee/e/c.openConnection(Ljava/net/URL;)Ljava/net/URLConnection; @80:

insert image description here
Corresponds to the exception in:

  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'java/net/URLConnection' (from method signature)

What is needed is URLConnection, but what is given is Object, so it causes an exception. This must be caused by confusion. Adjust the proguard configuration. The following is what I can use after adjustment:

      <!-- proguard混淆插件-->
      <plugin>
        <groupId>com.github.wvengen</groupId>
        <artifactId>proguard-maven-plugin</artifactId>
        <version>2.5.3</version>
        <executions>
          <execution>
            <!-- 打包的时候开始混淆-->
            <phase>package</phase>
            <goals>
              <goal>proguard</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <injar>${
    
    project.build.finalName}.jar</injar>
          <outjar>${
    
    project.build.finalName}.jar</outjar>
          <obfuscate>true</obfuscate>
          <putLibraryJarsInTempDir>true</putLibraryJarsInTempDir>
          <options>
            <option>-target 1.8</option>
            <option>-dontnote</option>
            <option>-dontshrink</option>
            <option>-dontoptimize</option>
            <option>-adaptclassstrings</option>
            <option>-ignorewarnings</option>
            <option>-dontskipnonpubliclibraryclasses</option>
            <option>-dontskipnonpubliclibraryclassmembers</option>
            <option>-dontusemixedcaseclassnames</option>
            <option>-keepdirectories</option>
            <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod</option>
            <option>-keepclassmembers enum * {
    
     *; }</option>
            <option>-keepparameternames</option>
            <option>-flattenpackagehierarchy aaa.fffff.xxxx.ddd.aaa</option>
            <option>
              -keepclassmembers class *{
    
    
                public static void main(java.lang.String[]);
              }
            </option>
          </options>
          <libs>
            <!-- 添加依赖 java8-->
            <lib>${
    
    java.home}/lib/rt.jar</lib>
            <lib>${
    
    java.home}/lib/jce.jar</lib>
          </libs>
        </configuration>
      </plugin>

The jar package bytecode packaged with the above configuration is as follows:

insert image description here

Guess you like

Origin blog.csdn.net/mashangzhifu/article/details/123155567