aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj')
-rw-r--r--tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj b/tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj
new file mode 100644
index 000000000..6bd48f3b7
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj
@@ -0,0 +1,29 @@
+package pkg;
+
+import java.lang.annotation.Annotation;
+
+import org.aspectj.lang.reflect.MethodSignature;
+
+public aspect SourceExceptionHandlerAspect {
+
+ pointcut handleSourceExceptionPointcut(): @annotation(HandleSourceException);
+
+ declare soft : SourceException : handleSourceExceptionPointcut();
+
+ Object around() throws TargetException: handleSourceExceptionPointcut() {
+ try {
+ return proceed();
+ } catch (Throwable exception) {
+ String message = "";
+ Annotation[] annotations = ((MethodSignature) thisJoinPoint.getSignature()).getMethod().getAnnotationsByType(HandleSourceException.class);
+ if (annotations.length == 1) {
+ message = ((HandleSourceException) annotations[0]).message();
+ }
+ if (message.isBlank()) {
+ message = exception.getMessage();
+ }
+ throw new TargetException(message, exception);
+ }
+ }
+
+}