blob: eff35ab7c48dc5a32a9d11f6e04bfbc3afcb9476 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
[[miscellaneous]]
= Other Changes in AspectJ 5
[[pointcuts-change]]
== Pointcuts
AspectJ 5 is more liberal than AspectJ 1.2.1 in accepting pointcut
expressions that bind context variables in more than one location. For
example, AspectJ 1.2.1 does not allow:
[source, java]
....
pointcut foo(Foo foo) :
(execution(* *(..)) && this(foo) ) ||
(set(* *) && target(foo));
....
whereas this expression is permitted in AspectJ 5. Each context variable
must be bound exactly once in each branch of a disjunction, and the
disjunctive branches must be mutually exclusive. In the above example
for instance, no join point can be both an execution join point and a
set join point so the two branches are mutually exclusive.
[[declare-soft-change]]
== Declare Soft
The semantics of the `declare soft` statement have been refined in
AspectJ 5 to only soften exceptions that are not already runtime
exceptions. If the exception type specified in a declare soft statement
is `RuntimeException` or a subtype of `RuntimeException` then a new
XLint warning will be issued:
[source, java]
....
declare soft : SomeRuntimeException : execution(* *(..));
// "SomeRuntimeException will not be softened as it is already a
// RuntimeException" [XLint:runtimeExceptionNotSoftened]
....
This XLint message can be controlled by setting the
`runtimeExceptionNotSoftened` XLint parameter.
If the exception type specified in a declare soft statement is a super
type of `RuntimeException` (such as `Exception` for example) then any
_checked_ exception thrown at a matched join point, where the exception
is an instance of the softened exception, will be softened to an
`org.aspectj.lang.SoftException`.
[source, java]
....
public aspect SoftenExample {
declare soft : Exception : execution(* Foo.*(..));
}
class Foo {
public static void main(String[] args) {
Foo foo = new Foo();
foo.foo();
foo.bar();
}
void foo() throws Exception {
throw new Exception(); // this will be converted to a SoftException
}
void bar() throws Exception {
throw new RuntimeException(); // this will remain a RuntimeException
}
}
....
|