-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array type reference not working when aspect is compiled separately from referenced type #24
Comments
BTW, when modifying the aspect like this experimentally public aspect MyAspect {
after() : execution(public MaybeMissing* MaybeMissing*.*()) {
System.out.println(thisJoinPoint);
}
after() : execution(public MaybeMissing*[] MaybeMissing*.*()) {
System.out.println(thisJoinPoint);
}
} now both advices match both methods, i.e. the absolute type name as such does not seem to be the (only) problem. This is true for both compiling the aspect separately or together with the target class. The program output will be:
There seems to be some imprecision with pointcut parsing in this case. |
Some feedback from a maintainer would be welcome. Thank you. |
Not sure what I can say, looks like a bug as you say. Maybe in parsing of point cuts ( |
I started adding tests reproducing both the currently working and failing cases to the code base in a branch. For the second case with the fuzzy pointcuts - return types |
Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
For the first case with the exact type names, I compared
|
Pointcut parsing and array information storage seem to be OK. In both cases (exact and fuzzy/wildcard type patterns), |
I managed to locally fix the matcher for one-dimensional array return types. For multi-dimensional ones like public aspect ExactlyMatchingAspect {
after() : execution(public MaybeMissingClass MaybeMissingClass.*()) {
System.out.println(thisJoinPoint);
}
after() : execution(public MaybeMissingClass[] MaybeMissingClass.*()) {
System.out.println(thisJoinPoint);
}
after() : execution(public MaybeMissingClass[][] MaybeMissingClass.*()) {
System.out.println(thisJoinPoint);
}
} Maybe there is something wrong in Update: I have a local prototype working with multi-dimensional array return types, but it needs to be verified, tidied up and checked. E.g., so far I only tried with arrays of reference types, not of primitive types yet. While I am at it, I also want to look into array type matching for method parameter and field types, not just return types. |
More test cases were added for - multi-dimensional arrays, - primitive type arrays. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
The method falsely determined that a one-dimensional array was not an array due to a one-off bug. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
A simple boolean condition is enough. Loosely relates to #24, but actually it is just drive-by cosmetics. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Fixes #24, both the array return type matching as such as well as matching dimensionality patterns correctly. E.g., 'Foo*[]' is not the same as 'Foo*[][]'. This also works correctly in combination with asterisks, even for primitive types, i.e. 'in*[][]' correctly matches a 2-dimensional array of 'int'. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Especially 'hashCode' did not correspond to 'equals', disregarding several fields, array dimension information being only one of them. This led to parts of pointcuts being ignored, because they were regarded as duplicates. Example: execution(Foo* *(..)) && !execution(Foo*[] *(..)) Here, the negated pattern was falsely regarded as equal to the first pattern, leading to an "A && !A" situation, i.e. no match at all. Furthermore, 'toString' did not print array strings, i.e. instead of "Foo*[][]" something like "Foo*" was printed. This false information was also present in annotations generated by the weaver. FuzzilyMatchingAspect was adjusted to actually match exactly once, as expected, for the "Foo*" return types, i.e. exclusions for the array return types have been added. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
After WildTypePattern.hashCode was fixed in the previous commit, PointcutRewriterTest started failing, because in many places it was falsely relying on a specific order of hash codes, which cannot be guaranteed, especially since more instance fields are part of the hash code now in accordance with 'equals'. The new test helper class LogicalPointcutStructure is able to recognise chained '&&' and '||' pointcuts of the same logical nesting level, un-nesting them from the actual pointcut structure and making them comparable, disregarding their order. I.e., something like ((A && B) && C) && D is actually recognised to logically be A && B && C && D and equivalent to e.g. either of D && B && A && C A && B && D && C C && A && D && B This helps to compare rewritten pointcuts, as long as their logical structure has not been altered. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
More test cases were added for - multi-dimensional arrays, - primitive type arrays. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
The method falsely determined that a one-dimensional array was not an array due to a one-off bug. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
A simple boolean condition is enough. Loosely relates to #24, but actually it is just drive-by cosmetics. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Fixes #24, both the array return type matching as such as well as matching dimensionality patterns correctly. E.g., 'Foo*[]' is not the same as 'Foo*[][]'. This also works correctly in combination with asterisks, even for primitive types, i.e. 'in*[][]' correctly matches a 2-dimensional array of 'int'. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Especially 'hashCode' did not correspond to 'equals', disregarding several fields, array dimension information being only one of them. This led to parts of pointcuts being ignored, because they were regarded as duplicates. Example: execution(Foo* *(..)) && !execution(Foo*[] *(..)) Here, the negated pattern was falsely regarded as equal to the first pattern, leading to an "A && !A" situation, i.e. no match at all. Furthermore, 'toString' did not print array strings, i.e. instead of "Foo*[][]" something like "Foo*" was printed. This false information was also present in annotations generated by the weaver. FuzzilyMatchingAspect was adjusted to actually match exactly once, as expected, for the "Foo*" return types, i.e. exclusions for the array return types have been added. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
After WildTypePattern.hashCode was fixed in the previous commit, PointcutRewriterTest started failing, because in many places it was falsely relying on a specific order of hash codes, which cannot be guaranteed, especially since more instance fields are part of the hash code now in accordance with 'equals'. The new test helper class LogicalPointcutStructure is able to recognise chained '&&' and '||' pointcuts of the same logical nesting level, un-nesting them from the actual pointcut structure and making them comparable, disregarding their order. I.e., something like ((A && B) && C) && D is actually recognised to logically be A && B && C && D and equivalent to e.g. either of D && B && A && C A && B && D && C C && A && D && B This helps to compare rewritten pointcuts, as long as their logical structure has not been altered. Relates to #24. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
If you look at the merged PR, this issue became considerably bigger than I thought, because along the way I also improved the syntax for array matching. So, this was not just a simple bugfix. |
I have found StackOverflow question #64416863 and can reproduce the author's problem with AspectJ 1.9.6. I further simplified the code a bit to now read:
When compiling everything together, it works as expected:
When compiling the aspect separately however, the second advice unexpectedly intercepts target method
f1
:The text was updated successfully, but these errors were encountered: