Java Casting: Java 11 throws LambdaConversionException while 1.8 does not The 2019 Stack Overflow Developer Survey Results Are InIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?How does the Java 'for each' loop work?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Does Java support default parameter values?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?

Did 3000BC Egyptians use meteoric iron weapons?

Is bread bad for ducks?

Protecting Dualbooting Windows from dangerous code (like rm -rf)

What is the most effective way of iterating a std::vector and why?

Is "plugging out" electronic devices an American expression?

Is an up-to-date browser secure on an out-of-date OS?

Time travel alters history but people keep saying nothing's changed

How to notate time signature switching consistently every measure

Can one be advised by a professor who is very far away?

Who coined the term "madman theory"?

Right tool to dig six foot holes?

Deal with toxic manager when you can't quit

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?

How to type this arrow in math mode?

Button changing it's text & action. Good or terrible?

Multiply Two Integer Polynomials

What did it mean to "align" a radio?

How are circuits which use complex ICs normally simulated?

What does ひと匙 mean in this manga and has it been used colloquially?

Falsification in Math vs Science

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Reference request: Oldest number theory books with (unsolved) exercises?

Have you ever entered Singapore using a different passport or name?

Geography at the pixel level



Java Casting: Java 11 throws LambdaConversionException while 1.8 does not



The 2019 Stack Overflow Developer Survey Results Are InIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?How does the Java 'for each' loop work?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?Does Java support default parameter values?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








52















the following code works perfectly fine in a Java 1.8 VM but produces a LambdaConversionException when executed in a Java 11 VM. Wheres the difference and why does it behave like this?




Code:



public void addSomeListener(Component comp)
if(comp instanceof HasValue)
((HasValue<?,?>) comp).addValueChangeListener(evt ->
//do sth with evt
);




HasValue Javadoc



Exception (V11 only):



Caused by: java.lang.invoke.LambdaConversionException: Type mismatch
for instantiated parameter 0: class java.lang.Object is not a subtype
of interface com.vaadin.flow.component.HasValue$ValueChangeEvent
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:503)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
... 73 more



Workaround:



ValueChangeListener<ValueChangeEvent<?>> listener = evt -> 
// do sth with evt
;
((HasValue<?,?>) comp).addValueChangeListener(listener);



System:

OS: Windows 10

IDE: Eclipse 2018-12 (4.10.0)

Java (Compile): JDK 1.8.0_201

Java (Webserver): JDK 11.0.2

Webserver: Wildfly 15










share|improve this question



















  • 2





    Interesting and yet poor thing there (HasValue<?,?>) comp ... Such validation though agreed didn't exist in the JDK-8 code.

    – Naman
    Apr 5 at 9:24












  • When exactly do you get this exception? When you add the listener or when the listener is invoked with an event? If the latter, how do you invoke it with an event (show the code place)

    – Erwin Bolwidt
    Apr 5 at 9:40






  • 8





    That’s an important information, as Eclipse has its own compiler, so problems caused by the compiler (and this looks much like a compiler problem) do not have to apply to javac then.

    – Holger
    Apr 5 at 10:51






  • 2





    @JornVernee changing the language level sometimes causes behavioral changes in the compiler.

    – Holger
    Apr 5 at 11:40






  • 1





    @CommonMan IJ neither has its own compiler nor is it a Java VM, so it makes no difference in this case whether you write your code with IJ or a text editor.

    – howlger
    Apr 5 at 11:51

















52















the following code works perfectly fine in a Java 1.8 VM but produces a LambdaConversionException when executed in a Java 11 VM. Wheres the difference and why does it behave like this?




Code:



public void addSomeListener(Component comp)
if(comp instanceof HasValue)
((HasValue<?,?>) comp).addValueChangeListener(evt ->
//do sth with evt
);




HasValue Javadoc



Exception (V11 only):



Caused by: java.lang.invoke.LambdaConversionException: Type mismatch
for instantiated parameter 0: class java.lang.Object is not a subtype
of interface com.vaadin.flow.component.HasValue$ValueChangeEvent
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:503)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
... 73 more



