From 7577e2c74de9e7b89313fe68798e8188fc492549 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Tue, 5 Nov 2024 16:22:26 +0100 Subject: [PATCH] Rule for @Async detection Signed-off-by: Juan Manuel Leflet Estrada --- ...g-framework-5.x-to-6.0-core-container.yaml | 21 +++++++++++++++++++ .../src/main/java/org/konveyor/Main.java | 18 +++++++++++++--- ...mework-5.x-to-6.0-core-container.test.yaml | 7 +++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/default/generated/spring-framework/spring-framework-5.x-to-6.0-core-container.yaml b/default/generated/spring-framework/spring-framework-5.x-to-6.0-core-container.yaml index 1338e0cc..de4cea3a 100644 --- a/default/generated/spring-framework/spring-framework-5.x-to-6.0-core-container.yaml +++ b/default/generated/spring-framework/spring-framework-5.x-to-6.0-core-container.yaml @@ -20,3 +20,24 @@ links: - title: 'Spring 6.0 migration guide' url: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#core-container + +- ruleID: spring-framework-5.x-to-6.0-core-container-00010 + category: potential + effort: 2 + labels: + - konveyor.io/source=spring5 + - konveyor.io/target=spring6+ + when: + java.referenced: + pattern: org.springframework.scheduling.annotation.Async + location: ANNOTATION + description: Methods annotated with @Async must return either Future or void + message: | + Methods annotated with @Async must return either Future or void. This has long been documented but is now also + actively checked and enforced, with an exception thrown for any other return type. + + If your @Async annotated method does not return `Future` or `void`, please change its signature. + links: + - title: 'Spring 6.0 migration guide' + url: https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-6.0-Release-Notes#core-container + diff --git a/default/generated/spring-framework/tests/data/core-container/src/main/java/org/konveyor/Main.java b/default/generated/spring-framework/tests/data/core-container/src/main/java/org/konveyor/Main.java index cf006a4f..cae553ef 100644 --- a/default/generated/spring-framework/tests/data/core-container/src/main/java/org/konveyor/Main.java +++ b/default/generated/spring-framework/tests/data/core-container/src/main/java/org/konveyor/Main.java @@ -1,12 +1,13 @@ package org.konveyor; import org.konveyor.beans.Bean; +import org.springframework.beans.BeanInfoFactory; +import org.springframework.beans.SimpleBeanInfoFactory; +import org.springframework.scheduling.annotation.Async; import java.beans.BeanInfo; import java.beans.IntrospectionException; - -import org.springframework.beans.BeanInfoFactory; -import org.springframework.beans.SimpleBeanInfoFactory; +import java.util.concurrent.RunnableFuture; public class Main { @@ -14,6 +15,17 @@ public static void main(String[] args) throws IntrospectionException { BeanInfoFactory factory = new SimpleBeanInfoFactory(); BeanInfo beanInfo = factory.getBeanInfo(Bean.class); System.out.println(beanInfo.getBeanDescriptor()); + + + } + + @Async + public RunnableFuture correctAsyncMethod(String param) { + return null; + } + + @Async + public void correctAsyncMethod2(String param) { } } diff --git a/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-core-container.test.yaml b/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-core-container.test.yaml index 3a4829e5..54ad96e3 100644 --- a/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-core-container.test.yaml +++ b/default/generated/spring-framework/tests/spring-framework-5.x-to-6.0-core-container.test.yaml @@ -10,3 +10,10 @@ tests: mode: "source-only" hasIncidents: exactly: 2 +- ruleID: spring-framework-5.x-to-6.0-core-container-00010 + testCases: + - name: tc-1 + analysisParams: + mode: "source-only" + hasIncidents: + exactly: 2