Bug 148508 - [matching] subtype array type pattern support is broken
Summary: [matching] subtype array type pattern support is broken
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.2   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 1.6.4   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-24 01:58 EDT by Matt Whitlock CLA
Modified: 2009-02-19 16:06 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Whitlock CLA 2006-06-24 01:58:24 EDT
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?
Comment 1 Adrian Colyer CLA 2006-06-24 07:41:37 EDT
This looks to be a straightforward parser bug. Note that the variation (Object+)[]  does not seem to work either...
Comment 2 Matt Whitlock CLA 2006-06-30 23:03:07 EDT
Version bump.  This bug still applies to final releases of AspectJ 1.5.2 with AJDT 1.4 and Eclipse 3.2.
Comment 3 Andrew Clement CLA 2007-10-24 11:01:45 EDT
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
Comment 4 Andrew Clement CLA 2008-09-30 14:32:44 EDT
(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..?)
Comment 5 Andrew Clement CLA 2008-09-30 14:48:59 EDT
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[][])
Comment 6 Matt Whitlock CLA 2008-09-30 15:26:22 EDT
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.
Comment 7 Andrew Clement CLA 2008-09-30 15:59:33 EDT
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)
Comment 8 Matt Whitlock CLA 2008-09-30 16:36:35 EDT
(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.
Comment 9 Andrew Clement CLA 2008-12-09 15:22:18 EST
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.
Comment 10 Andrew Clement CLA 2009-02-19 13:55:14 EST
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

Comment 11 Andrew Clement CLA 2009-02-19 16:06:02 EST
More tests added at TypePatternTestCase.testArrayMatch()

All fixed and passing now.