Class Has Been Compiled by a More Recent Version of the Java Environment

Class has been compiled by a more recent version of the Java Environment

This is just a version mismatch. You have compiled your code using java version 9 and your current JRE is version 8. Try upgrading your JRE to 9.

49 = Java 5
50 = Java 6
51 = Java 7
52 = Java 8
53 = Java 9
54 = Java 10
55 = Java 11
56 = Java 12
57 = Java 13
58 = Java 14
59 = Java 15
60 = Java 16
61 = Java 17
62 = Java 18
63 = Java 19

org/testng/ITestListener has been compiled by a more recent version of the Java Runtime (class file version 55.0), only recognizes version up to 52

As noted in the comments, the TestNG website says:

Requirements

TestNG Upto v7.5: JDK 8 or higher.

TestNG v7.6.0 and above: JDK 11 or higher.

So the possible solutions are:

  1. Use an older version of TestNG than v7.6.0 if you want to use Java 8 as your development platform. The TestNG version will probably be in your project's POM file.

  2. Upgrade your development platform to Java 11 or later.

  3. If you are feeling brave1, attempt to backport the version of TestNG (>= v7.6.0) that you are using to run on Java 8 (or older).


1 - This could be trivial or complicated. You won't know until you try it.

CamelContextAware has been compiled by a more recent version of the Java Runtime

The problem was here

    <dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<version>3.15.0</version>
<scope>test</scope>
</dependency>

Setting version at 3.12.0 solved for me.

Spring Boot Application has been compiled by more recent version of Java runtime

Update: I solved the issue by removing the javapath path variable and restarting.

I believe it was the following I removed:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

JNI error : A class has been compiled by a more recent version of the Java Runtime

So, the problem is that you're compiling with javac from JDK 11, and then trying to run with Java 8. Since the java.exe from %JAVA_HOME%\bin is being picked up before C:\Program Files\Java\jdk-11.0.2\bin. And, I'm guessing it can't find javac because you added C:\Program Files\Java\jdk-11.0.2\bin to the path, without restarting your shell, which means the path is not reloaded.

To resolve this you should remove the C:\Program Files\Java\jdk-11.0.2\bin entry from the path, and then update the JAVA_HOME environment variable to point to C:\Program Files\Java\jdk-11.0.2 instead. Then restart your shell and it should pick up C:\Program Files\Java\jdk-11.0.2\bin expanded from %JAVA_HOME%\bin.

Class compiled by a more recent version of the Java Runtime (0.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Your statement

return new ClassWriter(classReader,
ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES).toByteArray();

create a new ClassWriter but doesn’t write anything to it before requesting the generated bytecode.

You have to populate it with the class information. In your specific case:

ClassWriter cw = new ClassWriter(classReader,
ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(cw);
return cw.toByteArray();

Like classReader.accept(classNode, ClassReader.EXPAND_FRAMES); copied all information from the class reader to the classNode, the classNode.accept(cw); will copy the modified information from the classNode to the class writer.

To answer the question literally, a call to
visit​(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces) will specify the main information of the class, including the version number, however, the method will be invoked automatically when using the Visitor Pattern.



Related Topics



Leave a reply



Submit