Workaround:



ValueChangeListener<ValueChangeEvent<?>> listener = evt -> 
// do sth with evt
;
((HasValue<?,?>) comp).addValueChangeListener(listener);



System:

OS: Windows 10

IDE: Eclipse 2018-12 (4.10.0)

Java (Compile): JDK 1.8.0_201

Java (Webserver): JDK 11.0.2

Webserver: Wildfly 15










share|improve this question



















  • 2





    Interesting and yet poor thing there (HasValue<?,?>) comp ... Such validation though agreed didn't exist in the JDK-8 code.

    – Naman
    Apr 5 at 9:24












  • When exactly do you get this exception? When you add the listener or when the listener is invoked with an event? If the latter, how do you invoke it with an event (show the code place)

    – Erwin Bolwidt
    Apr 5 at 9:40






  • 8





    That’s an important information, as Eclipse has its own compiler, so problems caused by the compiler (and this looks much like a compiler problem) do not have to apply to javac then.

    – Holger
    Apr 5 at 10:51






  • 2





    @JornVernee changing the language level sometimes causes behavioral changes in the compiler.

    – Holger
    Apr 5 at 11:40






  • 1





    @CommonMan IJ neither has its own compiler nor is it a Java VM, so it makes no difference in this case whether you write your code with IJ or a text editor.

    – howlger
    Apr 5 at 11:51













52












52








52


10






the following code works perfectly fine in a Java 1.8 VM but produces a LambdaConversionException when executed in a Java 11 VM. Wheres the difference and why does it behave like this?




Code:



public void addSomeListener(Component comp)
if(comp instanceof HasValue)
((HasValue<?,?>) comp).addValueChangeListener(evt ->
//do sth with evt
);




HasValue Javadoc



Exception (V11 only):



Caused by: java.lang.invoke.LambdaConversionException: Type mismatch
for instantiated parameter 0: class java.lang.Object is not a subtype
of interface com.vaadin.flow.component.HasValue$ValueChangeEvent
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:503)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
... 73 more



Workaround:



ValueChangeListener<ValueChangeEvent<?>> listener = evt -> 
// do sth with evt
;
((HasValue<?,?>) comp).addValueChangeListener(listener);



System:

OS: Windows 10

IDE: Eclipse 2018-12 (4.10.0)

Java (Compile): JDK 1.8.0_201

Java (Webserver): JDK 11.0.2

Webserver: Wildfly 15










share|improve this question
















the following code works perfectly fine in a Java 1.8 VM but produces a LambdaConversionException when executed in a Java 11 VM. Wheres the difference and why does it behave like this?




Code:



public void addSomeListener(Component comp)
if(comp instanceof HasValue)
((HasValue<?,?>) comp).addValueChangeListener(evt ->
//do sth with evt
);




HasValue Javadoc



Exception (V11 only):



Caused by: java.lang.invoke.LambdaConversionException: Type mismatch
for instantiated parameter 0: class java.lang.Object is not a subtype
of interface com.vaadin.flow.component.HasValue$ValueChangeEvent
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:503)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
... 73 more



Workaround:



ValueChangeListener<ValueChangeEvent<?>> listener = evt -> 
// do sth with evt
;
((HasValue<?,?>) comp).addValueChangeListener(listener);



System:

OS: Windows 10

IDE: Eclipse 2018-12 (4.10.0)

Java (Compile): JDK 1.8.0_201

Java (Webserver): JDK 11.0.2

Webserver: Wildfly 15







java eclipse java-8 java-11 vaadin-flow






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 5 at 13:58







Gerrit Sedlaczek

















asked Apr 5 at 9:17









Gerrit SedlaczekGerrit Sedlaczek

5621617




