java.lang.VerifyError:期望分支目标上的stackmap帧 [英] java.lang.VerifyError: Expecting a stackmap frame at branch target

查看:705
本文介绍了java.lang.VerifyError:期望分支目标上的stackmap帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成功编译项目并与Maven一起构建。这是我的第一个maven项目。但我不知道为什么我会收到以下错误。



在tomcat上部署战争并点击我的网址并在浏览器中显示以下错误。

  java.lang.VerifyError:期望分支目标72的堆栈图帧
异常详细信息:
位置:
com / ebetinc / frontend / presentation / components / Login。 isToteAvailable(Ljava / lang / String; Lcom / ebetinc / frontend / dao / DatabaseDao;)Z @ 46:lookupswitch
原因:
此位置的预期堆栈图帧。
字节码:
0000000:043d 2bb9 03a4 0100 4e2a c601 1c13 03a6
0000010:2ab8 03aa 9900 0803 3da7 010d 2db8 03ad
0000020:9900 692a 3a04 0236 0519 04b6 03b1 ab00
0000030:0000 003a 0000 0002 0000 0626 0000 002c
0000040:0000 0644 0000 001a 0019 0413 03b3 b603
0000050:b599 0017 0336 05a7 0011 1904 1303 b7b6
0000060:03b5 9900 0604 3605 1505 ab00 0000 001c $ b $ 00 0000070:0000 0002 0000 0000 0000 001a 0000 0001
0000080:0000 001a 033d a700 a02d b803 ba99 0099
0000090:2a3a 0402 3605 1904 b603 b1ab 0000 006a
00000a0:0000 0004 0000 af34 0000 0029 0000 af4c $ b $ 00 00000b0:0000 003a 0000 af4d 0000 004b 0015 51cb
00000c0:0000 005c 1904 1303 bcb6 03b5 9900 3903
00000d0:3605 a700 3319 0413 03be b603 b599 0028
00000e0:0436 05a7 0022 1904 1303 c0b6 03b5 9900
00000f0:1705 3605 a700 1119 0413 03c2 b603 b599
0000100:0006 0636 0515 05aa 0000 001f 0000 00 00
0000110:0000 0003 0000 001d 0000 001d 0000 001d
0000120:0000 001d 033d 1cac
Stackmap表:
append_frame(@ 28,整数,对象[#931])
append_frame(@ 73,Object [#200],Integer)
same_frame(@ 90)
same_frame(@ 104)
same_frame(@ 132)
chop_frame(@ 134,2)
same_frame(@ 137)
append_frame(@ 196,对象[#200],整数)
same_frame(@ 213)
same_frame(@ 230)
same_frame(@ 247)
same_frame(@ 261)
same_frame(@ 292)
chop_frame(@ 294,2)

任何人都可以抛出一些输入吗?感谢您的帮助。



配置:

  Java 1.7 
Maven 3+


解决方案

嗨这与某些相关应用程序中的字节码。 (请参阅此关于Java 7的兼容性更改的说明 http:// www .oracle.com / technetwork / java / javase / compatibility-417013.html #incoompatibilities ,看看JSR 202下面的一些行)



你可以




  • 使用JDK 7重新编译所有来源

  • 或者如果您无权访问源


    • 使用 java with paramter -XX:-UseSplitVerifier

    • 如果您使用开关面对promblems,请切换到Java 6




编辑即使答案已经有点旧了。由于目前的情况,我添加了一些更详细的解释。



类文件中的 StackMapTable 属性是,甚至当时没有记录,在Java 6中引入。



Foo.java

  public class Foo {
public static boolean bar(String s){
if(s.length()== 0){
return true;
}
返回false;
}
}

$ java -version
java版1.6.0
Java(TM)SE运行时环境(版本1.6.0- b105)
$ javac Foo.java
$ javap -c -v Foo
编译自Foo.java
公共类Foo扩展java.lang.Object
SourceFile:Foo.java
次要版本:0
主要版本:50
...
public static boolean bar(java.lang.String);
代码:
Stack = 1,Locals = 1,Args_size = 1
0:aload_0
1:invokevirtual#2; //方法java / lang / String.length :()I
4:ifne 9
7:iconst_1
8:ireturn
9:iconst_0
10:ireturn
LineNumberTable:
第3行:0
第4行:7
第6行:9

StackMapTable:number_of_entries = 1
frame_type = 9 / *相同* /
}

类验证程序没有检查属性是否在该类是否。



以下创建文件 Foo.class ,不带 StackMatTable 属性。



FooDump.java

  import org.objectweb.asm。*; 
import java.io. *;

公共类FooDump实现操作码{

public static void main(String [] args)抛出异常{
FileOutputStream fos = new FileOutputStream(Foo.class );
fos.write(dump());
fos.close();
}

public static byte [] dump()抛出异常{
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;

cw.visit(V1_6,ACC_PUBLIC + ACC_SUPER,Foo,null,java / lang / Object,
null);

MethodVisitor mv = cw.visitMethod(ACC_PUBLIC,< init>,()V,null,
null);
mv.visitCode();
mv.visitVarInsn(ALOAD,0);
mv.visitMethodInsn(INVOKESPECIAL,java / lang / Object,< init>,()V,
false);
mv.visitInsn(RETURN);
mv.visitMaxs(1,1);
mv.visitEnd();

mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC,bar,
(Ljava / lang / String;)Z,null,null);
mv.visitCode();
mv.visitVarInsn(ALOAD,0);
mv.visitMethodInsn(INVOKEVIRTUAL,java / lang / String,length,()I,
false);
Label l0 = new Label();
mv.visitJumpInsn(IFNE,l0);
mv.visitInsn(ICONST_1);
mv.visitInsn(IRETURN);
mv.visitLabel(l0);
//这一行将生成StackMapTable属性
// mv.visitFrame(Opcodes.F_SAME,0,null,0,null);
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
mv.visitMaxs(1,1);
mv.visitEnd();

cw.visitEnd();
返回cw.toByteArray();
}
}

编译并运行它

  $ javac -cp asm-5.2.jar:asm-util-5.2.jar:。 FooDump.java 
$ java -cp asm-5.2.jar:asm-util-5.2.jar:。 FooDump

检查 StackMapTable 属性是否在文件中

  $ javap -c -v Foo 
公共类Foo扩展java.lang.Object
次要版本:0
主要版本:50
...
public static boolean bar(java.lang.String);
代码:
Stack = 1,Locals = 1,Args_size = 1
0:aload_0
1:invokevirtual#16; //方法java / lang / String.length :()I
4:ifne 9
7:iconst_1
8:ireturn
9:iconst_0
10:ireturn
}

FooDemo.java

  public class FooDemo {
public static void main(String [] args){
System.out.println(output: + Foo.bar());
}
}

$ java -version
java版1.6.0
Java(TM)SE运行时环境(版本1.6.0- b105)
$ javac FooDemo.java
$ java FooDemo
输出:true

使用Java 7,类验证已更改。



对于类文件版本50(Java 6),如果 StackMapTable 缺失或错误,则检查有故障转移(请参阅: jvms-4.10.1 )。



使用 Foo 类Java 6运行检查。

  $ java -version 
java version1.7.0
Java(TM)SE运行时环境(版本1.7。 0-b147)

$ javap -c -v Foo
Classfile /home/suboptimal/playground/Foo.class
最后修改日期2017年6月9日;大小232字节
MD5校验和5a7ea4a5dd2f6d1bcfddb9ffd720f9c9
公共类Foo
次要版本:0
主要版本:50< - 类文件Java 6
...

$ javac FooDemo.java
$ java FooDemo
输出:true

类文件版本51(Java 7)不再发生此故障转移。



创建 Foo Java 7的类版本修改 FooDump.java 的代码。

  // cw.visit(V1_6,ACC_PUBLIC + ACC_SUPER,Foo,null,java / lang / Object,null); 
cw.visit(V1_7,ACC_PUBLIC + ACC_SUPER,Foo,null,java / lang / Object,null);

编译并运行它

  $ javac -cp asm-5.2.jar:asm-util-5.2.jar:。 FooDump.java 
$ java -cp asm-5.2.jar:asm-util-5.2.jar:。 FooDump

检查它是否为班级版本51

  $ java -version 
java version1.7.0
Java(TM)SE运行时环境(版本1.7.0-b147)

$ javap -c -v Foo
Classfile /home/suboptimal/playground/Foo.class
最后修改日期:2017年6月9日;大小232字节
MD5校验和cfd57fb547ac98a1b2808549f5e9e8c1
公共类Foo
次要版本:0
主要版本:51< - 类文件Java 7
...

$ javac FooDemo.java
$ java FooDemo
线程main中的异常java.lang.VerifyError:期望方法Foo.bar中的分支目标9处的stackmap帧(Ljava / lang / String;)Z偏移4

在Java 7中,<$ c $的类型检查c>使用选项属性以回退到Java 6故障转移机制jsp-140102.html#BehavioralOptionsrel =noreferrer> UseSplitVerifier

  $ java -version 
java版本1.7.0
Java(TM)SE运行时环境(版本1.7.0-b147)

$ java -XX:-UseSplitVerifier FooDemo
输出:在$ 8中验证 StackMapTable 属性因为我是强制性的,并删除了选项 UseSplitVerifier

  $ java -version 
java版本1.8.0
Java(TM)SE运行时环境(版本1.8.0-b132)

$ javap -c -v Foo
类文件/home/suboptimal/playground/Foo.class
最后修改日期:2017年6月9日;大小232字节
MD5校验和cfd57fb547ac98a1b2808549f5e9e8c1
公共类Foo
次要版本:0
主要版本:51< - 类文件Java 7
...

$ javac FooDemo.java
$ java FooDemo
线程main中的异常java.lang.VerifyError:期望分支目标的堆栈图帧9

$ java -XX:-UseSplitVerifier FooDemo
Java HotSpot(TM)64位服务器VM警告:忽略选项UseSplitVerifier;支持在8.0
中删除线程main中的异常java.lang.VerifyError:期望分支目标的堆栈图帧9

note 要始终使用Java 6/7/8的初始版本,意图是从一开始就表明行为是存在的。



你可能会发现一些建议让它运行Java 8 ...

  $ java -noverify FooDemo 
输出:true

$ java -Xverify:none FooDemo
输出:true

note 这会禁用字节码验证程序。请记住永远不要禁用生产中的字节码验证系统


Successfully compiled the project and build as well with Maven. This is my first maven project. But I have no idea why I'm getting the below error.

Deployeed the war on tomcat and hit my url and the below error shown in my browser.

java.lang.VerifyError: Expecting a stackmap frame at branch target 72
Exception Details:
  Location:
    com/ebetinc/frontend/presentation/components/Login.isToteAvailable(Ljava/lang/String;Lcom/ebetinc/frontend/dao/DatabaseDao;)Z @46: lookupswitch
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 043d 2bb9 03a4 0100 4e2a c601 1c13 03a6
    0000010: 2ab8 03aa 9900 0803 3da7 010d 2db8 03ad
    0000020: 9900 692a 3a04 0236 0519 04b6 03b1 ab00
    0000030: 0000 003a 0000 0002 0000 0626 0000 002c
    0000040: 0000 0644 0000 001a 0019 0413 03b3 b603
    0000050: b599 0017 0336 05a7 0011 1904 1303 b7b6
    0000060: 03b5 9900 0604 3605 1505 ab00 0000 001c
    0000070: 0000 0002 0000 0000 0000 001a 0000 0001
    0000080: 0000 001a 033d a700 a02d b803 ba99 0099
    0000090: 2a3a 0402 3605 1904 b603 b1ab 0000 006a
    00000a0: 0000 0004 0000 af34 0000 0029 0000 af4c
    00000b0: 0000 003a 0000 af4d 0000 004b 0015 51cb
    00000c0: 0000 005c 1904 1303 bcb6 03b5 9900 3903
    00000d0: 3605 a700 3319 0413 03be b603 b599 0028
    00000e0: 0436 05a7 0022 1904 1303 c0b6 03b5 9900
    00000f0: 1705 3605 a700 1119 0413 03c2 b603 b599
    0000100: 0006 0636 0515 05aa 0000 001f 0000 0000
    0000110: 0000 0003 0000 001d 0000 001d 0000 001d
    0000120: 0000 001d 033d 1cac                    
  Stackmap Table:
    append_frame(@28,Integer,Object[#931])
    append_frame(@73,Object[#200],Integer)
    same_frame(@90)
    same_frame(@104)
    same_frame(@132)
    chop_frame(@134,2)
    same_frame(@137)
    append_frame(@196,Object[#200],Integer)
    same_frame(@213)
    same_frame(@230)
    same_frame(@247)
    same_frame(@261)
    same_frame(@292)
    chop_frame(@294,2)

Can anyone throw some inputs ? Thanks for any help.

Configuration:

Java 1.7
Maven 3+

解决方案

Hi this is related to some bytecode in your application. (see this note on compatibility changes for Java 7 http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#incompatibilities, look there some lines below for JSR 202)

You can either

  • recompile all sources with JDK 7
  • or in case you have no access to the source
    • use java with paramter -XX:-UseSplitVerifier
    • or switch to Java 6 if you face promblems using the switch

edit Even the answer is already a bit old. Because of a current case I add some more detailed explanation.

The StackMapTable attribute in the class file was, even not documented at that time, introduced with Java 6.

Foo.java

public class Foo {
    public static boolean bar(String s) {
        if (s.length() == 0) {
            return true;
        }
        return false;
    }
}

$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
$ javac Foo.java
$ javap -c -v Foo
Compiled from "Foo.java"
public class Foo extends java.lang.Object
  SourceFile: "Foo.java"
  minor version: 0
  major version: 50
...
public static boolean bar(java.lang.String);
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   invokevirtual   #2; //Method java/lang/String.length:()I
   4:   ifne    9
   7:   iconst_1
   8:   ireturn
   9:   iconst_0
   10:  ireturn
  LineNumberTable: 
   line 3: 0
   line 4: 7
   line 6: 9

  StackMapTable: number_of_entries = 1
   frame_type = 9 /* same */
}

The class verifier did no check if the attribute was in the class or not.

Following creates the file Foo.class without the StackMatTable attribute.

FooDump.java

import org.objectweb.asm.*;
import java.io.*;

public class FooDump implements Opcodes {

    public static void main(String[] args) throws Exception {
        FileOutputStream fos = new FileOutputStream("Foo.class");
        fos.write(dump());
        fos.close();
    }

    public static byte[] dump() throws Exception {
        ClassWriter cw = new ClassWriter(0);
        FieldVisitor fv;

        cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "Foo", null, "java/lang/Object",
            null);

        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, 
            null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", 
            false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "bar", 
            "(Ljava/lang/String;)Z", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "length", "()I", 
            false);
        Label l0 = new Label();
        mv.visitJumpInsn(IFNE, l0);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l0);
        // this line would generate the StackMapTable attribute
        // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();

        cw.visitEnd();
        return cw.toByteArray();
    }
}

compile and run it

$ javac -cp asm-5.2.jar:asm-util-5.2.jar:. FooDump.java
$ java -cp asm-5.2.jar:asm-util-5.2.jar:. FooDump

check that the StackMapTable attribute is not in the file

$ javap -c -v Foo
public class Foo extends java.lang.Object
  minor version: 0
  major version: 50
...
public static boolean bar(java.lang.String);
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   invokevirtual   #16; //Method java/lang/String.length:()I
   4:   ifne    9
   7:   iconst_1
   8:   ireturn
   9:   iconst_0
   10:  ireturn
}

FooDemo.java

public class FooDemo {
    public static void main(String[] args) {
        System.out.println("output: " + Foo.bar(""));
    }
}

$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
$ javac FooDemo.java
$java FooDemo 
output: true

With Java 7 the class verification was changed.

For class files version 50 (Java 6) the check had a failover if the StackMapTable was missing or wrong (see: jvms-4.10.1).

Run the check with the Foo class version of Java 6.

$ java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)

$ javap -c -v Foo
Classfile /home/suboptimal/playground/Foo.class
  Last modified Jun 9, 2017; size 232 bytes
  MD5 checksum 5a7ea4a5dd2f6d1bcfddb9ffd720f9c9
public class Foo
  minor version: 0
  major version: 50 <-- class file Java 6
...

$ javac FooDemo.java
$ java FooDemo
output: true

This failover did not occur anymore for class files version 51 (Java 7).

To create a Foo class version of Java 7 amend the code of FooDump.java.

// cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "Foo", null, "java/lang/Object", null);
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "Foo", null, "java/lang/Object", null);

compile and run it

$ javac -cp asm-5.2.jar:asm-util-5.2.jar:. FooDump.java
$ java -cp asm-5.2.jar:asm-util-5.2.jar:. FooDump

check that it's a class version 51

$ java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)

$ javap -c -v Foo
Classfile /home/suboptimal/playground/Foo.class
  Last modified Jun 9, 2017; size 232 bytes
  MD5 checksum cfd57fb547ac98a1b2808549f5e9e8c1
public class Foo
  minor version: 0
  major version: 51 <-- class file Java 7
...

$ javac FooDemo.java
$ java FooDemo
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 9 in method Foo.bar(Ljava/lang/String;)Z at offset 4

In Java 7 the type check for the StackMapTable attribute can be disabled to step back to the Java 6 failover mechanism using option UseSplitVerifier.

$ java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)

$ java -XX:-UseSplitVerifier FooDemo
output: true

In Java 8 the verification of the StackMapTable attribute became mandatory and the option UseSplitVerifier was removed.

$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)

$ javap -c -v Foo
Classfile /home/suboptimal/playground/Foo.class
  Last modified Jun 9, 2017; size 232 bytes
  MD5 checksum cfd57fb547ac98a1b2808549f5e9e8c1
public class Foo
  minor version: 0
  major version: 51 <-- class file Java 7
...

$ javac FooDemo.java
$ java FooDemo
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 9

$ java -XX:-UseSplitVerifier FooDemo
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option UseSplitVerifier; support was removed in 8.0
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 9

note To use always the initial version of Java 6/7/8 was done by intention to show that the behaviour was there from the beginning.

You might find some suggestions to get it running with Java 8 ...

$ java -noverify FooDemo
output: true

$ java -Xverify:none FooDemo
output: true

note This disables the bytecode verifier. Keep in mind to never disable bytecode verification in a production system.

这篇关于java.lang.VerifyError:期望分支目标上的stackmap帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