ApprovalTests.Java icon indicating copy to clipboard operation
ApprovalTests.Java copied to clipboard

`NoSuchMethod` when running ApprovalTests on Java 8

Open rohanKanojia opened this issue 1 year ago • 6 comments

Hello, we use ApprovalTests in Fabric8 Kubernetes Client

We wanted to merge pull request by dependabot for bumping approval tests to v24.4.0 https://github.com/fabric8io/kubernetes-client/pull/6255

However, we noticed that Approval tests are no longer running on JDK8 properly, currently we're seeing this error:

logs from GitHub Action

Error:    CRDGeneratorApprovalTest.apiV1ApprovalTest:92 » NoClassDefFound Could not initialize class org.approvaltests.reporters.DefaultFrontLoadedReporter
org.approvaltests.reporters.DefaultFrontLoadedReporter
Error:    CRDGeneratorApprovalTest.apiV2ApprovalTest:118 » NoSuchMethod java.util.Map.entry(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/Map$Entry;

Javadoc for Map.entry(Object, Object) says it's introduced since Java 9. However, I'm not able to find any references to this method in your codebase.

Same test completes successfully on JDK11 and JDK17.

I wanted to check if this change was intentional in a minor release. Is support for Java8 dropped from ApprovalTests?

rohanKanojia avatar Aug 26 '24 13:08 rohanKanojia

I'll have a look. We still want to be compatible with jdk8, even though right now our pipelines don't use it. The eclipse code formatter maven plugin is the reason for this, as their latest versions requrie at least jdk 11 and from what it looks like, soon 21 https://code.revelc.net/formatter-maven-plugin/eclipse-versions.html

LarsEckart avatar Aug 26 '24 14:08 LarsEckart

Another finding. We bumped jakarta-servlet-api and that also has:

Minimum Java SE Version Java SE 17 or higher

@isidore this is used in approvaltests-util in ServletContextLoader.

LarsEckart avatar Aug 26 '24 14:08 LarsEckart

Found another one:

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

if we have such dependencies (even when marked optional I think), we cannot compile with jdk 8 (and find such issues)

LarsEckart avatar Aug 26 '24 14:08 LarsEckart

When I rip out all those dependencies, I can compile our project with jdk8, only aprovaltests-tests doesnt work because well, there we really started using later APIs and thos bumped the dependency on this project.

[INFO] ApprovalTests.Java ................................. SUCCESS [  0.159 s]
[INFO] approvaltests-util ................................. SUCCESS [  3.117 s]
[INFO] approvaltests ...................................... SUCCESS [  1.159 s]
[INFO] approvaltests-util-tests ........................... SUCCESS [  0.117 s]
[INFO] approvaltests-tests ................................ FAILURE [  0.219 s]

LarsEckart avatar Aug 26 '24 14:08 LarsEckart

@LarsEckart : Thanks for your swift response. Is it okay to say that ApprovalTests no longer support Java8? We currently use ApprovalTests v24.3.0 and it is building on JDK8 . Something has changed since v24.3.0 , ApprovalTests are no longer working on JDK8 for us.

rohanKanojia avatar Aug 26 '24 14:08 rohanKanojia

We'll discuss this, so far we wanted to stay jdk8 compatible and I consider this rather an unfortunate mistake. I'll get back to you if we bump the min jdk or if we verify all our dependencies to be able to stay on 8.

LarsEckart avatar Aug 27 '24 06:08 LarsEckart

Please give version 24.5.0 a try, it should work again on jdk 8.

LarsEckart avatar Sep 16 '24 18:09 LarsEckart

Please give version 24.5.0 a try, it should work again on jdk 8.

This is working now, thanks!

https://github.com/fabric8io/kubernetes-client/pull/6349

manusa avatar Sep 17 '24 04:09 manusa