5621617







  • 2





    Interesting and yet poor thing there (HasValue<?,?>) comp ... Such validation though agreed didn't exist in the JDK-8 code.

    – Naman
    Apr 5 at 9:24












  • When exactly do you get this exception? When you add the listener or when the listener is invoked with an event? If the latter, how do you invoke it with an event (show the code place)

    – Erwin Bolwidt
    Apr 5 at 9:40






  • 8





    That’s an important information, as Eclipse has its own compiler, so problems caused by the compiler (and this looks much like a compiler problem) do not have to apply to javac then.

    – Holger
    Apr 5 at 10:51






  • 2





    @JornVernee changing the language level sometimes causes behavioral changes in the compiler.

    – Holger
    Apr 5 at 11:40






  • 1





    @CommonMan IJ neither has its own compiler nor is it a Java VM, so it makes no difference in this case whether you write your code with IJ or a text editor.

    – howlger
    Apr 5 at 11:51












  • 2





    Interesting and yet poor thing there (HasValue<?,?>) comp ... Such validation though agreed didn't exist in the JDK-8 code.

    – Naman
    Apr 5 at 9:24












  • When exactly do you get this exception? When you add the listener or when the listener is invoked with an event? If the latter, how do you invoke it with an event (show the code place)

    – Erwin Bolwidt
    Apr 5 at 9:40






  • 8





    That’s an important information, as Eclipse has its own compiler, so problems caused by the compiler (and this looks much like a compiler problem) do not have to apply to javac then.

    – Holger
    Apr 5 at 10:51






  • 2





    @JornVernee changing the language level sometimes causes behavioral changes in the compiler.

    – Holger
    Apr 5 at 11:40






  • 1





    @CommonMan IJ neither has its own compiler nor is it a Java VM, so it makes no difference in this case whether you write your code with IJ or a text editor.

    – howlger
    Apr 5 at 11:51







2




2





Interesting and yet poor thing there (HasValue<?,?>) comp ... Such validation though agreed didn't exist in the JDK-8 code.

– Naman
Apr 5 at 9:24






Interesting and yet poor thing there (HasValue<?,?>) comp ... Such validation though agreed didn't exist in the JDK-8 code.

– Naman
Apr 5 at 9:24














When exactly do you get this exception? When you add the listener or when the listener is invoked with an event? If the latter, how do you invoke it with an event (show the code place)

– Erwin Bolwidt
Apr 5 at 9:40





When exactly do you get this exception? When you add the listener or when the listener is invoked with an event? If the latter, how do you invoke it with an event (show the code place)

– Erwin Bolwidt
Apr 5 at 9:40




8




8





That’s an important information, as Eclipse has its own compiler, so problems caused by the compiler (and this looks much like a compiler problem) do not have to apply to javac then.

– Holger
Apr 5 at 10:51





That’s an important information, as Eclipse has its own compiler, so problems caused by the compiler (and this looks much like a compiler problem) do not have to apply to javac then.

– Holger
Apr 5 at 10:51




2




2





@JornVernee changing the language level sometimes causes behavioral changes in the compiler.

– Holger
Apr 5 at 11:40





@JornVernee changing the language level sometimes causes behavioral changes in the compiler.

– Holger
Apr 5 at 11:40




1




1





@CommonMan IJ neither has its own compiler nor is it a Java VM, so it makes no difference in this case whether you write your code with IJ or a text editor.

– howlger
Apr 5 at 11:51





@CommonMan IJ neither has its own compiler nor is it a Java VM, so it makes no difference in this case whether you write your code with IJ or a text editor.

– howlger
Apr 5 at 11:51












1 Answer
1






active

oldest

votes


















46














TL;DR The Eclipse compiler generates a method signature for the lambda instance that is invalid according to the specification. Due to additional type checking code added in JDK 9 to better enforce the specification, the incorrect signature is now causing an exception when running on Java 11.




Verified with Eclipse 2019-03 as well with this code:



public class Main 
public static void main(String[] args)
getHasValue().addValueChangeListener(evt -> );


public static HasValue<?, ?> getHasValue()
return null;



