Issue
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. In which version of the JDK was this problem solved?
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);
How can I find in which version this fix was made? I need to inform into my team.
In the IntelliJ idea prompt states that Source code don't 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.
Solution
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.
Answered By - Holger
Answer Checked By - Cary Denson (JavaFixing Admin)