Community
Participate
Working Groups
Excerpt from AspectJ Programmer's Guide: > Array type patterns > A type name pattern or subtype pattern can be > followed by one or more sets of square brackets > to make array type patterns. So Object[] is an > array type pattern, and so is com.xerox..*[][], > and so is Object+[]. Both of these pointcut definitions cause syntax errors: pointcut broken1() : execution(* *(Object+[])); pointcut broken2() : execution(* *(*)) && args(Object+[]); The compiler complains that it is expecting a ')' instead of the '['. What gives?
This looks to be a straightforward parser bug. Note that the variation (Object+)[] does not seem to work either...
Version bump. This bug still applies to final releases of AspectJ 1.5.2 with AJDT 1.4 and Eclipse 3.2.
take a quick look at the parser in 1.5.4 to see if there is a simple fix but this might need to wait until the grammar is open for the 1.6.0 compiler upgrade
(Object+[]) still breaks the parser. (Object[]+) parses but doesn't mean much (try finding a subtype of array...) I propose that (Object+[]) will match (Object[]) (Integer[]) (String[]) I will ignore (Object[]+) - don't want to break existing users of that right now (who are they..?)
OK - going to make this in plan for 1.6.3. Doing it properly will disturb matching more than I want to in 1.6.2. I'll commit a couple of testcases ready for this. Changes will be needed in PatternParser.parseSingleTypePattern() where it checks for the subtype '+' after checking for the dimensions '[]'. Also looks like varargs can make things complex (Object[]...) - should test if that actually matches what is expected. Also changes required in TypePattern.matchesSubtypes() - it must do some extra work for an ArrayReferenceType. Check the dimensions match and the component type subtype. (So Object+[] matches String[] but not String[][])
Two notes: 1.) Every array type with reference-type components is a subclass of Object[]. Object[] arr = new String[5]; if (arr instanceof String[]) { System.out.println("Yes it is."); } This means that Object[]+ should match every array type with reference-type components. (But array types with non-reference-type components, such as int[], should not match Object[]+. Do note, however, that int[][] should match Object[]+ because int[][] is a subclass of Object[], since int[] is a subclass of Object, as discussed in #2 below.) 2.) Furthermore, every array type is a subclass of Object. Object arr = new int[5]; Object arr2 = new String[5][]; Therefore, Object+[] should match String[][], since String[] is a subclass of Object. Object+[] should also match int[][], since int[] is a subclass of Object, but it should not match int[], since int is not a subclass of Object. Following these two rules, it would seem that Object[]+ and Object+[] should be equivalent in practical application, though their underlying parse trees and evaluation sequences differ.
I don't suppose you want to write the testcases for me? Keep them as simple as possible (multiple simple ones rather than one large one)
(In reply to comment #7) > I don't suppose you want to write the testcases for me? I would if my team were still using AspectJ, but sorry, no. I only commented here in the interest of getting this bug thoroughly fixed for others.
no votes at the moment, not modifying pointcut matching any more in 1.6.3 as it already includes some drastic changes for generics matching.
looking at this properly now. I even found a testcase: checkMatch("java.lang.Object+[]", "java.lang.String[]", true); but it is a bad testcase, it does not parse all of the input pattern (stopping at the []) so works by accident. Addressing this will also fix bug 265418
More tests added at TypePatternTestCase.testArrayMatch() All fixed and passing now.