interface HasValue<E extends HasValue.ValueChangeEvent<V>,V>
public static interface ValueChangeEvent<V>
public static interface ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
void valueChanged(E event);

void addValueChangeListener(HasValue.ValueChangeListener<? super E> listener);



Even when using null as the receiver, the code fails when bootstrapping with the same error.



Using javap -v Main we can see where the problem lies. I'm seeing this in the BoostrapMethods table:



BootstrapMethods:
0: #48 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#50 (Lmain/HasValue$ValueChangeEvent;)V
#53 REF_invokeStatic main/Main.lambda$0:(Ljava/lang/Object;)V
#54 (Ljava/lang/Object;)V


Note that the last argument (constant #54) is (Ljava/lang/Object;)V, while javac generates (Lmain/HasValue$ValueChangeEvent;)V. i.e. the method signature that Eclipse wants to use for the lambda is different from what javac wants to use.



If the wanted method signature is the erasure of the target method (which seems to be the case), then the correct method signature is indeed (Lmain/HasValue$ValueChangeEvent;)V since that is the erasure of the target method, which is:



void valueChanged(E event);


Where E is E extends HasValue.ValueChangeEvent<?>, so that would be erased to HasValue.ValueChangeEvent.



The problem seems to be with ECJ, and seems to have been brought to the surface by JDK-8173587 (revision) (Unfortunately this seems to be a private ticket.) which adds extra type checks to verify that the SAM method type is actually compatible with the instantiate method type. According to the documentation of LambdaMetafactory::metafactory the instantiated method type must be the same, or a specialization of the SAM method type:




instantiatedMethodType - The signature and return type that should be enforced dynamically at invocation time. This may be the same as samMethodType, or may be a specialization of it.




which the method type generated by ECJ is evidently not, so this ends up throwing an exception. (though, to be fair, I don't see defined anywhere what constitutes a "specialization" in this case). I've reported this on the Eclipse bugzilla here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=546161



I'm guessing this change was made somewhere in JDK 9, since source code was already modular at that point, and the date of the revision is fairly early (February 2017).



Since javac generates the correct method signature, you could switch to that for the time being as a workaround.






share|improve this answer




















  • 7





    I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

    – Jorn Vernee
    Apr 5 at 12:18






  • 1





    this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

    – Eugene
    Apr 5 at 13:16











  • Could you please add a link to the corresponding Eclipse bug?

    – howlger
    Apr 5 at 13:16











  • @JornVernee Not at all. I think you explain bytecode related answers very well.

    – Michael Berry
    Apr 5 at 14:00






  • 2





    @howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

    – Jorn Vernee
    Apr 5 at 15:34











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55532055%2fjava-casting-java-11-throws-lambdaconversionexception-while-1-8-does-not%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









46














TL;DR The Eclipse compiler generates a method signature for the lambda instance that is invalid according to the specification. Due to additional type checking code added in JDK 9 to better enforce the specification, the incorrect signature is now causing an exception when running on Java 11.




Verified with Eclipse 2019-03 as well with this code:



public class Main 
public static void main(String[] args)
getHasValue().addValueChangeListener(evt -> );


public static HasValue<?, ?> getHasValue()
return null;



interface HasValue<E extends HasValue.ValueChangeEvent<V>,V>
public static interface ValueChangeEvent<V>
public static interface ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
void valueChanged(E event);

void addValueChangeListener(HasValue.ValueChangeListener<? super E> listener);



Even when using null as the receiver, the code fails when bootstrapping with the same error.



Using javap -v Main we can see where the problem lies. I'm seeing this in the BoostrapMethods table:



BootstrapMethods:
0: #48 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#50 (Lmain/HasValue$ValueChangeEvent;)V
#53 REF_invokeStatic main/Main.lambda$0:(Ljava/lang/Object;)V
#54 (Ljava/lang/Object;)V


Note that the last argument (constant #54) is (Ljava/lang/Object;)V, while javac generates (Lmain/HasValue$ValueChangeEvent;)V. i.e. the method signature that Eclipse wants to use for the lambda is different from what javac wants to use.



If the wanted method signature is the erasure of the target method (which seems to be the case), then the correct method signature is indeed (Lmain/HasValue$ValueChangeEvent;)V since that is the erasure of the target method, which is:



void valueChanged(E event);


Where E is E extends HasValue.ValueChangeEvent<?>, so that would be erased to HasValue.ValueChangeEvent.



The problem seems to be with ECJ, and seems to have been brought to the surface by JDK-8173587 (revision) (Unfortunately this seems to be a private ticket.) which adds extra type checks to verify that the SAM method type is actually compatible with the instantiate method type. According to the documentation of LambdaMetafactory::metafactory the instantiated method type must be the same, or a specialization of the SAM method type:




instantiatedMethodType - The signature and return type that should be enforced dynamically at invocation time. This may be the same as samMethodType, or may be a specialization of it.




which the method type generated by ECJ is evidently not, so this ends up throwing an exception. (though, to be fair, I don't see defined anywhere what constitutes a "specialization" in this case). I've reported this on the Eclipse bugzilla here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=546161



I'm guessing this change was made somewhere in JDK 9, since source code was already modular at that point, and the date of the revision is fairly early (February 2017).



Since javac generates the correct method signature, you could switch to that for the time being as a workaround.






share|improve this answer




















  • 7





    I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

    – Jorn Vernee
    Apr 5 at 12:18






  • 1





    this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

    – Eugene
    Apr 5 at 13:16











  • Could you please add a link to the corresponding Eclipse bug?

    – howlger
    Apr 5 at 13:16











  • @JornVernee Not at all. I think you explain bytecode related answers very well.

    – Michael Berry
    Apr 5 at 14:00






  • 2





    @howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

    – Jorn Vernee
    Apr 5 at 15:34















46














TL;DR The Eclipse compiler generates a method signature for the lambda instance that is invalid according to the specification. Due to additional type checking code added in JDK 9 to better enforce the specification, the incorrect signature is now causing an exception when running on Java 11.




Verified with Eclipse 2019-03 as well with this code:



public class Main 
public static void main(String[] args)
getHasValue().addValueChangeListener(evt -> );


public static HasValue<?, ?> getHasValue()
return null;



interface HasValue<E extends HasValue.ValueChangeEvent<V>,V>
public static interface ValueChangeEvent<V>
public static interface ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
void valueChanged(E event);

void addValueChangeListener(HasValue.ValueChangeListener<? super E> listener);



Even when using null as the receiver, the code fails when bootstrapping with the same error.



Using javap -v Main we can see where the problem lies. I'm seeing this in the BoostrapMethods table:



BootstrapMethods:
0: #48 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#50 (Lmain/HasValue$ValueChangeEvent;)V
#53 REF_invokeStatic main/Main.lambda$0:(Ljava/lang/Object;)V
#54 (Ljava/lang/Object;)V


Note that the last argument (constant #54) is (Ljava/lang/Object;)V, while javac generates (Lmain/HasValue$ValueChangeEvent;)V. i.e. the method signature that Eclipse wants to use for the lambda is different from what javac wants to use.



If the wanted method signature is the erasure of the target method (which seems to be the case), then the correct method signature is indeed (Lmain/HasValue$ValueChangeEvent;)V since that is the erasure of the target method, which is:



void valueChanged(E event);


Where E is E extends HasValue.ValueChangeEvent<?>, so that would be erased to HasValue.ValueChangeEvent.



The problem seems to be with ECJ, and seems to have been brought to the surface by JDK-8173587 (revision) (Unfortunately this seems to be a private ticket.) which adds extra type checks to verify that the SAM method type is actually compatible with the instantiate method type. According to the documentation of LambdaMetafactory::metafactory the instantiated method type must be the same, or a specialization of the SAM method type:




instantiatedMethodType - The signature and return type that should be enforced dynamically at invocation time. This may be the same as samMethodType, or may be a specialization of it.




which the method type generated by ECJ is evidently not, so this ends up throwing an exception. (though, to be fair, I don't see defined anywhere what constitutes a "specialization" in this case). I've reported this on the Eclipse bugzilla here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=546161



I'm guessing this change was made somewhere in JDK 9, since source code was already modular at that point, and the date of the revision is fairly early (February 2017).



Since javac generates the correct method signature, you could switch to that for the time being as a workaround.






share|improve this answer




















  • 7





    I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

    – Jorn Vernee
    Apr 5 at 12:18






  • 1





    this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

    – Eugene
    Apr 5 at 13:16











  • Could you please add a link to the corresponding Eclipse bug?

    – howlger
    Apr 5 at 13:16











  • @JornVernee Not at all. I think you explain bytecode related answers very well.

    – Michael Berry
    Apr 5 at 14:00






  • 2





    @howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

    – Jorn Vernee
    Apr 5 at 15:34













46












46








46







TL;DR The Eclipse compiler generates a method signature for the lambda instance that is invalid according to the specification. Due to additional type checking code added in JDK 9 to better enforce the specification, the incorrect signature is now causing an exception when running on Java 11.




Verified with Eclipse 2019-03 as well with this code:



public class Main 
public static void main(String[] args)
getHasValue().addValueChangeListener(evt -> );


public static HasValue<?, ?> getHasValue()
return null;



interface HasValue<E extends HasValue.ValueChangeEvent<V>,V>
public static interface ValueChangeEvent<V>
public static interface ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
void valueChanged(E event);

void addValueChangeListener(HasValue.ValueChangeListener<? super E> listener);



Even when using null as the receiver, the code fails when bootstrapping with the same error.



Using javap -v Main we can see where the problem lies. I'm seeing this in the BoostrapMethods table:



BootstrapMethods:
0: #48 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#50 (Lmain/HasValue$ValueChangeEvent;)V
#53 REF_invokeStatic main/Main.lambda$0:(Ljava/lang/Object;)V
#54 (Ljava/lang/Object;)V


Note that the last argument (constant #54) is (Ljava/lang/Object;)V, while javac generates (Lmain/HasValue$ValueChangeEvent;)V. i.e. the method signature that Eclipse wants to use for the lambda is different from what javac wants to use.



If the wanted method signature is the erasure of the target method (which seems to be the case), then the correct method signature is indeed (Lmain/HasValue$ValueChangeEvent;)V since that is the erasure of the target method, which is:



void valueChanged(E event);


Where E is E extends HasValue.ValueChangeEvent<?>, so that would be erased to HasValue.ValueChangeEvent.



The problem seems to be with ECJ, and seems to have been brought to the surface by JDK-8173587 (revision) (Unfortunately this seems to be a private ticket.) which adds extra type checks to verify that the SAM method type is actually compatible with the instantiate method type. According to the documentation of LambdaMetafactory::metafactory the instantiated method type must be the same, or a specialization of the SAM method type:




instantiatedMethodType - The signature and return type that should be enforced dynamically at invocation time. This may be the same as samMethodType, or may be a specialization of it.




which the method type generated by ECJ is evidently not, so this ends up throwing an exception. (though, to be fair, I don't see defined anywhere what constitutes a "specialization" in this case). I've reported this on the Eclipse bugzilla here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=546161



I'm guessing this change was made somewhere in JDK 9, since source code was already modular at that point, and the date of the revision is fairly early (February 2017).



Since javac generates the correct method signature, you could switch to that for the time being as a workaround.






share|improve this answer















TL;DR The Eclipse compiler generates a method signature for the lambda instance that is invalid according to the specification. Due to additional type checking code added in JDK 9 to better enforce the specification, the incorrect signature is now causing an exception when running on Java 11.




Verified with Eclipse 2019-03 as well with this code:



public class Main 
public static void main(String[] args)
getHasValue().addValueChangeListener(evt -> );


public static HasValue<?, ?> getHasValue()
return null;



interface HasValue<E extends HasValue.ValueChangeEvent<V>,V>
public static interface ValueChangeEvent<V>
public static interface ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
void valueChanged(E event);

void addValueChangeListener(HasValue.ValueChangeListener<? super E> listener);



Even when using null as the receiver, the code fails when bootstrapping with the same error.



Using javap -v Main we can see where the problem lies. I'm seeing this in the BoostrapMethods table:



BootstrapMethods:
0: #48 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#50 (Lmain/HasValue$ValueChangeEvent;)V
#53 REF_invokeStatic main/Main.lambda$0:(Ljava/lang/Object;)V
#54 (Ljava/lang/Object;)V


Note that the last argument (constant #54) is (Ljava/lang/Object;)V, while javac generates (Lmain/HasValue$ValueChangeEvent;)V. i.e. the method signature that Eclipse wants to use for the lambda is different from what javac wants to use.



If the wanted method signature is the erasure of the target method (which seems to be the case), then the correct method signature is indeed (Lmain/HasValue$ValueChangeEvent;)V since that is the erasure of the target method, which is:



void valueChanged(E event);


Where E is E extends HasValue.ValueChangeEvent<?>, so that would be erased to HasValue.ValueChangeEvent.



The problem seems to be with ECJ, and seems to have been brought to the surface by JDK-8173587 (revision) (Unfortunately this seems to be a private ticket.) which adds extra type checks to verify that the SAM method type is actually compatible with the instantiate method type. According to the documentation of LambdaMetafactory::metafactory the instantiated method type must be the same, or a specialization of the SAM method type:




instantiatedMethodType - The signature and return type that should be enforced dynamically at invocation time. This may be the same as samMethodType, or may be a specialization of it.




which the method type generated by ECJ is evidently not, so this ends up throwing an exception. (though, to be fair, I don't see defined anywhere what constitutes a "specialization" in this case). I've reported this on the Eclipse bugzilla here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=546161



I'm guessing this change was made somewhere in JDK 9, since source code was already modular at that point, and the date of the revision is fairly early (February 2017).



Since javac generates the correct method signature, you could switch to that for the time being as a workaround.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 5 at 15:33

























answered Apr 5 at 12:01









Jorn VerneeJorn Vernee

21.4k34366




21.4k34366







  • 7





    I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

    – Jorn Vernee
    Apr 5 at 12:18






  • 1





    this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

    – Eugene
    Apr 5 at 13:16











  • Could you please add a link to the corresponding Eclipse bug?

    – howlger
    Apr 5 at 13:16











  • @JornVernee Not at all. I think you explain bytecode related answers very well.

    – Michael Berry
    Apr 5 at 14:00






  • 2





    @howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

    – Jorn Vernee
    Apr 5 at 15:34












  • 7





    I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

    – Jorn Vernee
    Apr 5 at 12:18






  • 1





    this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

    – Eugene
    Apr 5 at 13:16











  • Could you please add a link to the corresponding Eclipse bug?

    – howlger
    Apr 5 at 13:16











  • @JornVernee Not at all. I think you explain bytecode related answers very well.

    – Michael Berry
    Apr 5 at 14:00






  • 2





    @howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

    – Jorn Vernee
    Apr 5 at 15:34







7




7





I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

– Jorn Vernee
Apr 5 at 12:18





I tend to over-complicate these bytecode related answers (being someone who's used to looking at bytecode). It's hard to find the right balance between sufficient explanation, and keeping the answer succinct. If anything is unclear, please feel free to ask for clarification.

– Jorn Vernee
Apr 5 at 12:18




1




1





this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

– Eugene
Apr 5 at 13:16





this is not over-complicate and it's an easy to read and understand answer, there simply isn't a better one. I had a pleasure reading it, thank you for taking the time

– Eugene
Apr 5 at 13:16













Could you please add a link to the corresponding Eclipse bug?

– howlger
Apr 5 at 13:16





Could you please add a link to the corresponding Eclipse bug?

– howlger
Apr 5 at 13:16













@JornVernee Not at all. I think you explain bytecode related answers very well.

– Michael Berry
Apr 5 at 14:00





@JornVernee Not at all. I think you explain bytecode related answers very well.

– Michael Berry
Apr 5 at 14:00




2




2





@howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

– Jorn Vernee
Apr 5 at 15:34





@howlger Done: bugs.eclipse.org/bugs/show_bug.cgi?id=546161

– Jorn Vernee
Apr 5 at 15:34



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55532055%2fjava-casting-java-11-throws-lambdaconversionexception-while-1-8-does-not%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

Romeo and Juliet ContentsCharactersSynopsisSourcesDate and textThemes and motifsCriticism and interpretationLegacyScene by sceneSee alsoNotes and referencesSourcesExternal linksNavigation menu"Consumer Price Index (estimate) 1800–"10.2307/28710160037-3222287101610.1093/res/II.5.31910.2307/45967845967810.2307/2869925286992510.1525/jams.1982.35.3.03a00050"Dada Masilo: South African dancer who breaks the rules"10.1093/res/os-XV.57.1610.2307/28680942868094"Sweet Sorrow: Mann-Korman's Romeo and Juliet Closes Sept. 5 at MN's Ordway"the original10.2307/45957745957710.1017/CCOL0521570476.009"Ram Leela box office collections hit massive Rs 100 crore, pulverises prediction"Archived"Broadway Revival of Romeo and Juliet, Starring Orlando Bloom and Condola Rashad, Will Close Dec. 8"Archived10.1075/jhp.7.1.04hon"Wherefore art thou, Romeo? To make us laugh at Navy Pier"the original10.1093/gmo/9781561592630.article.O006772"Ram-leela Review Roundup: Critics Hail Film as Best Adaptation of Romeo and Juliet"Archived10.2307/31946310047-77293194631"Romeo and Juliet get Twitter treatment""Juliet's Nurse by Lois Leveen""Romeo and Juliet: Orlando Bloom's Broadway Debut Released in Theaters for Valentine's Day"Archived"Romeo and Juliet Has No Balcony"10.1093/gmo/9781561592630.article.O00778110.2307/2867423286742310.1076/enst.82.2.115.959510.1080/00138380601042675"A plague o' both your houses: error in GCSE exam paper forces apology""Juliet of the Five O'Clock Shadow, and Other Wonders"10.2307/33912430027-4321339124310.2307/28487440038-7134284874410.2307/29123140149-661129123144728341M"Weekender Guide: Shakespeare on The Drive""balcony"UK public library membership"romeo"UK public library membership10.1017/CCOL9780521844291"Post-Zionist Critique on Israel and the Palestinians Part III: Popular Culture"10.2307/25379071533-86140377-919X2537907"Capulets and Montagues: UK exam board admit mixing names up in Romeo and Juliet paper"Istoria Novellamente Ritrovata di Due Nobili Amanti2027/mdp.390150822329610820-750X"GCSE exam error: Board accidentally rewrites Shakespeare"10.2307/29176390149-66112917639"Exam board apologises after error in English GCSE paper which confused characters in Shakespeare's Romeo and Juliet""From Mariotto and Ganozza to Romeo and Guilietta: Metamorphoses of a Renaissance Tale"10.2307/37323537323510.2307/2867455286745510.2307/28678912867891"10 Questions for Taylor Swift"10.2307/28680922868092"Haymarket Theatre""The Zeffirelli Way: Revealing Talk by Florentine Director""Michael Smuin: 1938-2007 / Prolific dance director had showy career"The Life and Art of Edwin BoothRomeo and JulietRomeo and JulietRomeo and JulietRomeo and JulietEasy Read Romeo and JulietRomeo and Julieteeecb12003684p(data)4099369-3n8211610759dbe00d-a9e2-41a3-b2c1-977dd692899302814385X313670221313670221