Community
Participate
Working Groups
The call of the hasRole(Object, Class) method throws a NoSuchMethodError if the call is used in an inner team. Code to reproduce the bug: public team class OuterTeam { public team class InnerTeam playedBy OuterBase { protected class SomeRole playedBy InnerBase { } @SuppressWarnings("ambiguouslowering") public void createRole(InnerBase as SomeRole b) { System.out.println(OuterTeam.this.hasRole(b, SomeRole.class)); } } public InnerTeam registerInnerTeam(OuterBase as InnerTeam o) { return o; } } public class Main { public static void main(String[] args) { OuterBase ob = new OuterBase(); InnerBase ib = new InnerBase(); final OuterTeam ot = new OuterTeam(); InnerTeam<@ot> it = ot.registerInnerTeam(ob); it.createRole(ib); } }
Thanks for the report. BTW: why did you suppress the warning? I think it has something relevant to tell, no?
Created attachment 166716 [details] patch Fixed: for nested teams we have to ensure that the synthetic _OT$getClass$XY method is also propagated into the interface part. In the example we were only generating otdtbugs.OuterTeam$__OT__InnerTeam._OT$getClass$SomeRole() {...} not otdtbugs.OuterTeam$InnerTeam._OT$getClass$SomeRole();
Patch committed as part of r274. Tests are test926_roleClassLiteralAccess3() and test926_roleClassLiteralAccess4()
Verified for M2 using I201005052210 In order to successfully run the example I change OuterTeam to: public team class OuterTeam { public team class InnerTeam playedBy OuterBase { protected class SomeRole extends Confined playedBy InnerBase { } public void createRole(InnerBase as SomeRole b) { System.out.println(InnerTeam.this.hasRole(b, SomeRole.class)); } } public InnerTeam registerInnerTeam(OuterBase as InnerTeam o) { return o; } } By marking SomeRole as Confined I ensure that hasRole(b, ...) will need to lower its argument b because Object is expected, which SomeRole no longer is conform to. This also resolves the "ambiguouslowering" warning. Additionally, the InnerTeam must be asked not OuterTeam. (Note, that the argument to hasRole must be a base instance).
(In reply to comment #1) > Thanks for the report. > > BTW: why did you suppress the warning? > I think it has something relevant to tell, no? Oh yeah it has. I have just been copying this code and modified it quick to a simple example. I didn't read the warning carefully at that time. It's ambiguous because both the base and the role inherit Object. So the lowering mechanism doesn't know what to do. Makes sense. Thanks for pointing it out. greetings Jan Marc
Setting iplog flag to acknowledge the contributed testcase in comment 0.