From 65f1ec72c2fc9446a162780dc3f6dee625704c02 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 4 Dec 2022 16:16:37 +0100 Subject: Fix #366085 concerning declared annotations with source retention See https://bugs.eclipse.org/bugs/show_bug.cgi?id=366085. See https://stackoverflow.com/q/74618269/1082681. The issue described in the Bugzilla issue is about 'declare @type', but similar issues also existed for 'declare @field', 'declare @method', 'declare @constructor'. This fix is rather superficial and leaves things to be desired, because it is rather hacky and simply ignores errors source retention annotation declarations during weaving. A better fix would drop the corresponding declarations while parsing and also issue compiler warnings in each case. Signed-off-by: Alexander Kriegisch --- tests/bugs1919/366085/Application.java | 11 +++++++++++ tests/bugs1919/366085/DeclareAnnotationsAspect.aj | 13 +++++++++++++ tests/bugs1919/366085/Marker.java | 4 ++++ tests/bugs1919/366085/ToString.java | 4 ++++ .../java/org/aspectj/systemtest/ajc1919/Bugs1919Tests.java | 4 ++-- .../resources/org/aspectj/systemtest/ajc1919/ajc1919.xml | 12 +++++++++--- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 tests/bugs1919/366085/Application.java create mode 100644 tests/bugs1919/366085/DeclareAnnotationsAspect.aj create mode 100644 tests/bugs1919/366085/Marker.java create mode 100644 tests/bugs1919/366085/ToString.java (limited to 'tests') diff --git a/tests/bugs1919/366085/Application.java b/tests/bugs1919/366085/Application.java new file mode 100644 index 000000000..3ef2126fd --- /dev/null +++ b/tests/bugs1919/366085/Application.java @@ -0,0 +1,11 @@ +public class Application { + public int number; + + public Application(int number) { + this.number = number; + } + + public int getNumber() { + return number; + } +} diff --git a/tests/bugs1919/366085/DeclareAnnotationsAspect.aj b/tests/bugs1919/366085/DeclareAnnotationsAspect.aj new file mode 100644 index 000000000..8fdc9460c --- /dev/null +++ b/tests/bugs1919/366085/DeclareAnnotationsAspect.aj @@ -0,0 +1,13 @@ +public aspect DeclareAnnotationsAspect { + // These should be ignored, because @ToString has SOURCE retention + declare @type : Application : @ToString; + declare @method : * Application.*(..) : @ToString; + declare @constructor : Application.new(..) : @ToString; + declare @field : * Application.* : @ToString; + + // These should be applied, because @Marker has RUNTIME retention + declare @type : Application : @Marker; + declare @method : * Application.*(..) : @Marker; + declare @constructor : Application.new(..) : @Marker; + declare @field : * Application.* : @Marker; +} diff --git a/tests/bugs1919/366085/Marker.java b/tests/bugs1919/366085/Marker.java new file mode 100644 index 000000000..42ba9af15 --- /dev/null +++ b/tests/bugs1919/366085/Marker.java @@ -0,0 +1,4 @@ +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +@Retention(RetentionPolicy.RUNTIME) +public @interface Marker { } diff --git a/tests/bugs1919/366085/ToString.java b/tests/bugs1919/366085/ToString.java new file mode 100644 index 000000000..08e9399c4 --- /dev/null +++ b/tests/bugs1919/366085/ToString.java @@ -0,0 +1,4 @@ +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +@Retention(RetentionPolicy.SOURCE) +public @interface ToString { } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1919/Bugs1919Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1919/Bugs1919Tests.java index 38441267e..3c921f51a 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1919/Bugs1919Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1919/Bugs1919Tests.java @@ -15,8 +15,8 @@ import org.aspectj.testing.XMLBasedAjcTestCase; */ public class Bugs1919Tests extends XMLBasedAjcTestCase { - public void testDummyBug() { - //runTest("dummy Java 19 bug"); + public void testDeclareAnnotationWithSourceRetention() { + runTest("declare annotation with SOURCE retention"); } public static Test suite() { diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1919/ajc1919.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1919/ajc1919.xml index 3741b338c..eaeca7143 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc1919/ajc1919.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1919/ajc1919.xml @@ -162,8 +162,14 @@ - - - + + + + + + + + + -- cgit v1.2.3