aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs1920/github_spring_27761
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2023-10-05 11:24:28 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2023-10-05 11:25:01 +0700
commit99f426e351b62310ce3c31348594b106a4bf624e (patch)
treeba16b304a9fa948a4fc544f31944686c9a530962 /tests/bugs1920/github_spring_27761
parent39c5da6eb973ce31ad90c30c1b4156988d6b9bf8 (diff)
downloadaspectj-99f426e351b62310ce3c31348594b106a4bf624e.tar.gz
aspectj-99f426e351b62310ce3c31348594b106a4bf624e.zip
Move some 1.9.20.1 bug tests to correct directory
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'tests/bugs1920/github_spring_27761')
-rw-r--r--tests/bugs1920/github_spring_27761/JpaRepositoryDump.java62
-rw-r--r--tests/bugs1920/github_spring_27761/RepositoryAspect.aj35
2 files changed, 97 insertions, 0 deletions
diff --git a/tests/bugs1920/github_spring_27761/JpaRepositoryDump.java b/tests/bugs1920/github_spring_27761/JpaRepositoryDump.java
new file mode 100644
index 000000000..b70330bff
--- /dev/null
+++ b/tests/bugs1920/github_spring_27761/JpaRepositoryDump.java
@@ -0,0 +1,62 @@
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class JpaRepositoryDump implements Opcodes {
+ public static void main(String[] args) throws IOException {
+ // Write class file to test sandbox directory
+ String classFile = args[0] + File.separator + "JpaRepository.class";
+ try (FileOutputStream outputStream = new FileOutputStream(classFile)) {
+ outputStream.write(dump());
+ }
+ }
+
+ public static byte[] dump() {
+ /*
+ Write out a class corresponding to this source code:
+ ------------------------------------------------------------
+ interface JpaRepository<T> extends CrudRepository<T> {
+ @Override
+ <S extends T> List<S> saveAll(Iterable<S> entities);
+ }
+ ------------------------------------------------------------
+ The only difference to the original class created by Javac or Ajc is that the bridge method is written to the class
+ file first, then the overriding method with the return type narrowed from Iterable to List. This has the effect of
+ org.aspectj.weaver.ResolvedType.getMethodsIncludingIntertypeDeclarations also finding the bridge method first,
+ which helps to reproduce https://github.com/spring-projects/spring-framework/issues/27761 in a regression test.
+
+ The resulting class file can be found in .../gh_spring_27761/JpaRepository_bridge_first.jar and is used during test
+ "do not match bridge methods".
+ */
+
+ ClassWriter classWriter = new ClassWriter(0);
+ classWriter.visit(V1_8, ACC_ABSTRACT | ACC_INTERFACE, "JpaRepository", "<T:Ljava/lang/Object;>Ljava/lang/Object;LCrudRepository<TT;>;", "java/lang/Object", new String[]{"CrudRepository"});
+ classWriter.visitSource("RepositoryAspect.aj", null);
+
+ MethodVisitor methodVisitor;
+ methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_BRIDGE | ACC_SYNTHETIC, "saveAll", "(Ljava/lang/Iterable;)Ljava/lang/Iterable;", null, null);
+ methodVisitor.visitCode();
+ Label label0 = new Label();
+ methodVisitor.visitLabel(label0);
+ methodVisitor.visitLineNumber(1, label0);
+ methodVisitor.visitVarInsn(ALOAD, 0);
+ methodVisitor.visitVarInsn(ALOAD, 1);
+ methodVisitor.visitTypeInsn(CHECKCAST, "java/lang/Iterable");
+ methodVisitor.visitMethodInsn(INVOKEINTERFACE, "JpaRepository", "saveAll", "(Ljava/lang/Iterable;)Ljava/util/List;", true);
+ methodVisitor.visitInsn(ARETURN);
+ methodVisitor.visitMaxs(2, 2);
+ methodVisitor.visitEnd();
+
+ methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "saveAll", "(Ljava/lang/Iterable;)Ljava/util/List;", "<S:TT;>(Ljava/lang/Iterable<TS;>;)Ljava/util/List<TS;>;", null);
+ methodVisitor.visitEnd();
+
+ classWriter.visitEnd();
+
+ return classWriter.toByteArray();
+ }
+}
diff --git a/tests/bugs1920/github_spring_27761/RepositoryAspect.aj b/tests/bugs1920/github_spring_27761/RepositoryAspect.aj
new file mode 100644
index 000000000..b938d754c
--- /dev/null
+++ b/tests/bugs1920/github_spring_27761/RepositoryAspect.aj
@@ -0,0 +1,35 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public aspect RepositoryAspect {
+ Object around(): execution(* JpaRepository.save*(..)) {
+ System.out.println(thisJoinPoint);
+ return proceed();
+ }
+
+ public static void main(String[] args) {
+ new RepositoryImpl<String>().saveAll(Arrays.asList("One", "Two", "Three"));
+ }
+}
+
+interface CrudRepository<T> {
+ <S extends T> Iterable<S> saveAll(Iterable<S> entities);
+}
+
+/*
+interface JpaRepository<T> extends CrudRepository<T> {
+ @Override
+ <S extends T> List<S> saveAll(Iterable<S> entities);
+}
+*/
+
+class RepositoryImpl<S> implements JpaRepository<String> {
+ @Override
+ public <S extends String> List<S> saveAll(Iterable<S> entities) {
+ List<S> entityList = new ArrayList<>();
+ entities.iterator().forEachRemaining(entityList::add);
+ System.out.println("Saving " + entityList);
+ return entityList;
+ }
+}