线程“ main”中的异常java.lang.VerifyError:操作数堆栈Java 8 121上的类型错误,但是在Java 11上不是 [英] Exception in thread "main" java.lang.VerifyError: Bad type on operand stack Java 8 121 but not on Java 11
问题描述
我知道Java 8 Build 75上已进行了修复。 https:/ /bugs.java.com/bugdatabase/view_bug.do?bug_id=8006684 ,我无法在75之前的版本上重现同样的问题,但是该代码在Java 8-121上引发了异常,但不是在Java 11上,我想知道此问题在哪个版本的Jdk中得到了解决。
一个示例,该代码在75之前的版本中产生了问题,但之后没有出现。
public static void main(String [] args){
xxx();
}
static void xxx(){
Functional1 f =()-> {
Object o = new Object(){};
返回新的A();
};
}
静态类A {}
静态接口Functional1 {A func(); }
但是我的代码在Java 8-121而不是Java 11上抛出了异常。 p>
该代码只是可以表示它的真实代码的一个示例,但仍以单一方式表示。
class Element {
private final String data;
public Element(最终字符串数据){
this.data = data;
}
public String getData(){
返回数据;
}
}
类Html {
受保护的元素doSomething(最终字符串数据){
返回新的元素(数据);
}
}
A类{
受保护的最终HTML html = new Html();
}
B类扩展了A {}
C类扩展了B {}
D类扩展了C {}
E类扩展了D {}
最终公共类JavaBug扩展了E {
最终公共类List< SupplierElementWithMapper> data = Arrays.asList(new SupplierElementWithMapper());
public static void main(String [] args)引发异常{
System.out.println( JavaVersion: + System.getProperty( java.version));;
最终的JavaBug clazz = new JavaBug();
}
私有最终类别SupplierElementWithMapper {
私有最终Supplier< Element>供应商
private final Function< Element,String>映射器
私人UnaryOperator< String> unaryOperator = UnaryOperator.identity();
public SupplierElementWithMapper(最终字符串选择器){
this(()-> html.doSomething(selector),Element :: getData);
}
public SupplierElementElementMapper(final Supplier< Element>供应商,final Function< Element,String>映射器){
this.supplier = provider;
this.mapper =映射器;
}
私有SupplierElementElementWithMapper addUnaryOperator(final UnaryOperator< String> unaryOperator){
this.unaryOperator = unaryOperator;
返回;
}
}
}
控制台
JavaVersion:1.8.0_121
线程 main中的异常java.lang.VerifyError:操作数堆栈上的类型错误
异常详细信息:
位置:
projectname / issues / JavaBug $ SupplierElementWithMapper.lambda $ new $ 1(Ljava / lang / String; Lprojectname / issues / JavaBug;)Lprojectname / issues / Element; @ 1:getfield
原因:
类型'java / lang / String'(当前帧,堆栈[0])不可分配给'projectname / issues / JavaBug $ SupplierElementWithMapper'
当前帧:
bci:@ 1
标志:{}
当地人:{'java / lang / String','projectname / issues / JavaBug'}
堆栈:{'java / lang / String'}
字节码:
0x0000000:2ab4 0005 b400 102a b600 11b0
at projectname.issues.JavaBug。< init>(JavaBug.java:34)
在projectname.issues.JavaBug.main(JavaBug.java:37)
C:\Users\JavIut\AppData\Local\NetBeans\Cache\8.2\executor-snippets \run.xml:53:Java返回:1
问题是供应商中的这一行。
this(()-> html.doSomething(selector),Element :: getData);
正在呼叫受保护的成员,但我尝试失败,没有成功。
this(()-> {return html.doSomething(selector);},Element :: getData);
this(()-> JavaBug.super.html.doSomething(selector),Element :: getData);
this(()-> getHtml()。doSomething(selector),Element :: getData); / *在代码中添加Getter * /
但这可行。
this(()-> JavaBug.this.html.doSomething(selector),Element :: getData);
我不知道该修复程序的版本是什么,我需要通知我的团队。我希望将其放在此处的代码希望对遇到相同问题的人有所帮助。
在intellij提示中,提示源代码与字节码不匹配
与121 https://discuss.newrelic.com/t/verifyerror-bad-type-on-operand-stack/50700
我认为解决方案可能是这样。
https:/ /bugs.java.com/bugdatabase/view_bug.do?bug_id=8178444
完整产品版本:
Java版本 1.8.0_121
Java(TM)SE Runtime Environment(内部版本1.8.0_121-b13)
Java HotSpot(TM)64位服务器VM(内部版本25.121-b13,混合模式)
javac 1.8.0_121
其他操作系统版本信息:
OSX 10.12.4(16E195)
16.5.0 Darwin Kernel Version 16.5.0 :2017年3月3日星期五16:52:33 PST; root:xnu-3789.51.2〜3 / RELEASE_X86_64 x86_64
问题描述:
请参阅下面的代码段。
重新出现问题的步骤:
运行提供的代码。
最诚挚的问候。
您的问题是
JDK-8129740不完整。在外部类是子类并且其[sic]超类的实体在lambda表达式中被引用的情况下,该方法将失败。
该错误已通过修复版本:10关闭,我确实可以使用JDK-9.0.4重现您的问题,但不能使用JDK-10.0.2来重现您的问题。
引用的 JDK-8129740 是链接在您已通过评论反向链接的此问与答。
I know that a fix was made on Java 8 Build 75 https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8006684 and i cannot reproduce the same problem with the code that break on version before 75 But this code is throwing the exception on Java 8-121 but not on Java 11 i want to know in which version of the Jdk was this problem solved please.
A example this code was generating the problem on versions before 75 but not afterwards.
public static void main(String[] args) {
xxx();
}
static void xxx() {
Functional1 f = () -> {
Object o = new Object() { };
return new A();
};
}
static class A { }
static interface Functional1 { A func(); }
But my code is throwing the exception on Java 8-121 but not on Java 11.
The code is just a example of the real code to be able to represent it but still in a single way.
class Element{
private final String data;
public Element(final String data) {
this.data = data;
}
public String getData() {
return data;
}
}
class Html{
protected Element doSomething(final String data){
return new Element(data);
}
}
class A{
protected final Html html = new Html();
}
class B extends A{}
class C extends B{}
class D extends C{}
class E extends D{}
public final class JavaBug extends E{
private final List<SupplierElementWithMapper>data = Arrays.asList(new SupplierElementWithMapper(""));
public static void main(String[] args)throws Exception{
System.out.println("JavaVersion: "+System.getProperty("java.version"));
final JavaBug clazz = new JavaBug();
}
private final class SupplierElementWithMapper{
private final Supplier<Element> supplier;
private final Function<Element,String> mapper;
private UnaryOperator<String> unaryOperator = UnaryOperator.identity();
public SupplierElementWithMapper(final String selector) {
this(()->html.doSomething(selector),Element::getData);
}
public SupplierElementWithMapper(final Supplier<Element> supplier,final Function<Element, String> mapper) {
this.supplier = supplier;
this.mapper = mapper;
}
private SupplierElementWithMapper addUnaryOperator(final UnaryOperator<String>unaryOperator){
this.unaryOperator = unaryOperator;
return this;
}
}
}
The console
JavaVersion: 1.8.0_121
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
projectname/issues/JavaBug$SupplierElementWithMapper.lambda$new$1(Ljava/lang/String;Lprojectname/issues/JavaBug;)Lprojectname/issues/Element; @1: getfield
Reason:
Type 'java/lang/String' (current frame, stack[0]) is not assignable to 'projectname/issues/JavaBug$SupplierElementWithMapper'
Current Frame:
bci: @1
flags: { }
locals: { 'java/lang/String', 'projectname/issues/JavaBug' }
stack: { 'java/lang/String' }
Bytecode:
0x0000000: 2ab4 0005 b400 102a b600 11b0
at projectname.issues.JavaBug.<init>(JavaBug.java:34)
at projectname.issues.JavaBug.main(JavaBug.java:37)
C:\Users\JavIut\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
The problem is this line in the supplier.
this(()->html.doSomething(selector),Element::getData);
Is calling a protected member i have try with no success.
this(()->{return html.doSomething(selector);},Element::getData);
this(()->JavaBug.super.html.doSomething(selector),Element::getData);
this(()->getHtml().doSomething(selector),Element::getData);/*ADDING IN THE CODE THE GETTER*/
But this works.
this(()->JavaBug.this.html.doSomething(selector),Element::getData);
Do have any a idea in which version this fix was made i need to inform into my team. The code i put it here i hope helps somebody with the same problem.
In the intellij idea prompt states that Source code dont match bytecode
Same problem with 121 https://discuss.newrelic.com/t/verifyerror-bad-type-on-operand-stack/50700
I think the solution might be this.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8178444
FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
javac 1.8.0_121
ADDITIONAL OS VERSION INFORMATION :
OSX 10.12.4 (16E195)
16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
See code snippet below.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided code.
Best regards.
Your problem is an instance of JDK-8184989:
The fix for
JDK-8129740is incomplete. It fails on cases when outer class is a subclass and the entities of it's [sic] superclass are referred to in lambda expression.
This bug has been close with "Fix Version/s: 10" and I can indeed reproduce your problem with JDK-9.0.4 but not with JDK-10.0.2.
The referenced JDK-8129740 is the bug report linked in this Q&A you already backlinked via a comment.
这篇关于线程“ main”中的异常java.lang.VerifyError:操作数堆栈Java 8 121上的类型错误,但是在Java 11上不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!