aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs1923/gh326
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bugs1923/gh326')
-rw-r--r--tests/bugs1923/gh326/pkg/BusinessDao.java9
-rw-r--r--tests/bugs1923/gh326/pkg/BusinessDto.java8
-rw-r--r--tests/bugs1923/gh326/pkg/BusinessService.java18
-rw-r--r--tests/bugs1923/gh326/pkg/HandleSourceException.java17
-rw-r--r--tests/bugs1923/gh326/pkg/SourceException.java7
-rw-r--r--tests/bugs1923/gh326/pkg/SourceExceptionHandlerAspect.aj29
-rw-r--r--tests/bugs1923/gh326/pkg/TargetException.java11
7 files changed, 99 insertions, 0 deletions
diff --git a/tests/bugs1923/gh326/pkg/BusinessDao.java b/tests/bugs1923/gh326/pkg/BusinessDao.java
new file mode 100644
index 000000000..8ab256912
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/BusinessDao.java
@@ -0,0 +1,9 @@
+package pkg;
+
+public class BusinessDao<D> {
+
+ public D doSomething() throws SourceException {
+ return (D) new BusinessDto();
+ }
+
+}
diff --git a/tests/bugs1923/gh326/pkg/BusinessDto.java b/tests/bugs1923/gh326/pkg/BusinessDto.java
new file mode 100644
index 000000000..42d792b27
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/BusinessDto.java
@@ -0,0 +1,8 @@
+package pkg;
+
+public class BusinessDto {
+
+ public BusinessDto() throws SourceException {
+throw new SourceException();
+}
+}
diff --git a/tests/bugs1923/gh326/pkg/BusinessService.java b/tests/bugs1923/gh326/pkg/BusinessService.java
new file mode 100644
index 000000000..10d98400f
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/BusinessService.java
@@ -0,0 +1,18 @@
+package pkg;
+
+public class BusinessService {
+
+ @HandleSourceException(message="42")
+ public BusinessDto doSomething() throws TargetException {
+ return new BusinessDao<BusinessDto>().doSomething();
+ }
+
+
+public static void main(String []argv) throws TargetException {
+try {
+ new BusinessService().doSomething();
+} catch (TargetException te) {
+ System.out.println(te.getMessage());
+}
+}
+}
diff --git a/tests/bugs1923/gh326/pkg/HandleSourceException.java b/tests/bugs1923/gh326/pkg/HandleSourceException.java
new file mode 100644
index 000000000..a5645cfac
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/HandleSourceException.java
@@ -0,0 +1,17 @@
+package pkg;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target(METHOD)
+public @interface HandleSourceException {
+
+ String message() default "";
+
+ boolean useLogger() default true;
+
+}
diff --git a/tests/bugs1923/gh326/pkg/SourceException.java b/tests/bugs1923/gh326/pkg/SourceException.java
new file mode 100644
index 000000000..2ada2d6fe
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/SourceException.java
@@ -0,0 +1,7 @@
+package pkg;
+
+public class SourceException extends Exception {
+
+ private static final long serialVersionUID = 2789789285541660969L;
+
+}
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);
+ }
+ }
+
+}
diff --git a/tests/bugs1923/gh326/pkg/TargetException.java b/tests/bugs1923/gh326/pkg/TargetException.java
new file mode 100644
index 000000000..aa3f5c868
--- /dev/null
+++ b/tests/bugs1923/gh326/pkg/TargetException.java
@@ -0,0 +1,11 @@
+package pkg;
+
+public class TargetException extends Exception {
+
+ private static final long serialVersionUID = -1282142579066274623L;
+
+ public TargetException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}