Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why javaassist throws invalid constant type: 18 when loading Entitymanager only when lambdas are used in project

Tags:

java

I read many QnA before posting this specific question. Most of the javaassist invalid constant 18 question were answered to upgrade the javaassist lib. Base on those QnA, I also upgraded lib to latest version in my project and it really worked. But I am not understanding following and need someone's assistance to give some insight please, if you could:

Here is the Environment

Current Version: JDK: build 1.8.0_92-b14

javaassist: 3.14.0.GA

Hibernate: 3.5.1-Final

Build Uses: Ant

Till date project does not have lamda or streams in code. Code Builds and Runs Successfully. No issues so far.

Now, here is what happens when I am using Lambdas and Streams.

Case 1: Without javaassist Upgrade Now, as soon as I introduce any Lamda and Stream in same project, then following Exception throws during Server Start up specially while Spring container is starting up. Weird thing is The class that had Lambda and Stream did get initialized with no issues as per the log showing in IoC container, however one of the existing bean trying to initiate EntityYmanager gets Run Time Exception. based on one of the QnA comment talking about

Case 2: As soon as java assist is upgraded to latest version(or anything above 3.17.0-GA), everything works fine.

Question: Why Exception is not thrown at the class having Lambdas, but the existing hibernate's Entitity Manager which was working fine when project did not have any lambda/stream? Infact Bean that had lambda got loaded successfully and inside container when this Exception is thrown.

Could someone please explain?

Here is the complete Error Trace:

org.springframework.beans.factory.BeanCreationException: Error creating bean     
with name 'ldbEntityManagerFactory' defined in ServletContext resource  
[/WEB-INF/spring/JPA.xml]: Invocation of init method failed; nested     
exception is java.lang.RuntimeException: Error while reading   
    file:/C:/home/tcserver/profiles/instance/webapps/app/WEB-INF/classes
    -------deleted--------------
    ... 25 more
    **Caused by: java.io.IOException: invalid constant type: 18**
    at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090)
    at javassist.bytecode.ConstPool.read(ConstPool.java:1033)
    at javassist.bytecode.ConstPool.<init>(ConstPool.java:149)
    at javassist.bytecode.ClassFile.read(ClassFile.java:764)
    at javassist.bytecode.ClassFile.<init>(ClassFile.java:108)
    atorg.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(Abs
    tractJarVisitor.java:236)
    atorg.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(Ab
    stractJarVisitor.java:202)
    aorg.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisito
    r.java:163)
    aorg.hibernate.ejb.packaging.ExplodedJarVisitor.getClassNamesInTree(Exploded
    JarVisitor.java:101)
    ----DELETED---       
    g.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:614)
    ... 31 more
like image 613
Ram Avatar asked Jan 18 '17 16:01

Ram


1 Answers

It fails to create the EntityManager instance, because a class the manager is loading fails. Then it is not a javassist problem with the manager, but with the class loaded by it. Thus it is entirely possible to have one time no problem creating the manager (without lambdas in the usage) and one time failing (with lambdas). The error message suggests that the old javaassist version does not understand invokedynamic instruction, which means it is a pre Java7 version. Only that in Java7 java itself did not use the instruction, which makes it entirely possible for the problem only appearing with java8 code. And lambdas are making use of invokedynamic.

like image 153
blackdrag Avatar answered Nov 14 '22 23:11

blackdrag