Friday 30 July 2021

AWS Lambda with Java giving error: java.lang.UnsupportedClassVersionError: com/test/functions/HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

 In this short post I am going to explain about a silly mistake I made because of which I got below error:


com/test/functions/HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0: java.lang.UnsupportedClassVersionError
java.lang.UnsupportedClassVersionError: com/test/functions/HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)

 

What I was doing ? 

I was running AWS Lambda functions on Java 8 runtime from long time. Recently I got below email from Amazon:

[Action Required] AWS Lambda is migrating the Java 8 runtime to the Amazon Corretto 8 JVM

As per the email description there was no action required from my side. As after a given date AWS promised to update your lambda runtime from OpenJDK to Amazon Corretto. 

What went wrong ?

I consider this change as a good opportunity and timing to upgrade to Java 11 on Amazon Corretto instead of staying on Java 8 runtime. I have downloaded Amazon Corretto JDK, compiled my lambda jar and uploaded the new jar file in the function code.

My Laziness !
 
After uploading that I haven't tested my function and assumed things are good. Then after sometime I was expecting some alerts and events from my code but haven't received so I went to cloudwatch and checked the logs and found above error.

Crucial step

The error message was clear. I was trying to run Java 11 compiled code on Java 8 runtime !!!

Yeah you got it right. I forgot to change below configuration to Java 11 in AWS Lambda configuration. After setting to Java 11 my function started working fine.


Learning

Be careful and QA before releasing to production !

Don't be overconfident with code, technology and your past experience. All of them have tendency to go wrong when you don't think so !


Wiedersehen
seh dich später

No comments:

Post a Comment